Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
c843775
fix: Dev rebuild
tmathern May 29, 2025
e0b9bf3
fix: Install package from local
tmathern May 29, 2025
7fdb6e3
fix: Temp deactivation of tests to debug publishing
tmathern May 29, 2025
0b580e3
fix: split install and wheel build step
tmathern May 29, 2025
b885d6f
fix: Debug Linux build
tmathern May 29, 2025
e9ede9b
fix: Simplify deps graph
tmathern May 29, 2025
2a9911d
fix: Source dist
tmathern May 29, 2025
4380c4f
fix: Fix warning
tmathern May 29, 2025
a8ca466
fix: Restore macos_x86
tmathern May 29, 2025
5ad5832
fix: Restore macos_aarch64
tmathern May 29, 2025
737d418
fix: Restore windows step
tmathern May 29, 2025
251169f
fix: Introduce reusable workflow
tmathern May 29, 2025
13ccf44
fix: Permissions
tmathern May 29, 2025
883580a
fix: restore tests step
tmathern May 29, 2025
d46ab70
fix: Pytest is touchy about venv
tmathern May 29, 2025
650da56
fix: Missing deps
tmathern May 29, 2025
3c667f9
fix: split out windows tests
tmathern May 29, 2025
98f6216
fix: split out windows tests 2
tmathern May 29, 2025
8b3b3f6
fix: Rename steps
tmathern May 29, 2025
2368fa3
fix: Rename the steps
tmathern May 29, 2025
45a00d2
fix: Test graph
tmathern May 29, 2025
d2d8a7c
fix: name of actions
tmathern May 29, 2025
74b6793
fix: Missing params
tmathern May 29, 2025
f7111dd
fix; conditional check
tmathern May 29, 2025
d641cff
fix: auth requests to avoid rate limtis
tmathern May 29, 2025
3b9ff40
fix: Dirs
tmathern May 29, 2025
bf8d4aa
fix: test wheel
tmathern May 29, 2025
31d73b0
fix: Just build
tmathern May 29, 2025
0638914
fix: Test wheels
tmathern May 30, 2025
3bc7b26
fix: Debug build
tmathern May 30, 2025
7e04776
fix: Debug build
tmathern May 30, 2025
75783d1
fix: Debug build
tmathern May 30, 2025
9464426
fix: Debug build
tmathern May 30, 2025
5a4213c
fix: Debug build
tmathern May 30, 2025
a360278
fix: Debug build
tmathern May 30, 2025
b23bb1c
fix: Debug build
tmathern May 30, 2025
3c74b32
fix: Debug build
tmathern May 30, 2025
e322562
fix: Debug build
tmathern May 30, 2025
ac90962
fix: Version number check
tmathern May 30, 2025
86f697b
fix: Version mismatch issue
tmathern May 30, 2025
3ccc9f3
fix: Rename wheels
tmathern May 30, 2025
824ec7d
fix: Build change
tmathern May 30, 2025
c3b0fb4
fix: follow-up text processing fix
tmathern May 30, 2025
659cf01
fix: Drop bdist_wheel use
tmathern May 30, 2025
8129de2
fix: Missed a spot
tmathern May 30, 2025
c86dfdb
fix: License inclusion in wheel tweaks
tmathern May 30, 2025
472e1c3
fix: Add back the deny.toml file
tmathern May 30, 2025
2b7ffcb
fix: sdist build
tmathern May 30, 2025
4b035b9
fix: Clean up deps
tmathern May 30, 2025
ddfbd76
fix: setuptools bug handling
tmathern May 30, 2025
ed21cb9
fix: Better makefile
tmathern May 30, 2025
dda8a5d
fix: deps oversight
tmathern May 30, 2025
825f841
fix: Split deps
tmathern May 30, 2025
c51ca63
fix: Space typo
tmathern May 30, 2025
6ff7c78
fix: bump version
tmathern May 30, 2025
70f98d4
fix: Upload
tmathern May 30, 2025
266982d
fix: wheel upload debug
tmathern May 30, 2025
f758144
fix over-eager version up
tmathern May 30, 2025
4a8ea4d
fix over-eager version up
tmathern May 30, 2025
6abb067
fix over-eager version up
tmathern May 30, 2025
38d61a7
fix: upload of wheels
tmathern May 30, 2025
34aa16c
fix: upload of wheels
tmathern May 30, 2025
9c71f70
fix: upload of wheels
tmathern May 30, 2025
24c2465
fix: upload of wheels
tmathern May 30, 2025
2f844ed
fix: upload of wheels
tmathern May 30, 2025
b1b908b
fix: upload of wheels
tmathern May 30, 2025
8e73614
fix: upload of wheels
tmathern May 30, 2025
226bc77
fix: upload of wheels
tmathern May 30, 2025
9e320c9
fix: upload of wheels
tmathern May 30, 2025
d900d85
fix: upload of wheels
tmathern May 30, 2025
bb28119
fix: upload of wheels
tmathern May 30, 2025
db0d184
fix: upload of wheels
tmathern May 30, 2025
2af8e13
fix: upload of wheels
tmathern May 30, 2025
05aa171
fix: upload of wheels
tmathern May 30, 2025
5252007
fix: fix warning
tmathern May 30, 2025
2492b88
fix: upload of wheels
tmathern May 30, 2025
6ae1e65
fix: upload of wheels
tmathern May 30, 2025
85ebe7c
fix: upload of wheels
tmathern May 30, 2025
bf1b7c1
fix: upload of wheels
tmathern May 30, 2025
8f8361d
fix: upload of wheels
tmathern May 30, 2025
4b77a03
fix: upload of wheels
tmathern May 30, 2025
2fe7ad9
fix: upload of wheels
tmathern May 30, 2025
5da91d5
fix: upload of wheels
tmathern May 30, 2025
211ceeb
fix: upload of wheels
tmathern May 30, 2025
1e4c374
fix: upload of wheels
tmathern May 30, 2025
3f69012
fix: upload of wheels
tmathern May 30, 2025
382187b
feat: manylinux support (#109)
tmathern May 30, 2025
091758a
fix: upload of wheels
tmathern May 30, 2025
184584d
fix: upload of wheels
tmathern May 30, 2025
b981e45
fix: upload of wheels
tmathern May 30, 2025
71a1d8b
fix: upload of wheels
tmathern May 31, 2025
1a631ed
fix: upload of wheels
tmathern May 31, 2025
c40da61
fix: Update test setup
tmathern May 31, 2025
0a4c347
fix: upload of wheels
tmathern May 31, 2025
b2b3603
fix: merge commit
tmathern May 31, 2025
64deb67
fix: upload of wheels
tmathern May 31, 2025
b9a8f97
fix: upload of wheels
tmathern May 31, 2025
c4e36d4
fix: upload of wheels
tmathern May 31, 2025
f58304c
fix: upload of wheels
tmathern May 31, 2025
0f94d4c
fix: upload of wheels
tmathern May 31, 2025
62c0aa0
fix: Fix setups once more (#110)
tmathern May 31, 2025
ee12132
fix: Test
tmathern May 31, 2025
b3371b7
fix: Add test
tmathern May 31, 2025
f5623ab
fix: Refactor tests
tmathern May 31, 2025
bfdca20
fix: Reader test
tmathern May 31, 2025
1cc2e29
fix: Update readme
tmathern May 31, 2025
83f8af0
fix: Docs
tmathern May 31, 2025
15e0e22
fix: Refactor
tmathern May 31, 2025
905e4b2
fix: benchmark
tmathern May 31, 2025
2c9e44b
fix: CLeaning up
tmathern May 31, 2025
5ad9392
fix: Stream tests
tmathern May 31, 2025
d17f373
fix: Reader tests
tmathern May 31, 2025
4de674b
fix: Builder double close test
tmathern May 31, 2025
6e78c6c
fix: Clean up
tmathern May 31, 2025
3a51eae
Resolve merge conflict: Keep updated version of tests/_test_api.py fr…
tmathern May 31, 2025
84a6103
fix: Clean up
tmathern May 31, 2025
050ca3c
ci: Merge branch 'mathern/pypitest-setup' into mathern/manywheels
tmathern May 31, 2025
a47891a
fix: Remove debug logs
tmathern May 31, 2025
bd148f2
fix: Fix typo
tmathern May 31, 2025
dcb862c
fix: Stream exception
tmathern May 31, 2025
0b22cea
fix: docs & more tests (#111)
tmathern May 31, 2025
7273647
fix: Threaded reading
tmathern May 31, 2025
b61f5c5
fix: Threading tests
tmathern May 31, 2025
9620ff0
fix: Interleaved thread test
tmathern May 31, 2025
811cf93
fix: Threading
tmathern May 31, 2025
6f9544c
fix: More tests
tmathern May 31, 2025
9057f20
fix: Test updates
tmathern May 31, 2025
dbd3ad2
fix: Test updates
tmathern May 31, 2025
9abd7a7
fix: Add some async tests
tmathern May 31, 2025
04f240d
fix: Test updates
tmathern May 31, 2025
b8aefa8
fix: Test updates
tmathern May 31, 2025
862470e
fix: Test updates
tmathern May 31, 2025
1b08ff8
fix: Test updates
tmathern May 31, 2025
7c3a0b5
fix: Add ingredients tests
tmathern May 31, 2025
26b44ef
fix: Test ingredient
tmathern May 31, 2025
6ec6434
fix: Test ingredient
tmathern May 31, 2025
195322f
fix: Add ingredient from stream
tmathern May 31, 2025
bc616d2
fix: Ingredient from stream
tmathern May 31, 2025
f3f7f6c
fix: Reorder test
tmathern May 31, 2025
60ac0d8
fix: Thread
tmathern May 31, 2025
d1dad05
fix: Threading with asyncio
tmathern May 31, 2025
ad71126
fix: RUn all the tests
tmathern May 31, 2025
3dbf41f
fix: refactor tests
tmathern May 31, 2025
0e2e674
fix: refactor and format
tmathern May 31, 2025
19eaa2e
fix: refactor and format 2
tmathern May 31, 2025
dbad283
ci: Merge commit
tmathern May 31, 2025
c7decbe
fix: benchmark
tmathern May 31, 2025
92664d9
fix: FOrmat
tmathern May 31, 2025
3f8c8a7
fix: Add test for contention
tmathern May 31, 2025
9f73274
fix: Add test for contention 2
tmathern May 31, 2025
9d922f6
fix: Threads
tmathern Jun 2, 2025
811950a
fix: Paths use and some timing
tmathern Jun 2, 2025
3147903
fix: autopep8
tmathern Jun 2, 2025
2392e15
fix: Format
tmathern Jun 2, 2025
575821c
fix: Undo test formating as json formatting seems touchy
tmathern Jun 2, 2025
3d5e7e2
fix: test_read_ingredient_file
tmathern Jun 2, 2025
68ba961
fix: format
tmathern Jun 2, 2025
8cc4dc9
fix: format
tmathern Jun 2, 2025
b3d5926
fix: fix a bug found by tests
tmathern Jun 2, 2025
8bceb5b
fix: Refactor sign_file to use new API internally, but keep the emtho…
tmathern Jun 2, 2025
cb7187c
fix: Clean up
tmathern Jun 2, 2025
91d1b66
fix: CLean up
tmathern Jun 2, 2025
5dbc6a7
fix: Remove debug code
tmathern Jun 2, 2025
128508c
fix: Ignore deprecation warnings in test logs
tmathern Jun 2, 2025
9dddb72
fix: One more clean up
tmathern Jun 2, 2025
8f94192
fix: One more clean up
tmathern Jun 2, 2025
92af391
fix: Add tests for coverage
alextrnnn Jun 6, 2025
6f51e55
Merge branch 'gpeacock/no_rust' into tran/test-coverage
alextrnnn Jun 6, 2025
623f33a
fix: Release reader from memory and typo
alextrnnn Jun 6, 2025
8a3b7a2
fix: Reset settings that would cause other test to fail
alextrnnn Jun 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ source .venv/bin/activate

# load project dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt

# download library artifacts for the current version you want, eg v0.55.0
python scripts/download_artifacts.py c2pa-v0.55.0
Expand Down
121 changes: 120 additions & 1 deletion tests/test_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import warnings

from c2pa import Builder, C2paError as Error, Reader, C2paSigningAlg as SigningAlg, C2paSignerInfo, Signer, sdk_version
from c2pa.c2pa import Stream, read_ingredient_file, read_file, sign_file
from c2pa.c2pa import Stream, read_ingredient_file, read_file, sign_file, load_settings

# Suppress deprecation warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
Expand Down Expand Up @@ -54,6 +54,17 @@ def test_stream_read_and_parse(self):
title = manifest_store["manifests"][manifest_store["active_manifest"]]["title"]
self.assertEqual(title, "C.jpg")

def test_stream_read_string_stream(self):
with Reader("image/jpeg", self.testPath) as reader:
json_data = reader.json()
self.assertIn("C.jpg", json_data)

def test_stream_read_string_stream_and_parse(self):
with Reader("image/jpeg", self.testPath) as reader:
manifest_store = json.loads(reader.json())
title = manifest_store["manifests"][manifest_store["active_manifest"]]["title"]
self.assertEqual(title, "C.jpg")

def test_reader_bad_format(self):
with self.assertRaises(Error.NotSupported):
with open(self.testPath, "rb") as file:
Expand Down Expand Up @@ -91,6 +102,13 @@ def test_reader_close_cleanup(self):
self.assertIsNone(reader._own_stream)
# Verify reader is marked as closed
self.assertTrue(reader._closed)

def test_resource_to_stream_on_closed_reader(self):
Comment thread
alextrnnn marked this conversation as resolved.
"""Test that resource_to_stream correctly raises error on closed."""
reader = Reader("image/jpeg", self.testPath)
reader.close()
with self.assertRaises(Error):
reader.resource_to_stream("", io.BytesIO(bytearray()))

def test_read_all_files(self):
"""Test reading C2PA metadata from all files in the fixtures/files-for-reading-tests directory"""
Expand Down Expand Up @@ -198,6 +216,11 @@ def setUp(self):
]
}

def test_reserve_size_on_closed_signer(self):
self.signer.close()
with self.assertRaises(Error):
self.signer.reserve_size()

def test_streams_sign(self):
with open(self.testPath, "rb") as file:
builder = Builder(self.manifestDefinition)
Expand Down Expand Up @@ -313,6 +336,17 @@ def test_builder_double_close(self):
# Verify builder is closed
with self.assertRaises(Error):
builder.set_no_embed()

def test_builder_add_ingredient_on_closed_builder(self):
"""Test that exception is raised when trying to add ingredient after close."""
builder = Builder(self.manifestDefinition)

builder.close()

with self.assertRaises(Error):
ingredient_json = '{"test": "ingredient"}'
with open(self.testPath, 'rb') as f:
builder.add_ingredient(ingredient_json, "image/jpeg", f)

def test_builder_add_ingredient(self):
"""Test Builder class operations with a real file."""
Expand Down Expand Up @@ -395,6 +429,55 @@ def test_builder_sign_with_ingredient(self):

builder.close()

def test_builder_sign_with_duplicate_ingredient(self):
"""Test Builder class operations with a real file."""
# Test creating builder from JSON

builder = Builder.from_json(self.manifestDefinition)
assert builder._builder is not None

# Test adding ingredient
ingredient_json = '{"title": "Test Ingredient"}'
with open(self.testPath3, 'rb') as f:
builder.add_ingredient(ingredient_json, "image/jpeg", f)
builder.add_ingredient(ingredient_json, "image/jpeg", f)
builder.add_ingredient(ingredient_json, "image/jpeg", f)

with open(self.testPath2, "rb") as file:
output = io.BytesIO(bytearray())
builder.sign(self.signer, "image/jpeg", file, output)
output.seek(0)
reader = Reader("image/jpeg", output)
json_data = reader.json()
manifest_data = json.loads(json_data)

# Verify active manifest exists
self.assertIn("active_manifest", manifest_data)
active_manifest_id = manifest_data["active_manifest"]

# Verify active manifest object exists
self.assertIn("manifests", manifest_data)
self.assertIn(active_manifest_id, manifest_data["manifests"])
active_manifest = manifest_data["manifests"][active_manifest_id]

# Verify ingredients array exists in active manifest
self.assertIn("ingredients", active_manifest)
self.assertIsInstance(active_manifest["ingredients"], list)
self.assertTrue(len(active_manifest["ingredients"]) > 0)

# Verify the first ingredient's title matches what we set
first_ingredient = active_manifest["ingredients"][0]
self.assertEqual(first_ingredient["title"], "Test Ingredient")

# Verify subsequent labels are unique and have a double underscore with a monotonically inc. index
second_ingredient = active_manifest["ingredients"][1]
self.assertTrue(second_ingredient["label"].endswith("__1"))

third_ingredient = active_manifest["ingredients"][2]
self.assertTrue(third_ingredient["label"].endswith("__2"))

builder.close()

def test_builder_sign_with_ingredient_from_stream(self):
"""Test Builder class operations with a real file using stream for ingredient."""
# Test creating builder from JSON
Expand Down Expand Up @@ -533,6 +616,37 @@ def test_builder_sign_with_multiple_ingredients_from_stream(self):

builder.close()

def test_builder_set_remote_url(self):
"""Test setting the remote url of a builder."""
builder = Builder.from_json(self.manifestDefinition)
builder.set_remote_url("http://this_does_not_exist/foo.jpg")

with open(self.testPath2, "rb") as file:
output = io.BytesIO(bytearray())
builder.sign(self.signer, "image/jpeg", file, output)
output.seek(0)
d = output.read()
self.assertIn(b'provenance="http://this_does_not_exist/foo.jpg"', d)

def test_builder_set_remote_url_no_embed(self):
"""Test setting the remote url of a builder with no embed flag."""
builder = Builder.from_json(self.manifestDefinition)
load_settings(r'{"verify": { "remote_manifest_fetch": false} }')
builder.set_no_embed()
builder.set_remote_url("http://this_does_not_exist/foo.jpg")

with open(self.testPath2, "rb") as file:
output = io.BytesIO(bytearray())
builder.sign(self.signer, "image/jpeg", file, output)
output.seek(0)
with self.assertRaises(Error) as e:
Reader("image/jpeg", output)

self.assertIn("http://this_does_not_exist/foo.jpg", e.exception.message)

# Return back to default settings
load_settings(r'{"verify": { "remote_manifest_fetch": true} }')

class TestStream(unittest.TestCase):
def setUp(self):
# Create a temporary file for testing
Expand Down Expand Up @@ -692,6 +806,11 @@ def tearDown(self):
import shutil
shutil.rmtree(self.temp_data_dir)

def test_invalid_settings_str(self):
"""Test loading a malformed settings string."""
with self.assertRaises(Error):
load_settings(r'{"verify": { "remote_manifest_fetch": false }')

def test_read_ingredient_file(self):
"""Test reading a C2PA ingredient from a file."""
# Test reading ingredient from file with data_dir
Expand Down