Skip to content

Commit

Permalink
Add selftest command
Browse files Browse the repository at this point in the history
  • Loading branch information
titusz committed Jun 20, 2023
1 parent 33bed59 commit af4c0f4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
9 changes: 9 additions & 0 deletions iscc_sdk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 9 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit af4c0f4

Please sign in to comment.