Skip to content

Commit

Permalink
Adapt unit tests for EXV_ENABLE_FILESYSTEM off
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-easterbrook committed Jul 31, 2024
1 parent 6b8b7ab commit d4a1e08
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions tests/test_basicio.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def test_CurlIo(self):
self.assertEqual(io.close(), 0)
self.assertEqual(io.isopen(), True)

@unittest.skipUnless(exiv2.versionInfo()['EXV_ENABLE_FILESYSTEM'],
'EXV_ENABLE_FILESYSTEM is off')
def test_FileIo(self):
# most functions are tested in test_MemIo
io = exiv2.ImageFactory.createIo(self.image_path)
Expand Down Expand Up @@ -172,6 +174,8 @@ def test_ref_counts(self):
del io
self.assertEqual(sys.getrefcount(self.data), 3)

@unittest.skipUnless(exiv2.versionInfo()['EXV_ENABLE_FILESYSTEM'],
'EXV_ENABLE_FILESYSTEM is off')
def test_unicode_paths(self):
cp = locale.getpreferredencoding()
with tempfile.TemporaryDirectory() as tmp_dir:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_easyaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class TestEasyaccessModule(unittest.TestCase):
@classmethod
def setUpClass(cls):
test_dir = os.path.dirname(__file__)
image = exiv2.ImageFactory.open(os.path.join(test_dir, 'image_02.jpg'))
with open(os.path.join(test_dir, 'image_02.jpg'), 'rb') as f:
image = exiv2.ImageFactory.open(f.read())
image.readMetadata()
cls.exif_data = image.exifData()

Expand Down
4 changes: 2 additions & 2 deletions tests/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def test_LogMsg(self):
self.assertEqual(exiv2.LogMsg.handler(), exiv2.LogMsg.pythonHandler)
# get exiv2 to raise an exception
with self.assertRaises(exiv2.Exiv2Error) as cm:
image = exiv2.ImageFactory.open('non-existing.jpg')
image = exiv2.ImageFactory.open(bytes())
self.assertEqual(cm.exception.code,
exiv2.ErrorCode.kerDataSourceOpenFailed)
exiv2.ErrorCode.kerInputDataReadFailed)


if __name__ == '__main__':
Expand Down
2 changes: 2 additions & 0 deletions tests/test_exif.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ def test_ExifThumb(self):
thumb.setJpegThumbnail(
data, exiv2.URational((160, 1)), exiv2.URational((120, 1)), 1)
self.assertEqual(len(thumb.copy()), 2532)
if not exiv2.versionInfo()['EXV_ENABLE_FILESYSTEM']:
self.skipTest('EXV_ENABLE_FILESYSTEM is off')
with tempfile.TemporaryDirectory() as tmp_dir:
temp_file = os.path.join(tmp_dir, 'thumb')
self.assertEqual(thumb.writeFile(temp_file), 2532)
Expand Down
14 changes: 8 additions & 6 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,22 @@ def test_ImageFactory(self):
factory.create(int(exiv2.ImageType.jpeg))
self.assertIsInstance(
factory.create(exiv2.ImageType.jpeg), exiv2.Image)
self.assertIsInstance(factory.createIo(self.image_data), exiv2.BasicIo)
self.check_result(factory.getType(self.image_data),
exiv2.ImageType, exiv2.ImageType.jpeg)
self.check_result(factory.getType(io),
exiv2.ImageType, exiv2.ImageType.jpeg)
self.assertIsInstance(factory.open(self.image_data), exiv2.Image)
if not exiv2.versionInfo()['EXV_ENABLE_FILESYSTEM']:
self.skipTest('EXV_ENABLE_FILESYSTEM is off')
with tempfile.TemporaryDirectory() as tmp_dir:
temp_file = os.path.join(tmp_dir, 'image.jpg')
self.assertIsInstance(
factory.create(exiv2.ImageType.jpeg, temp_file), exiv2.Image)
self.assertIsInstance(factory.createIo(self.image_path), exiv2.BasicIo)
self.assertIsInstance(factory.createIo(self.image_data), exiv2.BasicIo)
self.check_result(factory.getType(self.image_path),
exiv2.ImageType, exiv2.ImageType.jpeg)
self.check_result(factory.getType(self.image_data),
exiv2.ImageType, exiv2.ImageType.jpeg)
self.check_result(factory.getType(io),
exiv2.ImageType, exiv2.ImageType.jpeg)
self.assertIsInstance(factory.open(self.image_path), exiv2.Image)
self.assertIsInstance(factory.open(self.image_data), exiv2.Image)

def test_ref_counts(self):
# opening from data keeps reference to buffer
Expand Down
2 changes: 2 additions & 0 deletions tests/test_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def test_PreviewImage(self):
self.check_result(preview.mimeType(), str, 'image/jpeg')
self.check_result(preview.size(), int, 2532)
self.check_result(preview.width(), int, 160)
if not exiv2.versionInfo()['EXV_ENABLE_FILESYSTEM']:
self.skipTest('EXV_ENABLE_FILESYSTEM is off')
with tempfile.TemporaryDirectory() as tmp_dir:
temp_file = os.path.join(tmp_dir, 'image.jpg')
self.assertEqual(preview.writeFile(temp_file), 2532)
Expand Down

0 comments on commit d4a1e08

Please sign in to comment.