Skip to content

Commit 7865af7

Browse files
committed
Change assertions to error messages
1 parent 08194b2 commit 7865af7

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lchelper/parser.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Any, Dict, List, Tuple, Union
33

44
from lchelper.common import *
5+
from lchelper.logging import log
56

67
__all__ = [
78
"parse_problem",
@@ -94,9 +95,11 @@ def find_example_section(s: str, cur_tag: str, next_tag: str, colon: str = ":")
9495

9596
functions, input_str = parse_value(input_str)
9697
arg_vals, input_str = parse_value(input_str)
97-
assert len(input_str) == 0
98+
if len(input_str) > 0:
99+
log(f"Problem \"{problem.name}\": Extra characters in example input section: {input_str}", "warning")
98100
ret_vals, output_str = parse_value(output_str)
99-
assert len(output_str) == 0
101+
if len(output_str) > 0:
102+
log(f"Problem \"{problem.name}\": Extra characters in example output section: {output_str}", "warning")
100103

101104
cur_examples = [
102105
Interaction(
@@ -127,17 +130,19 @@ def find_example_section(s: str, cur_tag: str, next_tag: str, colon: str = ":")
127130
if idx > 0 and input_str.startswith(","):
128131
input_str = input_str[1:].strip()
129132
if idx == 0:
130-
if input_str.startswith(f"{name} = "):
131-
input_str = input_str[len(f"{name} = "):].strip()
133+
if input_str.startswith(f"{name} ="):
134+
input_str = input_str[len(f"{name} ="):].strip()
132135
else:
133-
assert input_str.startswith(f"{name} = ")
134-
input_str = input_str[len(f"{name} = "):].strip()
136+
assert input_str.startswith(f"{name} =")
137+
input_str = input_str[len(f"{name} ="):].strip()
135138
input_val, input_str = parse_value(input_str)
136139
input_vals[name] = input_val
137-
assert len(input_str) == 0
140+
if len(input_str) > 0:
141+
log(f"Problem \"{problem.name}\": Extra characters in example input section:\n{input_str}", "warning")
138142

139143
output_val, output_str = parse_value(output_str)
140-
assert len(output_str) == 0
144+
if len(output_str) > 0:
145+
log(f"Problem \"{problem.name}\": Extra characters in example output section:\n{output_str}", "warning")
141146

142147
examples.append(Example(input_vals, output_val))
143148

0 commit comments

Comments
 (0)