Skip to content

Commit

Permalink
Merge pull request #16 from kurtmckee/windows-tests
Browse files Browse the repository at this point in the history
Support running tests on Windows
  • Loading branch information
nedbat authored Dec 14, 2020
2 parents 030663d + 5bb5926 commit b366370
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
6 changes: 6 additions & 0 deletions changelog.d/20201212_221215_kurtmckee_os_sep.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fixed
.....

- Support Windows' directory separator (``\``) in unit test output. (#15)

This allows the unit tests to run in Windows environments.
6 changes: 6 additions & 0 deletions changelog.d/20201212_221749_kurtmckee_os_sep.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fixed
.....

- Explicitly specify the directories and files that Black should scan. (#15)

This prevents Black from scanning every file in a virtual environment.
3 changes: 2 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ def test_unknown_format():
def test_no_such_template():
# If you specify a template name, and it doesn't exist, an error will
# be raised.
with pytest.raises(Exception, match="No such file: changelog.d/foo.j2"):
msg = r"No such file: changelog\.d[/\\]foo\.j2"
with pytest.raises(Exception, match=msg):
Config(new_fragment_template="file: foo.j2")


Expand Down
33 changes: 21 additions & 12 deletions tests/test_create.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test creation logic."""

import os.path
from pathlib import Path

import freezegun
Expand Down Expand Up @@ -130,8 +131,9 @@ def test_create_file_exists(self, fake_git, cli_invoke, changelog_d):
# "create" ended with an error and a message.
assert result.exit_code == 1
expected = (
"File changelog.d/20130225_151617_joedev.rst already exists, "
+ "not overwriting\n"
"File changelog.d"
+ getattr(os.path, "sep", "")
+ "20130225_151617_joedev.rst already exists, not overwriting\n"
)
assert result.stdout == expected

Expand Down Expand Up @@ -231,10 +233,13 @@ def test_create_add(
mock_call.return_value = 0
with freezegun.freeze_time("2013-02-25T15:16:17"):
cli_invoke(["create", "--add"])
mock_call.assert_called_once_with(
["git", "add", "changelog.d/20130225_151617_joedev.rst"]
file_path = (
"changelog.d"
+ getattr(os.path, "sep", "")
+ "20130225_151617_joedev.rst"
)
assert "Added changelog.d/20130225_151617_joedev.rst" in caplog.text
mock_call.assert_called_once_with(["git", "add", file_path])
assert "Added " + file_path in caplog.text

def test_create_add_preference(
self, mocker, fake_git, cli_invoke, changelog_d
Expand All @@ -246,9 +251,12 @@ def test_create_add_preference(
mock_call.return_value = 0
with freezegun.freeze_time("2013-02-25T15:16:17"):
cli_invoke(["create"])
mock_call.assert_called_once_with(
["git", "add", "changelog.d/20130225_151617_joedev.rst"]
file_path = (
"changelog.d"
+ getattr(os.path, "sep", "")
+ "20130225_151617_joedev.rst"
)
mock_call.assert_called_once_with(["git", "add", file_path])

def test_create_add_preference_no_add(
self, caplog, mocker, fake_git, cli_invoke, changelog_d
Expand All @@ -272,11 +280,12 @@ def test_create_add_fail(
mock_call.return_value = 99
with freezegun.freeze_time("2013-02-25T15:16:17"):
result = cli_invoke(["create", "--add"], expect_ok=False)
mock_call.assert_called_once_with(
["git", "add", "changelog.d/20130225_151617_joedev.rst"]
file_path = (
"changelog.d"
+ getattr(os.path, "sep", "") # getattr() prevents MyPy errors
+ "20130225_151617_joedev.rst"
)
mock_call.assert_called_once_with(["git", "add", file_path])
assert result.exit_code == 99
assert "Added" not in caplog.text
assert (
"Couldn't add changelog.d/20130225_151617_joedev.rst" in caplog.text
)
assert "Couldn't add " + file_path in caplog.text
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ commands =
deps =
-r{toxinidir}/requirements/quality.txt
commands =
black --check --diff --line-length=80 .
black --check --diff --line-length=80 src/scriv tests docs setup.py
mypy src/scriv tests
pylint src/scriv tests docs setup.py
pycodestyle src/scriv tests docs setup.py
Expand Down

0 comments on commit b366370

Please sign in to comment.