Skip to content

Commit e5d6d5b

Browse files
committed
fix: Refactor
1 parent eed499c commit e5d6d5b

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/c2pa/c2pa.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ def add_resource(self, uri: str, stream: Any):
17531753
Builder._ERROR_MESSAGES['resource_error'].format("Unknown error"))
17541754

17551755
def add_ingredient(self, ingredient_json: str, format: str, source: Any):
1756-
"""Add an ingredient to the builder.
1756+
"""Add an ingredient to the builder (facade method).
17571757
The added ingredient's source should be a stream-like object, eg. and open file.
17581758
17591759
Args:
@@ -1836,12 +1836,12 @@ def add_ingredient_from_file_path(
18361836
)
18371837

18381838
try:
1839+
# Does the stream handling to use add_ingredient_from_stream
18391840
with open(filepath, 'rb') as file_stream:
18401841
self.add_ingredient_from_stream(ingredient_json, format, file_stream)
18411842
except FileNotFoundError:
18421843
raise FileNotFoundError(f"File not found: {filepath}")
18431844
except Exception as e:
1844-
# Re-raise C2paError and other exceptions as-is
18451845
raise e
18461846

18471847
def to_archive(self, stream: Any):

tests/test_unit_tests.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,13 +1348,12 @@ def test_signing_manifest_v2(self):
13481348

13491349
def test_builder_add_ingredient_from_file_path(self):
13501350
"""Test Builder class add_ingredient_from_file_path method."""
1351+
13511352
# Suppress the specific deprecation warning for this test, as this is a legacy method
13521353
with warnings.catch_warnings():
13531354
warnings.simplefilter("ignore", DeprecationWarning)
13541355

1355-
# Test creating builder from JSON
13561356
builder = Builder.from_json(self.manifestDefinition)
1357-
assert builder._builder is not None
13581357

13591358
# Test adding ingredient from file path
13601359
ingredient_json = '{"test": "ingredient_from_file_path"}'
@@ -1364,9 +1363,8 @@ def test_builder_add_ingredient_from_file_path(self):
13641363

13651364
def test_builder_sign_with_ingredient_from_file(self):
13661365
"""Test Builder class operations with an ingredient added from file path."""
1367-
# Test creating builder from JSON
1366+
13681367
builder = Builder.from_json(self.manifestDefinition)
1369-
assert builder._builder is not None
13701368

13711369
# Test adding ingredient from file path
13721370
ingredient_json = '{"title": "Test Ingredient From File"}'

0 commit comments

Comments
 (0)