|
| 1 | +import sys |
| 2 | +from unittest.mock import patch |
| 3 | +import urllib |
| 4 | + |
| 5 | +import totolo |
| 6 | +import totolo.util.validate |
| 7 | + |
| 8 | +from tests.test_totolo import precache_remote_resources |
| 9 | + |
| 10 | + |
| 11 | +EXPECTED_WARNINGS_20230723 = """ |
| 12 | +tests/data/sample-2023.07.23/notes/stories/film/film-scifi-1920s.st.txt: In movie: The Hands of Orlac (1924): Missing '{' in: ['body part transplant ', 'hand', '', ''] |
| 13 | +tests/data/sample-2023.07.23/notes/stories/film/film-scifi-1930s.st.txt: In movie: The Walking Dead (1936): Missing '{' in: ['artificial body part ', 'heart', '', ''] |
| 14 | +tests/data/sample-2023.07.23/notes/stories/film/film-scifi-1930s.st.txt: In movie: The Man They Could Not Hang (1939): Missing '{' in: ['artificial body part ', 'heart', '', ''] |
| 15 | +tests/data/sample-2023.07.23/notes/stories/film/film-scifi-1930s.st.txt: In movie: The Return of Doctor X (1939): Missing '{' in: ['artificial body part ', 'blood', '', ''] |
| 16 | +tests/data/sample-2023.07.23/notes/themes/primary.th.txt: artificial body part: unknown field 'Template' |
| 17 | +tests/data/sample-2023.07.23/notes/themes/primary.th.txt: historical figure: unknown field 'Template' |
| 18 | +movie: Algol: Tragedy of Power (1920): Undefined 'major theme' with name 'the lust for gold' |
| 19 | +movie: Woman in the Moon (1929): Undefined 'minor theme' with name 'the lust for gold' |
| 20 | +""".strip() |
| 21 | + |
| 22 | + |
| 23 | +def validate1(capsys, expected = None): |
| 24 | + out, err = capsys.readouterr() |
| 25 | + assert all(line.startswith("::") for line in err.strip().splitlines()) |
| 26 | + assert out.strip() == expected or EXPECTED_WARNINGS_20230723 |
| 27 | + |
| 28 | + |
| 29 | +class TestMakeJson: |
| 30 | + def test_from_path(self, capsys): |
| 31 | + p1 = "tests/data/sample-2023.07.23/notes" |
| 32 | + testargs = ["makejson", "--path", p1] |
| 33 | + with patch.object(sys, 'argv', testargs): |
| 34 | + totolo.util.validate.main() |
| 35 | + validate1(capsys) |
| 36 | + |
| 37 | + def test_from_path_narg(self, capsys): |
| 38 | + p1 = "tests/data/sample-2023.07.23/notes" |
| 39 | + testargs = ["makejson", p1] |
| 40 | + with patch.object(sys, 'argv', testargs): |
| 41 | + totolo.util.validate.main() |
| 42 | + validate1(capsys) |
| 43 | + |
| 44 | + def test_bad_usage(self, capsys): |
| 45 | + testargs = ["makejson", "--path", "foo", "--version", "foo"] |
| 46 | + with patch.object(sys, 'argv', testargs): |
| 47 | + totolo.util.validate.main() |
| 48 | + out, err = capsys.readouterr() |
| 49 | + assert all(x in err for x in ["--path", "--version", "positional"]) |
| 50 | + assert not out |
| 51 | + |
| 52 | + def test_remote_version(self, capsys): |
| 53 | + precache_remote_resources() |
| 54 | + testargs = ["makejson", "--version", "v2023.06"] |
| 55 | + with patch.object(sys, 'argv', testargs): |
| 56 | + with open("tests/data/sample-2023.07.23.tar.gz", "rb+") as fh: |
| 57 | + with patch.object(urllib.request, 'urlopen', return_value=fh): |
| 58 | + totolo.util.validate.main() |
| 59 | + validate1(capsys) |
| 60 | + |
| 61 | + def test_remote_version_narg(self, capsys): |
| 62 | + precache_remote_resources() |
| 63 | + testargs = ["makejson", "v2023.06"] |
| 64 | + with patch.object(sys, 'argv', testargs): |
| 65 | + with open("tests/data/sample-2023.07.23.tar.gz", "rb+") as fh: |
| 66 | + with patch.object(urllib.request, 'urlopen', return_value=fh): |
| 67 | + totolo.util.validate.main() |
| 68 | + validate1(capsys) |
| 69 | + |
| 70 | + def test_remote_head(self, capsys): |
| 71 | + precache_remote_resources() |
| 72 | + testargs = ["makejson"] |
| 73 | + with patch.object(sys, 'argv', testargs): |
| 74 | + with open("tests/data/sample-2023.07.23.tar.gz", "rb+") as fh: |
| 75 | + with patch.object(urllib.request, 'urlopen', return_value=fh): |
| 76 | + totolo.util.validate.main() |
| 77 | + validate1(capsys) |
0 commit comments