From 67ca3984a16131682a47590f7e0a74500e750c53 Mon Sep 17 00:00:00 2001 From: Mark Eichin Date: Sat, 14 Sep 2024 16:03:34 -0400 Subject: [PATCH] basic cram tests for ticket #7 Since I still use debspawn, I can't use autopkgtest, see https://github.com/lkhq/debspawn/issues/13 so instead, just add cram3 &c to the build-deps and use pybuild --test-custom --- cramtests/index.md | 124 +++++++++++++++++++++++++++++++++++++++ cramtests/runs-at-all.md | 26 ++++++++ debian/control | 15 ++++- debian/rules | 3 + 4 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 cramtests/index.md create mode 100644 cramtests/runs-at-all.md diff --git a/cramtests/index.md b/cramtests/index.md new file mode 100644 index 0000000..371374b --- /dev/null +++ b/cramtests/index.md @@ -0,0 +1,124 @@ +# Tests with constructed index files. + +## setup + +Find the built version (we haven't done the install step yet) and add +that to `PATH`. + + $ SCRIPTSBUILTDIR=$(realpath ${TESTDIR}/../build/scripts-*) + $ export PATH=${SCRIPTSBUILTDIR}:$PATH + +## basic index + +### Empty file, no tags. + + $ cat > /tmp/kpa-empty-idx.xml <<'KPA' + > + > + > + > + > + > + > + > KPA + +Confirm that it parses. + + $ kpa-grep --index /tmp/kpa-empty-idx.xml + +Confirm that dump-tags handles it. + + $ kpa-grep --index /tmp/kpa-empty-idx.xml --dump-tags + +Confirm that a nonexistent tag doesn't break. + + $ kpa-grep --index /tmp/kpa-empty-idx.xml --tag fred + +### Two images, one keyword applied to one of them. + + $ cat > /tmp/kpa-idx.xml <<'KPA' + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > KPA + +No filters should give all of the files. + + $ kpa-grep --index /tmp/kpa-idx.xml + /tmp/test_img_1.jpg + /tmp/test_img_2.jpg + +Dump tags should work. + + $ kpa-grep --index /tmp/kpa-idx.xml --dump-tags + Keywords test + +The files are explicitly ancient (1980) so "since last week" should +not produce them. + + $ kpa-grep --index /tmp/kpa-idx.xml --dump-tags --since "last week" + +Known tag path gets printed. + + $ kpa-grep --index /tmp/kpa-idx.xml --tag test + /tmp/test_img_1.jpg + +Known tag generates expected json output. + + $ kpa-grep --index /tmp/kpa-idx.xml --tag test --json + {"file": "test_img_1.jpg", "label": "", "startDate": "1980-01-01T00:00:10", "Keywords": ["test"]} + +Get a second opinion on the validity of the json output. + + $ kpa-grep --index /tmp/kpa-idx.xml --tag test --json | jq -r .file + test_img_1.jpg + +xml whitespace should probably be better, not just for the test, see + about +making it more completely valid/useful. + + $ kpa-grep --index /tmp/kpa-idx.xml --tag test --xml + + + + + + (no-eol) + +Test that `--exclude` gives us the other filename. + + $ kpa-grep --index /tmp/kpa-idx.xml --exclude test + /tmp/test_img_2.jpg + +Confirm that `--path` picks out an explicit file. + + $ kpa-grep --index /tmp/kpa-idx.xml --path test_img_1.jpg + /tmp/test_img_1.jpg + +Confirm that `--path` with a full path also works (the paths stored in +the XML file are relative to it - the above path worked with the exact +match, this is testing the "strip off the common prefix" feature.) + + $ kpa-grep --index /tmp/kpa-idx.xml --path /tmp/test_img_1.jpg + /tmp/test_img_1.jpg + +TODO: switch these to files that are in the cramtests dir... diff --git a/cramtests/runs-at-all.md b/cramtests/runs-at-all.md new file mode 100644 index 0000000..9b0067d --- /dev/null +++ b/cramtests/runs-at-all.md @@ -0,0 +1,26 @@ +# Make sure `kpa-grep` runs at all. + +## setup + +Find the built version (we haven't done the install step yet) and add +that to `PATH`. + + $ SCRIPTSBUILTDIR=$(realpath ${TESTDIR}/../build/scripts-*) + $ export PATH=${SCRIPTSBUILTDIR}:$PATH + + +Run it with `--help` which should always work, even without an index. + + $ kpa-grep --help 1>/dev/null + +Make sure it fails cleanly without an index. + + $ kpa-grep --dump-tags + No kphotoalbum index given (with --index or in kphotoalbumrc) + [1] + +Make sure it fails cleanly with an index arg that is missing. + + $ kpa-grep --index /tmp/missing-index.xml + kphotoalbum index /tmp/missing-index.xml not found + [1] diff --git a/debian/control b/debian/control index 5980c58..0cc4bdb 100644 --- a/debian/control +++ b/debian/control @@ -2,12 +2,23 @@ Source: kpa-grep Section: unknown Priority: extra Maintainer: Mark Eichin -Build-Depends: debhelper (>= 10), dh-python, python3 +Build-Depends: + debhelper (>= 10), + dh-python, + python3, +# test deps + python3-cram, + jq, +# duplicates of install-deps so we can run also tests at build time + python3-dateutil, + python3-parsedatetime, Standards-Version: 3.9.1 Package: kpa-grep Architecture: all -Depends: ${misc:Depends}, python3-dateutil, python3-parsedatetime +Depends: ${misc:Depends}, + python3-dateutil, + python3-parsedatetime, Description: Simple CLI tool for pulling subsets of photos out of KPhotoAlbum kpa-grep scans the index.xml directly. Base example: . diff --git a/debian/rules b/debian/rules index a7a492c..f582b06 100755 --- a/debian/rules +++ b/debian/rules @@ -9,5 +9,8 @@ # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 +export PYBUILD_TEST_ARGS:=cram3 --indent=4 {dir}/cramtests/*.md +export PYBUILD_TEST_CUSTOM:=1 + %: dh $@ --buildsystem=pybuild --with=python3