Skip to content

Commit 0a4e0be

Browse files
committed
add some unit tests and automation
1 parent 8fc992f commit 0a4e0be

File tree

6 files changed

+92
-1
lines changed

6 files changed

+92
-1
lines changed

.github/workflows/build.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
build-nightly-only:
11+
name: Build nightly only
12+
runs-on: ubuntu-latest
13+
container: quay.io/pypa/manylinux2014_x86_64
14+
steps:
15+
- uses: actions/checkout@v1
16+
- name: Install nightly rust
17+
run: curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
18+
# Insert steps here to install you other dependencies. Note that you're running inside of cent os 7, not ubuntu
19+
- name: Installing custom dependency
20+
run: echo "Installing custom dependency"
21+
- name: Build
22+
run: |
23+
source $HOME/.cargo/env
24+
for PYBIN in /opt/python/cp3[6789]*/bin; do
25+
"${PYBIN}/pip" install maturin
26+
"${PYBIN}/maturin" build -m nightly-only/Cargo.toml -i "${PYBIN}/python" --release --manylinux 2014
27+
done
28+
# Auditwheel isn't generally necessary. This is only shown as refernce for cases where you link
29+
# external libraries, in which case you have to set manylinux to off and then use auditwheel repair
30+
- name: Auditwheel repair
31+
run: |
32+
for wheel in nightly-only/target/wheels/*.whl; do
33+
auditwheel repair "${wheel}"
34+
done
35+
36+
37+
# This is similar to the above, except we're only using the lowest supported python version to build a single
38+
# abi3 wheel
39+
build-nightly-only-abi3:
40+
name: Build nightly only abi3
41+
runs-on: ubuntu-latest
42+
container: quay.io/pypa/manylinux2014_x86_64
43+
steps:
44+
- uses: actions/checkout@v1
45+
- name: Install nightly rust
46+
run: curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
47+
- name: Install maturin
48+
run: /opt/python/cp36-cp36m/bin/pip install maturin
49+
- name: Build with maturin
50+
run: |
51+
source $HOME/.cargo/env
52+
/opt/python/cp36-cp36m/bin/maturin build -m nightly-only-abi3/Cargo.toml -i /opt/python/cp36-cp36m/bin/python --release --manylinux 2014
53+
- name: Auditwheel repair
54+
run: auditwheel repair nightly-only-abi3/target/wheels/*.whl

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
debug/
44
target/
55

6+
venv/
7+
68
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
79
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
810
Cargo.lock
@@ -15,6 +17,7 @@ Cargo.lock
1517

1618
# Python caches
1719
__pycache__/
20+
.pytest_cache/
1821

1922
# Mac OS X files
2023
.DS_Store

src/json_api.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,25 @@ pub fn add_manifest_to_file_json(
8484
let signer = signer_info.signer()?;
8585
manifest.embed(&source, &dest, &*signer).map_err(Error::Sdk)
8686
}
87+
88+
#[cfg(test)]
89+
mod tests {
90+
use super::*;
91+
92+
/// returns a path to a file in the fixtures folder
93+
pub fn test_path(path: &str) -> String {
94+
let base = env!("CARGO_MANIFEST_DIR");
95+
format!("{}/{}", base, path)
96+
}
97+
98+
#[test]
99+
fn test_verify_from_file() {
100+
let path = test_path("tests/fixtures/C.jpg");
101+
let result = verify_from_file_json(&path);
102+
assert!(result.is_ok());
103+
let json_report = result.unwrap();
104+
println!("{}", json_report);
105+
assert!(json_report.contains("C.jpg"));
106+
//assert!(!json_report.contains("validation_status"));
107+
}
108+
}

tests/fixtures/C.jpg

135 KB
Loading

tests/test_c2pa.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@
1212
# each license.
1313

1414
import c2pa_python as c2pa
15+
import pytest
1516

1617
def test_version():
1718
assert c2pa.version() == "0.1.0"
1819

1920
def test_sdk_version():
2021
assert c2pa.sdk_version() == "0.25.2"
2122

23+
24+
#def test_verify_from_file():
25+
# json_store = c2pa.verify_from_file_json("tests/fixtures/A.jpg")
26+
# assert not "validation_status" in json_store
27+
28+
def test_verify_from_file_no_store():
29+
with pytest.raises(c2pa.Error.Sdk) as err:
30+
json_store = c2pa.verify_from_file_json("tests/fixtures/A.jpg")
31+
assert str(err.value) == "no JUMBF data found"
32+

tests/training.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ def getitem(d, key):
6969

7070
allowed = True # opt out model, assume training is ok if the assertion doesn't exist
7171
try:
72-
manifest_store = json.loads(c2pa.verify_from_file_json(testOutputFile))
72+
json_store = c2pa.verify_from_file_json(testOutputFile)
73+
manifest_store = json.loads(json_store)
7374

7475
manifest = manifest_store["manifests"][manifest_store["active_manifest"]]
7576
for assertion in manifest["assertions"]:

0 commit comments

Comments
 (0)