Skip to content

Commit

Permalink
Dont convert newlines in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin committed Jul 22, 2021
1 parent 3ee43ef commit 5cda8dd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion benchmark/run.py
Expand Up @@ -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:")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_extras.py
Expand Up @@ -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"))
Expand All @@ -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)

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_for_profiler.py
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/test_toml_compliance.py
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit 5cda8dd

Please sign in to comment.