From 5cda8dd09fe35987b4470f602e0502fec624ce53 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Fri, 23 Jul 2021 01:52:15 +0300 Subject: [PATCH] Dont convert newlines in tests --- benchmark/run.py | 2 +- tests/test_extras.py | 6 +++--- tests/test_for_profiler.py | 2 +- tests/test_toml_compliance.py | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/benchmark/run.py b/benchmark/run.py index 82dd8ce..6ef958f 100644 --- a/benchmark/run.py +++ b/benchmark/run.py @@ -37,7 +37,7 @@ def benchmark( def run(run_count: int) -> None: data_path = Path(__file__).parent / "data.toml" - test_data = data_path.read_text(encoding="utf-8") + test_data = data_path.read_bytes().decode() col_width = (10, 10, 28) col_head = ("parser", "exec time", "performance (more is better)") print(f"Parsing data.toml {run_count} times:") diff --git a/tests/test_extras.py b/tests/test_extras.py index 5b1f89f..b1bc401 100644 --- a/tests/test_extras.py +++ b/tests/test_extras.py @@ -10,7 +10,7 @@ VALID_FILES = tuple((DATA_DIR / "valid").glob("**/*.toml")) VALID_FILES_EXPECTED = tuple( - json.loads(p.with_suffix(".json").read_text("utf-8")) for p in VALID_FILES + json.loads(p.with_suffix(".json").read_bytes().decode()) for p in VALID_FILES ) INVALID_FILES = tuple((DATA_DIR / "invalid").glob("**/*.toml")) @@ -22,7 +22,7 @@ ids=[p.stem for p in INVALID_FILES], ) def test_invalid(invalid): - toml_str = invalid.read_text(encoding="utf-8") + toml_str = invalid.read_bytes().decode() with pytest.raises(tomli.TOMLDecodeError): tomli.loads(toml_str) @@ -33,7 +33,7 @@ def test_invalid(invalid): ids=[p.stem for p in VALID_FILES], ) def test_valid(valid, expected): - toml_str = valid.read_text(encoding="utf-8") + toml_str = valid.read_bytes().decode() actual = tomli.loads(toml_str) actual = burntsushi.convert(actual) expected = burntsushi.normalize(expected) diff --git a/tests/test_for_profiler.py b/tests/test_for_profiler.py index 03f8618..df519b7 100644 --- a/tests/test_for_profiler.py +++ b/tests/test_for_profiler.py @@ -14,7 +14,7 @@ def test_for_profiler(): path = Path(__file__).parent.parent / "benchmark" / "data.toml" - benchmark_toml = path.read_text("utf-8") + benchmark_toml = path.read_bytes().decode() # increase the count here to reduce the impact of # setting up pytest execution environment. Let's keep # the count low by default because this is part of the diff --git a/tests/test_toml_compliance.py b/tests/test_toml_compliance.py index 58792bd..323ead9 100644 --- a/tests/test_toml_compliance.py +++ b/tests/test_toml_compliance.py @@ -16,13 +16,13 @@ def __init__(self, path: Path): VALID_FILES = tuple((DATA_DIR / "valid").glob("**/*.toml")) # VALID_FILES_EXPECTED = tuple( -# json.loads(p.with_suffix(".json").read_text("utf-8")) for p in VALID_FILES +# json.loads(p.with_suffix(".json").read_bytes().decode()) for p in VALID_FILES # ) _expected_files = [] for p in VALID_FILES: json_path = p.with_suffix(".json") try: - text = json.loads(json_path.read_text("utf-8")) + text = json.loads(json_path.read_bytes().decode()) except FileNotFoundError: text = MissingFile(json_path) _expected_files.append(text) @@ -37,7 +37,7 @@ def __init__(self, path: Path): ids=[p.stem for p in INVALID_FILES], ) def test_invalid(invalid): - toml_str = invalid.read_text(encoding="utf-8") + toml_str = invalid.read_bytes().decode() with pytest.raises(tomli.TOMLDecodeError): tomli.loads(toml_str) @@ -50,7 +50,7 @@ def test_invalid(invalid): def test_valid(valid, expected): if isinstance(expected, MissingFile): pytest.xfail(f"Missing a .json file corresponding the .toml: {expected.path}") - toml_str = valid.read_text(encoding="utf-8") + toml_str = valid.read_bytes().decode() actual = tomli.loads(toml_str) actual = burntsushi.convert(actual) expected = burntsushi.normalize(expected)