From 51d4fb04c8f4ef291e30f82999e4c30db7cb1c10 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Wed, 19 Oct 2022 18:06:41 +0300 Subject: [PATCH] tests: Tokenize CLI arguments Pass tokenized arguments (i.e., arguments as lists of strings) to CLI invocations, else Click will attempt to tokenize them internally. The problem with leaving tokenization to Click is that it uses `shlex.split()`, which is Unix-oriented, and may miss some cases in Windows. --- tests/test_cli.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 383c847..7ce3f85 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -150,24 +150,24 @@ class TestCliBasic(TestCli): class TestCliConversion(TestCliBasic): def test_invalid_lang(self): - result = self.run_cli(f"{self.sample_doc} --ocr-lang piglatin") + result = self.run_cli([self.sample_doc, "--ocr-lang", "piglatin"]) result.assert_failure() @for_each_doc def test_formats(self, doc): - result = self.run_cli(f'"{doc}"') + result = self.run_cli(str(doc)) result.assert_success() def test_output_filename(self): temp_dir = tempfile.mkdtemp(prefix="dangerzone-") result = self.run_cli( - f"{self.sample_doc} --output-filename {temp_dir}/safe.pdf" + [self.sample_doc, "--output-filename", f"{temp_dir}/safe.pdf"] ) result.assert_success() def test_output_filename_new_dir(self): result = self.run_cli( - f"{self.sample_doc} --output-filename fake-directory/my-output.pdf" + [self.sample_doc, "--output-filename", "fake-directory/my-output.pdf"] ) result.assert_failure() @@ -176,7 +176,7 @@ class TestCliConversion(TestCliBasic): result.assert_failure() def test_lang_eng(self): - result = self.run_cli(f'"{self.sample_doc}" --ocr-lang eng') + result = self.run_cli([self.sample_doc, "--ocr-lang", "eng"]) result.assert_success() @pytest.mark.parametrize(