Skip to content

Commit 963a45e

Browse files
Ghesselinkaothms
authored andcommitted
small fixes
1 parent ed50b75 commit 963a45e

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
HeaderFieldError,
99
InvalidNameError,
1010
)
11-
except:
11+
except ImportError:
1212
from .parser.parse import parse
1313
from .parser.file import file, open
1414
from .parser.errors import (

parser/parse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def parse(
8080
) -> ParseResult:
8181
error_collector = ErrorCollector()
8282
if filename:
83-
assert not filecontent
83+
if filecontent:
84+
raise ValueError("Cannot specify both filename and filecontent")
8485
filecontent = builtins.open(filename, encoding=None).read()
8586

8687
# Match and remove the comments

parser/transformer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from lark import Transformer
21
from dataclasses import dataclass
32
import numbers
43
from lark import Lark, Transformer, Tree, Token

test_parser.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import glob
2+
import json
3+
import os
4+
import subprocess
25
import pytest
36

47
try:
@@ -10,7 +13,7 @@
1013
DuplicateNameError,
1114
HeaderFieldError,
1215
)
13-
except:
16+
except ImportError:
1417
from __init__ import (
1518
parse,
1619
open,
@@ -25,7 +28,7 @@
2528

2629
def create_context(fn):
2730
if "fail_" in fn:
28-
return pytest.raises(_ValidationError)
31+
return pytest.raises(CollectedValidationErrors)
2932
else:
3033
return nullcontext()
3134

@@ -186,7 +189,7 @@ def test_header_entity_fields_whole_file():
186189
parse(filename="fixtures/fail_too_many_header_entity_fields.ifc")
187190

188191

189-
def test_header_entity_fields_whole_file():
192+
def test_multiple_duplicate_ids():
190193
with pytest.raises(CollectedValidationErrors) as exc_info:
191194
parse(filename="fixtures/fail_multiple_duplicate_ids.ifc")
192195

@@ -204,3 +207,34 @@ def test_multiple_wrong_header_fields():
204207

205208
assert len(errors) == 2
206209
assert all(isinstance(e, HeaderFieldError) for e in errors)
210+
211+
212+
REPO_DIR = os.path.dirname(os.path.abspath(__file__))
213+
PARENT_DIR = os.path.dirname(REPO_DIR)
214+
MODULE_NAME = os.path.basename(REPO_DIR)
215+
216+
217+
def run_cli(*args):
218+
return subprocess.run(
219+
["python", "-m", MODULE_NAME, *args],
220+
capture_output=True, text=True, cwd=PARENT_DIR,
221+
)
222+
223+
224+
def test_cli_valid_file():
225+
result = run_cli("step-file-parser/fixtures/passing_header.ifc")
226+
assert result.returncode == 0
227+
assert "Valid" in result.stderr
228+
229+
230+
def test_cli_invalid_file():
231+
result = run_cli("step-file-parser/fixtures/fail_no_header.ifc")
232+
assert result.returncode == 1
233+
234+
235+
def test_cli_json_output():
236+
result = run_cli("--json", "step-file-parser/fixtures/fail_no_header.ifc")
237+
assert result.returncode == 1
238+
errors = json.loads(result.stdout)
239+
assert isinstance(errors, list)
240+
assert len(errors) > 0

0 commit comments

Comments
 (0)