Skip to content

Commit

Permalink
basic cram tests for ticket #7
Browse files Browse the repository at this point in the history
Since I still use debspawn, I can't use autopkgtest, see lkhq/debspawn#13
so instead, just add cram3 &c to the build-deps and use pybuild --test-custom
  • Loading branch information
eichin committed Sep 14, 2024
1 parent 3d4d2cf commit 67ca398
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 2 deletions.
124 changes: 124 additions & 0 deletions cramtests/index.md
Original file line number Diff line number Diff line change
@@ -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'
> <?xml version="1.0" encoding="UTF-8"?>
> <KPhotoAlbum version="10" compressed="0">
> <Categories>
> </Categories>
> <images>
> </images>
> </KPhotoAlbum>
> 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'
> <?xml version="1.0" encoding="UTF-8"?>
> <KPhotoAlbum version="10" compressed="0">
> <Categories>
> <Category name="Keywords">
> <value value="test" id="1"/>
> </Category>
> </Categories>
> <images>
> <image file="test_img_1.jpg" label="" startDate="1980-01-01T00:00:10">
> <options>
> <option name="Keywords">
> <value value="test"/>
> </option>
> </options>
> </image>
> <image file="test_img_2.jpg" label="" startDate="1980-01-02T00:00:10">
> <options/>
> </image>
> </images>
> </KPhotoAlbum>
> 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
<https://github.com/eichin/thok-kphotoalbum-grep/issues/3> about
making it more completely valid/useful.

$ kpa-grep --index /tmp/kpa-idx.xml --tag test --xml
<image file="test_img_1.jpg" label="" startDate="1980-01-01T00:00:10">
<options>
<option name="Keywords">
<value value="test" />
</option>
</options>
</image>
(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...
26 changes: 26 additions & 0 deletions cramtests/runs-at-all.md
Original file line number Diff line number Diff line change
@@ -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]
15 changes: 13 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ Source: kpa-grep
Section: unknown
Priority: extra
Maintainer: Mark Eichin <[email protected]>
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:
.
Expand Down
3 changes: 3 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 67ca398

Please sign in to comment.