Skip to content

Commit e9b9f7a

Browse files
committed
fix: Test stdout output
1 parent 532825e commit e9b9f7a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/c2pa/c2pa.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,20 +1380,22 @@ def wrapped_callback(
13801380
# signature length for correctness.
13811381
try:
13821382
if not data_ptr or data_len <= 0:
1383-
# Error: invalid input, native code will handle if seeing
1384-
# signature size being 0
1383+
# Error: invalid input, invalid so return -1,
1384+
# native code will handle it!
13851385
return -1
13861386

13871387
# Convert C pointer to Python bytes
13881388
data = bytes(data_ptr[:data_len])
13891389
if not data:
1390-
# Error: empty data, native code will handle it!
1390+
# Error: empty data, invalid so return -1,
1391+
# native code will also handle it!
13911392
return -1
13921393

13931394
# Call the user's callback
13941395
signature = callback(data)
13951396
if not signature:
1396-
# Error: empty signature, native code will handle that too!
1397+
# Error: empty signature, invalid so return -1,
1398+
# native code will handle that too!
13971399
return -1
13981400

13991401
# Copy the signature back to the C buffer (since callback is
@@ -1408,6 +1410,8 @@ def wrapped_callback(
14081410
print(
14091411
error_messages['callback_error'].format(
14101412
str(e)), file=sys.stderr)
1413+
# Error: exception raised, invalid so return -1,
1414+
# native code will handle the error when seeing -1
14111415
return -1
14121416

14131417
# Encode strings with error handling in case it's invalid UTF8

tests/test_unit_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ def test_read_cawg_data_file(self):
244244

245245
class TestBuilder(unittest.TestCase):
246246
def setUp(self):
247+
# Filter deprecation warnings for create_signer function
248+
warnings.filterwarnings("ignore", message="The create_signer function is deprecated")
249+
247250
# Use the fixtures_dir fixture to set up paths
248251
self.data_dir = FIXTURES_DIR
249252
self.testPath = DEFAULT_TEST_FILE
@@ -1223,6 +1226,7 @@ def setUp(self):
12231226
# Filter specific deprecation warnings for legacy API tests
12241227
warnings.filterwarnings("ignore", message="The read_file function is deprecated")
12251228
warnings.filterwarnings("ignore", message="The sign_file function is deprecated")
1229+
warnings.filterwarnings("ignore", message="The read_ingredient_file function is deprecated")
12261230

12271231
self.data_dir = FIXTURES_DIR
12281232
self.testPath = DEFAULT_TEST_FILE

0 commit comments

Comments
 (0)