@@ -37,9 +37,9 @@ async def test_validate_rng_with_rng_suffix(tmp_path: Path):
3737 <start><element name="root"><text/></element></start>
3838</grammar>""" )
3939
40- returncode , _ = await process_mod .validate_rng (xmlfile , rng_schema )
40+ proc = await process_mod .validate_rng (xmlfile , rng_schema )
4141
42- assert returncode , f'Expected True , got { returncode } '
42+ assert proc . returncode == 0 , f'Expected return code 0 , got { proc . returncode } '
4343
4444
4545@pytest .mark .skipif (not is_jing_installed (), reason = "jing command not found" )
@@ -54,9 +54,9 @@ async def test_validate_rng_with_invalid_xml(tmp_path: Path):
5454 <start><element name="root"><text/></element></start>
5555</grammar>""" )
5656
57- returncode , message = await process_mod .validate_rng (xmlfile , rng_schema )
58- assert returncode is False , f'Expected False , got { returncode } '
59- assert 'error: element "wrong_root"' in message
57+ proc = await process_mod .validate_rng (xmlfile , rng_schema )
58+ assert proc . returncode != 0 , f'Expected non-zero return code , got { proc . returncode } '
59+ assert 'error: element "wrong_root"' in ( proc . stdout + proc . stderr )
6060
6161
6262@pytest .mark .skipif (not is_jing_installed (), reason = "jing command not found" )
@@ -71,9 +71,9 @@ async def test_validate_rng_without_xinclude(tmp_path: Path):
7171 <start><element name="root"><text/></element></start>
7272</grammar>""" )
7373
74- returncode , _ = await process_mod .validate_rng (xmlfile , rng_schema , xinclude = False )
74+ proc = await process_mod .validate_rng (xmlfile , rng_schema , xinclude = False )
7575
76- assert returncode , f'Expected True , got { returncode } '
76+ assert proc . returncode == 0 , f'Expected return code 0 , got { proc . returncode } '
7777
7878
7979@pytest .mark .skipif (not is_jing_installed (), reason = "jing command not found" )
@@ -88,12 +88,10 @@ async def test_validate_rng_with_invalid_xml_without_xinclude(tmp_path: Path):
8888 <start><element name="root"><text/></element></start>
8989</grammar>""" )
9090
91- returncode , message = await process_mod .validate_rng (
92- xmlfile , rng_schema , xinclude = False
93- )
91+ proc = await process_mod .validate_rng (xmlfile , rng_schema , xinclude = False )
9492
95- assert returncode is False , f'Expected False , got { returncode } '
96- assert 'element "wrong_root" not allowed anywhere' in message
93+ assert proc . returncode != 0 , f'Expected non-zero return code , got { proc . returncode } '
94+ assert 'element "wrong_root" not allowed anywhere' in ( proc . stdout + proc . stderr )
9795
9896
9997async def test_validate_rng_jing_failure ():
@@ -112,12 +110,12 @@ async def test_validate_rng_jing_failure():
112110 stdout = 'Error in jing' ,
113111 stderr = '' ))
114112 ) as mock_run_command :
115- success , output = await process_mod .validate_rng (
113+ proc = await process_mod .validate_rng (
116114 xmlfile , rng_schema_path = rng_schema , xinclude = False , idcheck = False
117115 )
118116
119- assert not success , 'Expected validation to fail.'
120- assert output == 'Error in jing' , f'Unexpected output : { output } '
117+ assert proc . returncode != 0 , 'Expected validation to fail.'
118+ assert proc . stdout == 'Error in jing' , f'Unexpected stdout : { proc . stdout } '
121119
122120 mock_run_command .assert_called_once_with (
123121 ['jing' , str (rng_schema ), str (xmlfile )]
@@ -137,12 +135,12 @@ async def test_validate_rng_command_not_found():
137135 with patch .object (
138136 process_mod , 'run_command' , new_callable = AsyncMock , side_effect = error
139137 ):
140- success , output = await process_mod .validate_rng (
138+ proc = await process_mod .validate_rng (
141139 xmlfile , rng_schema_path = rng_schema , xinclude = False
142140 )
143141
144- assert not success , 'Expected validation to fail.'
145- assert output == 'jing command not found. Please install it to run validation.'
142+ assert proc . returncode != 0 , 'Expected validation to fail.'
143+ assert proc . stderr == 'jing command not found. Please install it to run validation.'
146144
147145
148146async def test_validate_rng_command_not_found_no_filename ():
@@ -155,21 +153,21 @@ async def test_validate_rng_command_not_found_no_filename():
155153 with patch .object (
156154 process_mod , 'run_command' , new_callable = AsyncMock , side_effect = error
157155 ):
158- success , output = await process_mod .validate_rng (
156+ proc = await process_mod .validate_rng (
159157 xmlfile , rng_schema , xinclude = False
160158 )
161159
162- assert not success , 'Expected validation to fail.'
160+ assert proc . returncode != 0 , 'Expected validation to fail.'
163161 assert (
164- output == 'xmllint/jing command not found. Please install it to run validation.'
162+ proc . stderr == 'xmllint/jing command not found. Please install it to run validation.'
165163 )
166164
167165
168166async def test_process_file_with_validation_issues (capsys , tmp_path ):
169167 with patch .object (
170168 process_mod ,
171169 'validate_rng' ,
172- new = AsyncMock (return_value = ( False , 'Validation error' )),
170+ new = AsyncMock (return_value = CompletedProcess ( args = [ 'jing' ], returncode = 1 , stdout = '' , stderr = 'Validation error' )),
173171 ) as mock_validate_rng :
174172 dir_path = tmp_path / 'path' / 'to'
175173 dir_path .mkdir (parents = True )
@@ -207,7 +205,7 @@ async def test_process_file_with_xmlsyntax_error(capsys, tmp_path):
207205 ),
208206 ) as mock_etree_parse ,
209207 patch .object (
210- process_mod , 'validate_rng' , new = AsyncMock (return_value = ( True , '' ))
208+ process_mod , 'validate_rng' , new = AsyncMock (return_value = CompletedProcess ( args = [ 'jing' ], returncode = 0 , stdout = '' , stderr = '' ))
211209 ) as mock_validate_rng ,
212210 ):
213211 result = await process_mod .process_file (xmlfile , mock_context , 40 )
0 commit comments