|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | +Test :: ExifTool base class - execute() using raw_bytes parameter |
| 4 | +""" |
| 5 | + |
| 6 | +# standard |
| 7 | +import unittest |
| 8 | +import shutil |
| 9 | + |
| 10 | +# test helpers |
| 11 | +from tests.common_util import et_get_temp_dir, TEST_IMAGE_DIR, TEST_IMAGE_JPG, create_random_bin_file |
| 12 | + |
| 13 | +# custom |
| 14 | +import exiftool |
| 15 | + |
| 16 | +class TestExifToolBytes(unittest.TestCase): |
| 17 | + |
| 18 | + # --------------------------------------------------------------------------------------------------------- |
| 19 | + def setUp(self): |
| 20 | + self.et = exiftool.ExifTool(common_args=["-G", "-n", "-overwrite_original"], config_file=TEST_IMAGE_DIR / "my_makernotes.config") |
| 21 | + |
| 22 | + (self.temp_obj, self.temp_dir) = et_get_temp_dir(suffix="etbytes") |
| 23 | + |
| 24 | + def tearDown(self): |
| 25 | + if self.et.running: |
| 26 | + self.et.terminate() |
| 27 | + |
| 28 | + # --------------------------------------------------------------------------------------------------------- |
| 29 | + |
| 30 | + def test_read_write_binary(self): |
| 31 | + self.assertFalse(self.et.running) |
| 32 | + self.et.run() |
| 33 | + |
| 34 | + ### set up files ### |
| 35 | + |
| 36 | + # write a binary file to test with ... we can make it random or the same, shouldn't matter |
| 37 | + BIN_FILE_SIZE = 1024 |
| 38 | + |
| 39 | + p_bin_file = self.temp_dir / "test_data.bin" |
| 40 | + create_random_bin_file(p_bin_file, BIN_FILE_SIZE) |
| 41 | + |
| 42 | + p_jpg_file = self.temp_dir / "rose.jpg" |
| 43 | + shutil.copyfile(TEST_IMAGE_JPG, p_jpg_file) |
| 44 | + |
| 45 | + ### write the binary data ### |
| 46 | + self.et.execute(f"-MyMakerNotes<={p_bin_file}", str(p_jpg_file)) |
| 47 | + self.assertEqual(self.et.last_status, 0) |
| 48 | + |
| 49 | + ### read the binary data and compare ### |
| 50 | + with open(p_bin_file, 'rb') as f: |
| 51 | + bin_file_data = f.read() |
| 52 | + |
| 53 | + # make sure it's the right amount of bytes wrote in originally |
| 54 | + self.assertEqual(len(bin_file_data), BIN_FILE_SIZE) |
| 55 | + |
| 56 | + # get the custom tag |
| 57 | + written_bin_data = self.et.execute("-b", "-MyMakerNotes", str(p_jpg_file), raw_bytes=True) |
| 58 | + |
| 59 | + # check that they are equal |
| 60 | + self.assertEqual(bin_file_data, written_bin_data) |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + """ also write tests to allow executehelper to use the execute(raw_bytes) and test whether it works with check error """ |
| 70 | + |
| 71 | + """ test multi tags in mixed encoding with bytes """ |
| 72 | + |
| 73 | + """ drawback to change is that it would be slower as the param list is copied again internally """ |
| 74 | + |
0 commit comments