diff --git a/tests/test_outputs.py b/tests/test_outputs.py index e35f8a2..2db28ea 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -16,16 +16,19 @@ 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: + # Escape regular expression + pattern = re.sub(r"([()])", r"\\\1", r.read()) + # Allow CRLF + pattern = re.sub("\n", r"\r?\n", pattern) + r'(?:\r\n)?' # 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 @@ -41,7 +44,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 @@ -56,13 +59,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": package_dir}, + env, ) else: # Use `.sample.txt` when testing against outputs with more variables. @@ -70,7 +78,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}, + env, ) setattr(TestOutputs, "test_{0}".format(f.replace(".py", "")), test_func)