Skip to content

Commit

Permalink
tests: adapt tests implicitly influenced by and add explicit test for…
Browse files Browse the repository at this point in the history
… consistent line endings in toml files
  • Loading branch information
radoering committed Jul 6, 2022
1 parent 0f64611 commit 4300362
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
10 changes: 4 additions & 6 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,12 +870,10 @@ def test_add_to_section_that_does_not_exist_yet(
cachy = "^0.2.0"
"""
# At the moment line endings will be inconsistent on Windows.
# See https://github.com/sdispater/tomlkit/issues/200 for details.
# https://github.com/sdispater/tomlkit/pull/201 fixes this issue
# In order to make tests forward compatible for tomlkit downstream tests,
# we replace "\r\n" with "\n" for now.
string_content = content.as_string().replace("\r\n", "\n")
string_content = content.as_string()
if "\r\n" in string_content:
# consistent line endings
expected = expected.replace("\n", "\r\n")

assert expected in string_content

Expand Down
26 changes: 24 additions & 2 deletions tests/console/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,6 @@ def test_add_package_with_extras_and_whitespace(tester: CommandTester):
assert "sqlite" in result[0]["extras"]


@pytest.mark.xfail(sys.platform == "win32", reason="regression in tomlkit")
def test_init_existing_pyproject_simple(
tester: CommandTester,
source_dir: Path,
Expand All @@ -901,7 +900,30 @@ def test_init_existing_pyproject_simple(
assert f"{existing_section}\n{init_basic_toml}" in pyproject_file.read_text()


@pytest.mark.xfail(sys.platform == "win32", reason="regression in tomlkit")
@pytest.mark.parametrize("linesep", ["\n", "\r\n"])
def test_init_existing_pyproject_consistent_linesep(
tester: CommandTester,
source_dir: Path,
init_basic_inputs: str,
init_basic_toml: str,
linesep: str,
):
pyproject_file = source_dir / "pyproject.toml"
existing_section = """
[tool.black]
line-length = 88
""".replace(
"\n", linesep
)
with open(pyproject_file, "w", newline="") as f:
f.write(existing_section)
tester.execute(inputs=init_basic_inputs)
with open(pyproject_file, newline="") as f:
content = f.read()
init_basic_toml = init_basic_toml.replace("\n", linesep)
assert f"{existing_section}{linesep}{init_basic_toml}" in content


def test_init_non_interactive_existing_pyproject_add_dependency(
tester: CommandTester,
source_dir: Path,
Expand Down
30 changes: 12 additions & 18 deletions tests/console/commands/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,10 @@ def test_remove_without_specific_group_removes_from_all_groups(
baz = "^1.0.0"
"""
# At the moment line endings will be inconsistent on Windows.
# See https://github.com/sdispater/tomlkit/issues/200 for details.
# https://github.com/sdispater/tomlkit/pull/201 fixes this issue
# In order to make tests forward compatible for tomlkit downstream tests,
# we replace "\r\n" with "\n" for now.
string_content = content.as_string().replace("\r\n", "\n")
string_content = content.as_string()
if "\r\n" in string_content:
# consistent line endings
expected = expected.replace("\n", "\r\n")

assert expected in string_content

Expand Down Expand Up @@ -154,12 +152,10 @@ def test_remove_without_specific_group_removes_from_specific_groups(
baz = "^1.0.0"
"""
# At the moment line endings will be inconsistent on Windows.
# See https://github.com/sdispater/tomlkit/issues/200 for details.
# https://github.com/sdispater/tomlkit/pull/201 fixes this issue
# In order to make tests forward compatible for tomlkit downstream tests,
# we replace "\r\n" with "\n" for now.
string_content = content.as_string().replace("\r\n", "\n")
string_content = content.as_string()
if "\r\n" in string_content:
# consistent line endings
expected = expected.replace("\n", "\r\n")

assert expected in string_content

Expand Down Expand Up @@ -263,12 +259,10 @@ def test_remove_canonicalized_named_removes_dependency_correctly(
baz = "^1.0.0"
"""
# At the moment line endings will be inconsistent on Windows.
# See https://github.com/sdispater/tomlkit/issues/200 for details.
# https://github.com/sdispater/tomlkit/pull/201 fixes this issue
# In order to make tests forward compatible for tomlkit downstream tests,
# we replace "\r\n" with "\n" for now.
string_content = content.as_string().replace("\r\n", "\n")
string_content = content.as_string()
if "\r\n" in string_content:
# consistent line endings
expected = expected.replace("\n", "\r\n")

assert expected in string_content

Expand Down

0 comments on commit 4300362

Please sign in to comment.