11"""Tests for the XML validation process module."""
22
3+ from subprocess import CompletedProcess
34from pathlib import Path
45from unittest .mock import AsyncMock , MagicMock , patch
56
@@ -33,7 +34,8 @@ def mock_context() -> DocBuildContext:
3334 return context
3435
3536
36- @patch .object (process_module , 'validate_rng' , new_callable = AsyncMock , return_value = (True , '' ))
37+ @patch .object (process_module , 'validate_rng' ,
38+ new_callable = AsyncMock , return_value = (True , '' ))
3739@patch .object (process_module .etree , 'parse' , side_effect = ValueError ('Generic test error' ))
3840async def test_process_file_with_generic_parsing_error (
3941 mock_etree_parse , mock_validate_rng , mock_context , tmp_path , capsys
@@ -119,7 +121,9 @@ async def test_process_file_with_unknown_validation_method(mock_context, tmp_pat
119121@patch .object (process_module , 'run_command' , new_callable = AsyncMock )
120122async def test_validate_rng_with_idcheck_success (mock_run_command , tmp_path ):
121123 """Test that validate_rng with idcheck=True succeeds for a valid XML."""
122- mock_run_command .return_value = (0 , '' , '' )
124+ mock_run_command .return_value = CompletedProcess (
125+ args = ["fake-command" ], returncode = 0 , stdout = '' , stderr = ''
126+ )
123127 xml_file = tmp_path / 'valid.xml'
124128 xml_file .touch ()
125129 rng_schema = tmp_path / 'schema.rnc'
@@ -130,13 +134,18 @@ async def test_validate_rng_with_idcheck_success(mock_run_command, tmp_path):
130134 assert is_valid is True
131135 assert message == ''
132136 # Ensure -i flag is passed to jing
133- assert '-i' in mock_run_command .call_args [0 ]
137+ assert "-i" in mock_run_command .call_args . args [0 ]
134138
135139
136140@patch .object (process_module , 'run_command' , new_callable = AsyncMock )
137141async def test_validate_rng_with_idcheck_duplicate_failure (mock_run_command , tmp_path ):
138142 """Test that validate_rng with idcheck=True fails for a duplicate ID."""
139- mock_run_command .return_value = (1 , '' , 'error: duplicate ID "test-id"' )
143+ mock_run_command .return_value = CompletedProcess (
144+ args = ['fake-command' ],
145+ returncode = 1 ,
146+ stdout = '' ,
147+ stderr = 'error: duplicate ID "test-id"' ,
148+ )
140149 xml_file = tmp_path / 'duplicate_id.xml'
141150 xml_file .touch ()
142151 rng_schema = tmp_path / 'schema.rnc'
@@ -147,13 +156,18 @@ async def test_validate_rng_with_idcheck_duplicate_failure(mock_run_command, tmp
147156 assert is_valid is False
148157 assert 'duplicate ID' in message
149158 # Ensure -i flag is passed to jing
150- assert '-i' in mock_run_command .call_args [0 ]
159+ assert '-i' in mock_run_command .call_args . args [0 ]
151160
152161
153162@patch .object (process_module , 'run_command' , new_callable = AsyncMock )
154163async def test_validate_rng_without_idcheck_success (mock_run_command , tmp_path ):
155164 """Test that validate_rng with idcheck=False succeeds despite a duplicate ID."""
156- mock_run_command .return_value = (0 , '' , '' )
165+ mock_run_command .return_value = CompletedProcess (
166+ args = ['fake-command' ],
167+ returncode = 0 ,
168+ stdout = '' ,
169+ stderr = '' ,
170+ )
157171 xml_file = tmp_path / 'duplicate_id.xml'
158172 xml_file .touch ()
159173 rng_schema = tmp_path / 'schema.rnc'
@@ -164,4 +178,4 @@ async def test_validate_rng_without_idcheck_success(mock_run_command, tmp_path):
164178 assert is_valid is True
165179 assert message == ''
166180 # Ensure -i flag is NOT passed to jing
167- assert '-i' not in mock_run_command .call_args [0 ]
181+ assert '-i' not in mock_run_command .call_args . args [0 ]
0 commit comments