From af4c0f423d2242a21f1bff25839e3b5922352873 Mon Sep 17 00:00:00 2001 From: Titusz Pan Date: Tue, 20 Jun 2023 14:06:22 +0200 Subject: [PATCH] Add selftest command --- iscc_sdk/cli.py | 9 +++++++++ tests/conftest.py | 6 +++--- tests/test_cli.py | 12 +++++++++--- tests/test_main.py | 8 +++++--- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/iscc_sdk/cli.py b/iscc_sdk/cli.py index 5f1875b..595d4fc 100644 --- a/iscc_sdk/cli.py +++ b/iscc_sdk/cli.py @@ -142,5 +142,14 @@ def batch(folder: Path, workers: int = os.cpu_count()): progress.update(task_id, advance=file_sizes_dict[fp], refresh=True) +@app.command() +def selftest(): + """Run conformance tests.""" + log.add(console.print, format=log_formatter, colorize=True) + from iscc_core.conformance import conformance_selftest + + conformance_selftest() + + if __name__ == "__main__": # pragma: no cover app() diff --git a/tests/conftest.py b/tests/conftest.py index d5c9480..7b47c01 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -113,10 +113,10 @@ def epub_file(tmp_path_factory): return dst.as_posix() -@pytest.fixture(scope="module") -def image_dir(tmp_path_factory): +@pytest.fixture(scope="session") +def asset_tree(tmp_path_factory): src = images()[0].parent - dst = tmp_path_factory.mktemp("images") + dst = tmp_path_factory.mktemp("tree") imgdir = shutil.copytree(src, dst, dirs_exist_ok=True) subdir = imgdir / "subdir" subdir.mkdir() diff --git a/tests/test_cli.py b/tests/test_cli.py index c289388..ea21fd5 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -85,9 +85,15 @@ def test_cli_batch_not_a_folder(): assert "Invalid folder" in result.stdout -def test_cli_batch(image_dir): +def test_cli_batch(asset_tree): from iscc_sdk.cli import iter_unprocessed - result = runner.invoke(app, ["batch", image_dir.as_posix()]) + result = runner.invoke(app, ["batch", asset_tree.as_posix()]) assert result.exit_code == 0 - assert list(iter_unprocessed(image_dir)) == [] + assert list(iter_unprocessed(asset_tree)) == [] + + +def test_cli_selftest(): + result = runner.invoke(app, ["selftest"]) + assert result.exit_code == 0 + assert "PASSED" in result.stdout diff --git a/tests/test_main.py b/tests/test_main.py index 1fd75f7..27a8410 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -35,15 +35,17 @@ def test_code_iscc_image(jpg_file): } -def test_code_iscc_audio(mp3_file): - assert idk.code_iscc(mp3_file).dict() == { +def test_code_iscc_audio(): + from iscc_samples import audios + + assert idk.code_iscc(audios("mp3")[0].as_posix()).dict() == { "@type": "AudioObject", "iscc": "ISCC:KIC2JKSX7OH5PBIENISKEJTS4TRKHYJBCZDNLQXYILWJHQAP3N3KPTQ", "name": "Belly Button", "datahash": "1e20ec93c00fdb76a7cec587e4a2bddfa8d0a0bac8110d0c7130c351ea07c366d626", "duration": 15, "filesize": 225707, - "filename": "audio.mp3", + "filename": "demo.mp3", "mediatype": "audio/mpeg", "metahash": "1e20c4933dc8c03ea58568159a1cbfb04132c7db93b6b4cd025ffd4db37f52a4756f", "mode": "audio",