Skip to content

Commit

Permalink
Add unit test for parse_file with a Path argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ptmcg committed Jul 12, 2023
1 parent c8b7664 commit bc4f614
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tests/test_unit.py
Expand Up @@ -6889,14 +6889,27 @@ def testParseFile(self):
s = """
123 456 789
"""
input_file = StringIO(s)
from pathlib import Path

integer = ppc.integer
test_parser = integer[1, ...]

input_file_as_stringio = StringIO(s)
input_file_as_str = "tests/parsefiletest_input_file.txt"
input_file_as_path = Path(input_file_as_str)

results = pp.OneOrMore(integer).parseFile(input_file)
print(results)
expected_list = [int(i) for i in s.split()]

results = pp.OneOrMore(integer).parseFile("tests/parsefiletest_input_file.txt")
print(results)
for input_file in (
input_file_as_stringio,
input_file_as_str,
input_file_as_path,
):
with self.subTest(input_file=input_file):
print(f"parse_file() called with {type(input_file).__name__}")
results = test_parser.parseFile(input_file)
print(results)
self.assertEqual(expected_list, results.as_list())

def testHTMLStripper(self):
sample = """
Expand Down

0 comments on commit bc4f614

Please sign in to comment.