Skip to content

Functional Tests

James edited this page Sep 21, 2022 · 4 revisions

The testdata/ directory in the repo has some minimal test data, but for a more-thorough test, the tools really need to be tested on an actual Obsidian repository with real-world notes in it.

This page is just some commands that I've used (which can be a starting point for others).

PATH Setup

To make this easier, I have symlinked the executable files from ~/src/obstagtools/ (where I have the repo checked out) into ~/bin/, which is on my PATH.

$ cd ~/bin/
$ ln -s ~/src/obstagtools/obs-*.py .
$ rm obs-wikify-yake.py  # because this one is pretty half-baked right now...

obs-filter-vault

Create Personal-only Vault

$ cd ~/tmp/
$ cp -a Worknotes Worknotes.bkup  # just for safety...
$ obs-filter-vault.py Worknotes/ Personal/ COPY tags INCLUDE personal --attachments --debug

Create Work-only Vault

(Continuing from above.)

$ cd ~/tmp/
$ obs-filter-vault.py Worknotes/ Workonly/ COPY tags EXCLUDE personal --attachments --debug

obs-prune-attach

$ cd ~/tmp/
$ obs-prune-attach.py Workonly/
delete:

This should emit nothing aside from delete: (an empty YAML list), because in theory obs-filter-vault.py shouldn't have copied over anything that's not linked.

If we create an unlinked file in the Attachments dir, then it should show up as deletable.

$ touch Workonly/Attachments/garbage_file
$ obs-prune-attach.py Workonly/
delete:
  - Workonly/Attachments/garbage_file

Alternately, this will move garbage_file to TrashDir:

$ obs-prune-attach.py Workonly/ --trash TrashDir
$ ls TrashDir/
garbage_file

A more useful pattern is probably to put the "trash" directory inside the Vault, just to keep things together:

$ obs-prune-attach.py Worknotes/ --trash Worknotes/Trash
ls -al Worknotes/Trash
total 1080
drwxr-xr-x   7 jachimo  staff     238 Sep 21 14:50 .
drwxr-xr-x@ 13 jachimo  staff     442 Sep 21 14:50 ..
-rw-r--r--@  1 jachimo  staff  404471 Sep 13 02:32 2022-05 REDACTED.pdf
-rw-r--r--@  1 jachimo  staff   25595 Sep 13 02:32 2022-07-31 REDACTED.xlsx
-rw-r--r--@  1 jachimo  staff   60181 Sep 13 02:32 Pasted image 20220830100130.png
-rw-r--r--@  1 jachimo  staff   36579 Sep 13 02:32 Pasted image 20220902160016.png
-rw-r--r--@  1 jachimo  staff   19489 Sep 13 02:32 Screen Shot 2022-08-30 at 10.01.28 AM.png
Clone this wiki locally