Skip to content

Commit 1e9e75d

Browse files
committed
fix: Added a test case
1 parent 838c97c commit 1e9e75d

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

tests/test_unit_tests.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_reader_close_cleanup(self):
104104
self.assertIsNone(reader._own_stream)
105105
# Verify reader is marked as closed
106106
self.assertTrue(reader._closed)
107-
107+
108108
def test_resource_to_stream_on_closed_reader(self):
109109
"""Test that resource_to_stream correctly raises error on closed."""
110110
reader = Reader("image/jpeg", self.testPath)
@@ -168,6 +168,50 @@ def test_read_all_files(self):
168168
except Exception as e:
169169
self.fail(f"Failed to read metadata from {filename}: {str(e)}")
170170

171+
def test_read_all_files_using_extension(self):
172+
"""Test reading C2PA metadata from all files in the fixtures/files-for-reading-tests directory"""
173+
reading_dir = os.path.join(self.data_dir, "files-for-reading-tests")
174+
175+
# Map of file extensions to MIME types
176+
extensions = {
177+
'.jpg': 'image/jpeg',
178+
'.jpeg': 'image/jpeg',
179+
'.png': 'image/png',
180+
}
181+
182+
# Skip system files
183+
skip_files = {
184+
'.DS_Store'
185+
}
186+
187+
for filename in os.listdir(reading_dir):
188+
if filename in skip_files:
189+
continue
190+
191+
file_path = os.path.join(reading_dir, filename)
192+
if not os.path.isfile(file_path):
193+
continue
194+
195+
# Get file extension and corresponding MIME type
196+
_, ext = os.path.splitext(filename)
197+
ext = ext.lower()
198+
if ext not in extensions:
199+
continue
200+
201+
try:
202+
with open(file_path, "rb") as file:
203+
# Remove the leading dot
204+
parsed_extension = ext[1:]
205+
reader = Reader(parsed_extension, file)
206+
json_data = reader.json()
207+
self.assertIsInstance(json_data, str)
208+
# Verify the manifest contains expected fields
209+
manifest = json.loads(json_data)
210+
self.assertIn("manifests", manifest)
211+
self.assertIn("active_manifest", manifest)
212+
except Exception as e:
213+
self.fail(f"Failed to read metadata from {filename}: {str(e)}")
214+
171215

172216
class TestBuilder(unittest.TestCase):
173217
def setUp(self):

0 commit comments

Comments
 (0)