Skip to content

Commit 260c61c

Browse files
committed
Fix tests
1 parent 2c48c8c commit 260c61c

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

Python/ini_converting/ini_parser_tests.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ def parser_tests():
1515
# { "type": "extra", "content": "\t\t" }, { "type": "property", "content": "Foo" }, { "type": "extra", "content": " " }, { "type": "extra", "content": "=" }, { "type": "extra", "content": " " }, { "type": "value", "content": "Bar" }
1616
# ]
1717
# ])
18+
# test("comments", [
19+
# [
20+
# { "type": "extra", "content": "\n" },
21+
# { "type": "extra", "content": "// foo"}, { "type": "extra", "content": "\n" },
22+
# { "type": "extra", "content": "/*a\nb\nc*/" }, { "type": "extra", "content": "\n" },
23+
# ],
24+
# ])
25+
# test("nested", [
26+
# [
27+
# { "type": "property", "content": "Foo" }, { "type": "extra", "content": " " }, { "type": "extra", "content": "=" }, { "type": "extra", "content": " " }, { "type": "value", "content": "Bar" }, { "type": "extra", "content": "\n" },
28+
# { "type": "lines_tokens", "content": [
29+
# [
30+
# { "type": "extra", "content": "\t" }, { "type": "property", "content": "Baz" }, { "type": "extra", "content": " " }, { "type": "extra", "content": "=" }, { "type": "extra", "content": " " }, { "type": "value", "content": "Bee" }, { "type": "extra", "content": "\n" }
31+
# ]
32+
# ]}
33+
# ]
34+
# ])
1835
# test("multiple", [
1936
# [
2037
# { "type": "property", "content": "Foo" }, { "type": "extra", "content": " " }, { "type": "extra", "content": "=" }, { "type": "extra", "content": " " }, { "type": "value", "content": "Bar" }, { "type": "extra", "content": "\n" },
@@ -57,7 +74,8 @@ def parser_tests():
5774

5875

5976
def test(filename, expected):
60-
text = tests.read_test(filename)
61-
tokens = ini_tokenizer.get_tokens(filename)
77+
filepath = tests.get_test_path_from_filename(filename)
78+
text = tests.read_test(filepath)
79+
tokens = ini_tokenizer.get_tokens(str(filepath))
6280
ini_cst = ini_parser.get_parsed_tokens(tokens)
6381
tests.test(text, ini_cst, expected)

Python/ini_converting/ini_tokenizer_tests.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,10 @@ def tokenizer_tests():
3535

3636

3737
def test(filename, expected):
38-
text = tests.read_test(filename)
39-
tests.test(text, ini_tokenizer.get_tokens(filename), expected)
38+
filepath = tests.get_test_path_from_filename(filename)
39+
text = tests.read_test(filepath)
40+
41+
tokens = ini_tokenizer.get_tokens(str(filepath))
42+
tokens_without_metadata = [ { "type": token["type"], "content": token["content"] } for token in tokens]
43+
44+
tests.test(text, tokens_without_metadata, expected)

Python/tests.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ def run():
1313
# ini_parser_tests.multi_line_tests()
1414

1515

16-
def read_test(filename):
17-
return Path(utils.resource_path(f"Python/ini_converting/ini_test_files/{filename}.ini")).read_text()
16+
def get_test_path_from_filename(filename):
17+
return Path(utils.resource_path(f"Python/ini_converting/ini_test_files/{filename}.ini"))
18+
19+
20+
def read_test(filepath):
21+
return filepath.read_text()
1822

1923

2024
def test(input_str, result, expected):
@@ -28,5 +32,13 @@ def test(input_str, result, expected):
2832
)
2933

3034
# print(result)
35+
36+
# TODO: Comment these out before releasing this!
37+
# import json
38+
# with open("result.json", "w") as f:
39+
# f.write(json.dumps(result))
40+
# with open("expected.json", "w") as f:
41+
# f.write(json.dumps(expected))
42+
3143
# TODO: Make the error_message not show twice in the popup.
3244
assert result == expected, error_message

0 commit comments

Comments
 (0)