11import glob
2+ import json
3+ import os
4+ import subprocess
25import pytest
36
47try :
1013 DuplicateNameError ,
1114 HeaderFieldError ,
1215 )
13- except :
16+ except ImportError :
1417 from __init__ import (
1518 parse ,
1619 open ,
2528
2629def 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