Skip to content

Commit 027a9f3

Browse files
committed
add tests for functions - let's see if the import works now
1 parent e032e4c commit 027a9f3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_jqlcomposer.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import subprocess
22
import filecmp
3+
import jqlcomposer
4+
import contextlib
35

46
TEST_TERMS=["summer"]
57

@@ -20,3 +22,36 @@ def test_jqlcomposer_main_astext():
2022
subprocess.run(["python", "src/jqlcomposer.py", TEST_TERMS[i], f'"{json_contents}"'], stdout=outfile)
2123
assert 0 == filecmp.cmp(f"tests/testout{idx}.txt", f"tests/expect{idx}.txt")
2224

25+
def test_jqlcomposer_compose_from_file():
26+
for i in range(len(TEST_TERMS)):
27+
idx = i+1
28+
with open(f"tests/testout{idx}.txt", "w") as outfile:
29+
with contextlib.redirect_stdout(outfile):
30+
jqlcomposer.create_from_file(f"tests/test{idx}.json", TEST_TERMS[i])
31+
assert 0 == filecmp.cmp(f"tests/testout{idx}.txt", f"tests/expect{idx}.txt")
32+
33+
def test_jqlcomposer_compose_from_string():
34+
for i in range(len(TEST_TERMS)):
35+
idx = i+1
36+
json_contents = ""
37+
with open(f"tests/test{idx}.json", "r") as infile:
38+
json_contents = infile.read()
39+
with open(f"tests/testout{idx}.txt", "w") as outfile:
40+
with contextlib.redirect_stdout(outfile):
41+
jqlcomposer.create_from_string(json_contents, TEST_TERMS[i])
42+
assert 0 == filecmp.cmp(f"tests/testout{idx}.txt", f"tests/expect{idx}.txt")
43+
44+
def test_cut_next():
45+
is_token, next_slice, remainder = jqlcomposer.cut_next("if in {doubt}, flail about")
46+
assert not is_token
47+
assert next_slice == "if in "
48+
assert remainder == "{doubt}, flail about"
49+
is_token, next_slice, remainder = jqlcomposer.cut_next("{doubt} leads to hostility")
50+
assert is_token
51+
assert next_slice == "doubt"
52+
assert remainder == " leads to hostility"
53+
is_token, next_slice, remainder = jqlcomposer.cut_next("nothing to cut here")
54+
assert not is_token
55+
assert next_slice == "nothing to cut here"
56+
assert remainder == ""
57+

0 commit comments

Comments
 (0)