Skip to content

Commit d4a1e08

Browse files
Adapt unit tests for EXV_ENABLE_FILESYSTEM off
1 parent 6b8b7ab commit d4a1e08

File tree

6 files changed

+20
-9
lines changed

6 files changed

+20
-9
lines changed

tests/test_basicio.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def test_CurlIo(self):
5252
self.assertEqual(io.close(), 0)
5353
self.assertEqual(io.isopen(), True)
5454

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

177+
@unittest.skipUnless(exiv2.versionInfo()['EXV_ENABLE_FILESYSTEM'],
178+
'EXV_ENABLE_FILESYSTEM is off')
175179
def test_unicode_paths(self):
176180
cp = locale.getpreferredencoding()
177181
with tempfile.TemporaryDirectory() as tmp_dir:

tests/test_easyaccess.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class TestEasyaccessModule(unittest.TestCase):
2626
@classmethod
2727
def setUpClass(cls):
2828
test_dir = os.path.dirname(__file__)
29-
image = exiv2.ImageFactory.open(os.path.join(test_dir, 'image_02.jpg'))
29+
with open(os.path.join(test_dir, 'image_02.jpg'), 'rb') as f:
30+
image = exiv2.ImageFactory.open(f.read())
3031
image.readMetadata()
3132
cls.exif_data = image.exifData()
3233

tests/test_error.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def test_LogMsg(self):
5757
self.assertEqual(exiv2.LogMsg.handler(), exiv2.LogMsg.pythonHandler)
5858
# get exiv2 to raise an exception
5959
with self.assertRaises(exiv2.Exiv2Error) as cm:
60-
image = exiv2.ImageFactory.open('non-existing.jpg')
60+
image = exiv2.ImageFactory.open(bytes())
6161
self.assertEqual(cm.exception.code,
62-
exiv2.ErrorCode.kerDataSourceOpenFailed)
62+
exiv2.ErrorCode.kerInputDataReadFailed)
6363

6464

6565
if __name__ == '__main__':

tests/test_exif.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ def test_ExifThumb(self):
206206
thumb.setJpegThumbnail(
207207
data, exiv2.URational((160, 1)), exiv2.URational((120, 1)), 1)
208208
self.assertEqual(len(thumb.copy()), 2532)
209+
if not exiv2.versionInfo()['EXV_ENABLE_FILESYSTEM']:
210+
self.skipTest('EXV_ENABLE_FILESYSTEM is off')
209211
with tempfile.TemporaryDirectory() as tmp_dir:
210212
temp_file = os.path.join(tmp_dir, 'thumb')
211213
self.assertEqual(thumb.writeFile(temp_file), 2532)

tests/test_image.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,22 @@ def test_ImageFactory(self):
131131
factory.create(int(exiv2.ImageType.jpeg))
132132
self.assertIsInstance(
133133
factory.create(exiv2.ImageType.jpeg), exiv2.Image)
134+
self.assertIsInstance(factory.createIo(self.image_data), exiv2.BasicIo)
135+
self.check_result(factory.getType(self.image_data),
136+
exiv2.ImageType, exiv2.ImageType.jpeg)
137+
self.check_result(factory.getType(io),
138+
exiv2.ImageType, exiv2.ImageType.jpeg)
139+
self.assertIsInstance(factory.open(self.image_data), exiv2.Image)
140+
if not exiv2.versionInfo()['EXV_ENABLE_FILESYSTEM']:
141+
self.skipTest('EXV_ENABLE_FILESYSTEM is off')
134142
with tempfile.TemporaryDirectory() as tmp_dir:
135143
temp_file = os.path.join(tmp_dir, 'image.jpg')
136144
self.assertIsInstance(
137145
factory.create(exiv2.ImageType.jpeg, temp_file), exiv2.Image)
138146
self.assertIsInstance(factory.createIo(self.image_path), exiv2.BasicIo)
139-
self.assertIsInstance(factory.createIo(self.image_data), exiv2.BasicIo)
140147
self.check_result(factory.getType(self.image_path),
141148
exiv2.ImageType, exiv2.ImageType.jpeg)
142-
self.check_result(factory.getType(self.image_data),
143-
exiv2.ImageType, exiv2.ImageType.jpeg)
144-
self.check_result(factory.getType(io),
145-
exiv2.ImageType, exiv2.ImageType.jpeg)
146149
self.assertIsInstance(factory.open(self.image_path), exiv2.Image)
147-
self.assertIsInstance(factory.open(self.image_data), exiv2.Image)
148150

149151
def test_ref_counts(self):
150152
# opening from data keeps reference to buffer

tests/test_preview.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def test_PreviewImage(self):
5959
self.check_result(preview.mimeType(), str, 'image/jpeg')
6060
self.check_result(preview.size(), int, 2532)
6161
self.check_result(preview.width(), int, 160)
62+
if not exiv2.versionInfo()['EXV_ENABLE_FILESYSTEM']:
63+
self.skipTest('EXV_ENABLE_FILESYSTEM is off')
6264
with tempfile.TemporaryDirectory() as tmp_dir:
6365
temp_file = os.path.join(tmp_dir, 'image.jpg')
6466
self.assertEqual(preview.writeFile(temp_file), 2532)

0 commit comments

Comments
 (0)