From 42208abf66a4c810cfc813f981c1577b517a2101 Mon Sep 17 00:00:00 2001 From: Blind4Basics <32236948+Blind4Basics@users.noreply.github.com> Date: Tue, 18 May 2021 21:20:51 +0200 Subject: [PATCH 1/5] Update test_outputs.py --- tests/test_outputs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_outputs.py b/tests/test_outputs.py index e35f8a2..7a61808 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -16,11 +16,11 @@ def test(self): ["python", test_file], env=env, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + stderr=subprocess.STDOUT, ) with open(expected_file, "r", encoding="utf-8") as r: # Allow duration to change - expected = re.sub(r"([()])", r"\\\1", r.read()) + expected = re.sub( r"([()])", r"\\\1", r.read() ) expected = re.sub( r"(?<=)\d+(?:\.\d+)?", r"\\d+(?:\\.\\d+)?", expected ) @@ -41,7 +41,7 @@ def test(self): ["python", test_file], env=env, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + stderr=subprocess.STDOUT, ) with open(sample_file, "r", encoding="utf-8") as r: # Ensure that it contains the same output structure @@ -62,7 +62,7 @@ def define_tests(): test_func = test_against_expected( os.path.join(fixtures_dir, f), expected_file, - {"PYTHONPATH": package_dir}, + {"PYTHONPATH": str(package_dir)}, ) else: # Use `.sample.txt` when testing against outputs with more variables. @@ -70,7 +70,7 @@ def define_tests(): test_func = test_against_sample( os.path.join(fixtures_dir, f), os.path.join(fixtures_dir, f.replace(".py", ".sample.txt")), - {"PYTHONPATH": package_dir}, + {"PYTHONPATH": str(package_dir)}, ) setattr(TestOutputs, "test_{0}".format(f.replace(".py", "")), test_func) From 5f40bb774ceed16fce5c956cae071ab1ded6ad57 Mon Sep 17 00:00:00 2001 From: Blind4Basics <32236948+Blind4Basics@users.noreply.github.com> Date: Tue, 18 May 2021 21:30:47 +0200 Subject: [PATCH 2/5] Update tests/test_outputs.py --- tests/test_outputs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_outputs.py b/tests/test_outputs.py index 7a61808..4b7e8a0 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -20,7 +20,7 @@ def test(self): ) with open(expected_file, "r", encoding="utf-8") as r: # Allow duration to change - expected = re.sub( r"([()])", r"\\\1", r.read() ) + expected = re.sub(r"([()])", r"\\\1", r.read()) expected = re.sub( r"(?<=)\d+(?:\.\d+)?", r"\\d+(?:\\.\\d+)?", expected ) From f1f6c6c350432a73f61df24a63e80f2afbf46426 Mon Sep 17 00:00:00 2001 From: kazk Date: Tue, 18 May 2021 12:51:30 -0700 Subject: [PATCH 3/5] Pass SYSTEMROOT to subprocess env if it exists --- tests/test_outputs.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_outputs.py b/tests/test_outputs.py index 4b7e8a0..efc099c 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -56,13 +56,18 @@ def define_tests(): fixtures_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "fixtures") package_dir = Path(fixtures_dir).parent.parent files = (f for f in os.listdir(fixtures_dir) if f.endswith(".py")) + + env = {"PYTHONPATH": str(package_dir)} + if "SYSTEMROOT" in os.environ: + env["SYSTEMROOT"] = os.environ["SYSTEMROOT"] + for f in files: expected_file = os.path.join(fixtures_dir, f.replace(".py", ".expected.txt")) if os.path.exists(expected_file): test_func = test_against_expected( os.path.join(fixtures_dir, f), expected_file, - {"PYTHONPATH": str(package_dir)}, + env, ) else: # Use `.sample.txt` when testing against outputs with more variables. @@ -70,7 +75,7 @@ def define_tests(): test_func = test_against_sample( os.path.join(fixtures_dir, f), os.path.join(fixtures_dir, f.replace(".py", ".sample.txt")), - {"PYTHONPATH": str(package_dir)}, + env, ) setattr(TestOutputs, "test_{0}".format(f.replace(".py", "")), test_func) From 2aa45044818d49b15f4d91891941208b943f95c9 Mon Sep 17 00:00:00 2001 From: kazk Date: Tue, 18 May 2021 13:44:53 -0700 Subject: [PATCH 4/5] Allow CRLF --- tests/test_outputs.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/test_outputs.py b/tests/test_outputs.py index efc099c..d5b5e1f 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -19,13 +19,16 @@ def test(self): stderr=subprocess.STDOUT, ) with open(expected_file, "r", encoding="utf-8") as r: + # Escape regular expression + pattern = re.sub(r"([()])", r"\\\1", r.read()) + # Allow CRLF + pattern = re.sub("\n", r"\r?\n", pattern) # Allow duration to change - expected = re.sub(r"([()])", r"\\\1", r.read()) - expected = re.sub( - r"(?<=)\d+(?:\.\d+)?", r"\\d+(?:\\.\\d+)?", expected + pattern = re.sub( + r"(?<=)\d+(?:\.\d+)?", r"\\d+(?:\\.\\d+)?", pattern ) - self.assertRegex(result.stdout.decode("utf-8"), expected) + self.assertRegex(result.stdout.decode("utf-8"), pattern) return test From 273f10f69f762aa1404e1cf2401f550732c18c1f Mon Sep 17 00:00:00 2001 From: Blind4Basics <32236948+Blind4Basics@users.noreply.github.com> Date: Tue, 18 May 2021 22:52:58 +0200 Subject: [PATCH 5/5] Update tests/test_outputs.py --- tests/test_outputs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_outputs.py b/tests/test_outputs.py index d5b5e1f..2db28ea 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -22,7 +22,7 @@ def test(self): # Escape regular expression pattern = re.sub(r"([()])", r"\\\1", r.read()) # Allow CRLF - pattern = re.sub("\n", r"\r?\n", pattern) + pattern = re.sub("\n", r"\r?\n", pattern) + r'(?:\r\n)?' # Allow duration to change pattern = re.sub( r"(?<=)\d+(?:\.\d+)?", r"\\d+(?:\\.\\d+)?", pattern