From 21c0e045cbdd2a7a7253532ff34085a248239f03 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Tue, 9 Jun 2020 00:30:13 -0700 Subject: [PATCH] Remove _OCRMYPDF_TEST_PATH environment variable --- src/ocrmypdf/exec/_support.py | 15 ++------------- tests/conftest.py | 14 ++++---------- tests/test_stdio.py | 8 +++----- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/ocrmypdf/exec/_support.py b/src/ocrmypdf/exec/_support.py index 5f52ac87..3ff10558 100644 --- a/src/ocrmypdf/exec/_support.py +++ b/src/ocrmypdf/exec/_support.py @@ -34,20 +34,10 @@ from ocrmypdf.exceptions import MissingDependencyError log = logging.getLogger(__name__) -def _get_program(args, env=None): - program = args[0] - test_path = env.get('_OCRMYPDF_TEST_PATH', '') - if test_path: - program = shutil.which(program, path=test_path) - return program - - def run(args, *, env=None, **kwargs): """Wrapper around subprocess.run() - The main purpose of this wrapper is to allow us to substitute the main program - for a spoof in the test suite. The hidden variable _OCRMYPDF_TEST_PATH replaces - the main PATH as a location to check for programs to run. + The main purpose of this wrapper is to log subprocess output. Secondly we have to account for behavioral differences in Windows in particular. Creating symbolic links in Windows requires administrator privileges and @@ -62,8 +52,7 @@ def run(args, *, env=None, **kwargs): env = os.environ # Search in spoof path if necessary - program = _get_program(args, env) - args = [program] + args[1:] + program = args[0] if os.name == 'nt': args = fix_windows_args(program, args, env) diff --git a/tests/conftest.py b/tests/conftest.py index 75789771..b520d73b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -105,7 +105,7 @@ def no_outpdf(tmp_path): @pytest.helpers.register -def check_ocrmypdf(input_file, output_file, *args, env=None): +def check_ocrmypdf(input_file, output_file, *args): """Run ocrmypdf and confirmed that a valid file was created""" args = [str(input_file), str(output_file)] + [ str(arg) for arg in args if arg is not None @@ -113,8 +113,6 @@ def check_ocrmypdf(input_file, output_file, *args, env=None): _parser, options, plugin_manager = get_parser_options_plugins(args=args) api.check_options(options, plugin_manager) - if env: - assert False, 'env set' result = api.run_pipeline(options, plugin_manager=plugin_manager, api=True) assert result == 0 @@ -125,7 +123,7 @@ def check_ocrmypdf(input_file, output_file, *args, env=None): @pytest.helpers.register -def run_ocrmypdf_api(input_file, output_file, *args, env=None): +def run_ocrmypdf_api(input_file, output_file, *args): """Run ocrmypdf via API and let caller deal with results Does not currently have a way to manipulate the PATH except for Tesseract. @@ -135,8 +133,6 @@ def run_ocrmypdf_api(input_file, output_file, *args, env=None): str(arg) for arg in args if arg is not None ] _parser, options, plugin_manager = get_parser_options_plugins(args=args) - if env: - assert False, 'env set' if options.tesseract_env: assert all(isinstance(v, (str, bytes)) for v in options.tesseract_env.values()) @@ -145,12 +141,9 @@ def run_ocrmypdf_api(input_file, output_file, *args, env=None): @pytest.helpers.register -def run_ocrmypdf(input_file, output_file, *args, env=None, universal_newlines=True): +def run_ocrmypdf(input_file, output_file, *args, universal_newlines=True): "Run ocrmypdf and let caller deal with results" - if env is None: - env = os.environ.copy() - p_args = ( OCRMYPDF + [str(arg) for arg in args if arg is not None] @@ -162,6 +155,7 @@ def run_ocrmypdf(input_file, output_file, *args, env=None, universal_newlines=Tr # Details: https://coverage.readthedocs.io/en/coverage-5.0/subprocess.html coverage_rc = Path(__file__).parent.parent / '.coveragerc' assert coverage_rc.exists() + env = os.environ.copy() env['COVERAGE_PROCESS_START'] = os.fspath(coverage_rc) p = run( diff --git a/tests/test_stdio.py b/tests/test_stdio.py index 883d48de..478661c2 100644 --- a/tests/test_stdio.py +++ b/tests/test_stdio.py @@ -105,11 +105,9 @@ def test_closed_streams(ocrmypdf_exec, resources, outpdf): Path('/etc/alpine-release').exists(), reason="invalid test on alpine" ) @pytest.mark.skipif(os.name == 'nt', reason="invalid test on Windows") -def test_bad_locale(): - env = os.environ.copy() - env['LC_ALL'] = 'C' - - p, out, err = run_ocrmypdf('a', 'b', env=env) +def test_bad_locale(monkeypatch): + monkeypatch.setenv('LC_ALL', 'C') + p, out, err = run_ocrmypdf('a', 'b') assert out == '', "stdout not clean" assert p.returncode != 0 assert 'configured to use ASCII as encoding' in err, "should whine"