diff options
| author | Egor Tensin <egor@tensin.name> | 2026-09-29 23:44:16 +0500 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-09-29 23:45:40 +0500 |
| commit | eec673b5c0122e359bf00b0136783a32e8a77df9 (patch) | |
| tree | 61457ccf0d65331f1411b28aa7ba2ad964191ba2 /test/tst-sessions.sh | |
| parent | remove annoying trailing period from repo URLs (diff) | |
| download | vk-scripts-eec673b5c0122e359bf00b0136783a32e8a77df9.tar.gz vk-scripts-eec673b5c0122e359bf00b0136783a32e8a77df9.zip | |
test: rework using the approach from my other projectsv1.2.0
The tests are now run using a framework common to my other projects,
like config-links & tag-release.
Diffstat (limited to 'test/tst-sessions.sh')
| -rw-r--r-- | test/tst-sessions.sh | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/tst-sessions.sh b/test/tst-sessions.sh new file mode 100644 index 0000000..2885d0c --- /dev/null +++ b/test/tst-sessions.sh @@ -0,0 +1,51 @@ +test_db_path="$script_dir/data/test_db.csv" +readonly test_db_path + +_test_format() { + local output_path + output_path="$( mktemp --tmpdir="$test_root_dir" )" + + test_run_module vk.tracking.sessions "$@" "$test_db_path" "$output_path" + + if [ ! -s "$output_path" ]; then + fail "Output file '$output_path' either doesn't exists or is empty" + return 1 + fi + + if file --brief --dereference --mime -- "$output_path" | grep --quiet -- 'charset=binary$'; then + log 'Output is a binary file, not going to show that' + return 0 + fi + + cat -- "$output_path" >&2 +} + +_test_group_by() { + local group_by + for group_by; do + local format + for format in csv json plot; do + _test_format --output-format "$format" --group-by "$group_by" + done + done +} + +_test_main() { + _test_group_by user + _test_group_by hour + _test_group_by date + _test_group_by weekday +} + +_fix_matplotlib() { + # Get rid of: + # tkinter.TclError: no display name and no $DISPLAY environment variable + mkdir -p -- ~/.config/matplotlib + echo 'backend: Agg' > ~/.config/matplotlib/matplotlibrc +} + +test_run() { + test_setup + _fix_matplotlib + _test_main +} |
