Skip to content

Commit 434c214

Browse files
committed
Finally fix tests on Windows.
1 parent 7b4441e commit 434c214

File tree

7 files changed

+136
-5
lines changed

7 files changed

+136
-5
lines changed

repo_helper/cli/utils.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import datetime
2828
import logging
2929
import os
30+
import platform
3031
import textwrap
3132
from typing import Iterable, Optional
3233

@@ -90,12 +91,18 @@ def commit_changed_files(
9091
staged_files = []
9192

9293
for filename in managed_files:
93-
if filename.encode("UTF-8") in unstaged_changes or filename in untracked_files:
94-
r.stage(os.path.normpath(filename))
94+
if filename.encode("UTF-8") in unstaged_changes or os.path.normpath(filename) in untracked_files:
95+
r.stage(filename)
96+
staged_files.append(filename)
97+
elif (
98+
os.path.normpath(filename) in stat.staged["add"]
99+
or os.path.normpath(filename) in stat.staged["modify"]
100+
or os.path.normpath(filename) in stat.staged["delete"]
101+
):
95102
staged_files.append(filename)
96103

97104
# Ensure pre-commit hooks are installed
98-
if enable_pre_commit:
105+
if enable_pre_commit and platform.system() == "Linux":
99106
with in_directory(repo_path):
100107
pre_commit.main.main(["install"])
101108

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apeye>=0.3.0
22
attrs>=20.2.0
33
click==7.1.2
4-
configconfig>=0.3.0
4+
configconfig>=0.4.0
55
consolekit>=0.1.2
66
css-parser==1.0.6
77
domdf-python-tools>=1.1.0

tests/test_core.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# stdlib
22
import datetime
3+
import os
34
import pathlib
45
import re
56
from tempfile import TemporaryDirectory
@@ -22,7 +23,44 @@
2223
FAKE_DATE = datetime.date(2020, 7, 25)
2324

2425

25-
def test_via_run_repo_helper(capsys, file_regression: FileRegressionFixture, monkeypatch):
26+
@pytest.mark.skipif(condition=os.sep == "\\", reason="Different test for platforms where os.sep == \\")
27+
def test_via_run_repo_helper_forward(capsys, file_regression: FileRegressionFixture, monkeypatch):
28+
29+
# Monkeypatch dulwich so it doesn't try to use the global config.
30+
monkeypatch.setattr(StackedConfig, "default_backends", lambda *args: [], raising=True)
31+
monkeypatch.setenv("GIT_COMMITTER_NAME", "Guido")
32+
monkeypatch.setenv("GIT_COMMITTER_EMAIL", "[email protected]")
33+
monkeypatch.setenv("GIT_AUTHOR_NAME", "Guido")
34+
monkeypatch.setenv("GIT_AUTHOR_EMAIL", "[email protected]")
35+
36+
monkeypatch.setattr(repo_helper.utils, "today", FAKE_DATE)
37+
38+
with TemporaryDirectory() as tmpdir:
39+
40+
path = PathPlus(tmpdir) / "~$tmp"
41+
path.mkdir()
42+
Repo.init(path)
43+
44+
(path / "repo_helper.yml").write_text((pathlib.Path(__file__).parent / "repo_helper.yml_").read_text())
45+
46+
run_repo_helper(path, force=False, initialise=True, commit=True, message="Testing Testing")
47+
48+
assert not status(path).untracked
49+
assert not status(path).unstaged
50+
51+
run_repo_helper(path, force=False, initialise=False, commit=True, message="Updated")
52+
53+
assert not status(path).untracked
54+
assert not status(path).unstaged
55+
56+
sha = "6d8cf72fff6adc4e570cb046ca417db7f2e10a3b"
57+
stdout = re.sub(f"Committed as [A-Za-z0-9]{{{len(sha)}}}", f"Committed as {sha}", capsys.readouterr().out)
58+
file_regression.check(stdout, extension="_stdout.txt", encoding="UTF-8")
59+
file_regression.check(capsys.readouterr().err, extension="_stderr.txt", encoding="UTF-8")
60+
61+
62+
@pytest.mark.skipif(condition=os.sep == "/", reason="Different test for platforms where os.sep == /")
63+
def test_via_run_repo_helper_backward(capsys, file_regression: FileRegressionFixture, monkeypatch):
2664

2765
# Monkeypatch dulwich so it doesn't try to use the global config.
2866
monkeypatch.setattr(StackedConfig, "default_backends", lambda *args: [], raising=True)

tests/test_core_/test_via_run_repo_helper_backward_stderr.txt

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
The following files will be committed:
3+
.dependabot\config.yml
4+
.github\ISSUE_TEMPLATE\bug_report.md
5+
.github\ISSUE_TEMPLATE\feature_request.md
6+
.github\workflows\docs_test_action.yml
7+
.github\workflows\octocheese.yml
8+
.github\workflows\python_ci.yml
9+
.github\workflows\python_ci_macos.yml
10+
.github\auto_assign.yml
11+
.github\stale.yml
12+
doc-source\404.rst
13+
doc-source\conf.py
14+
doc-source\contributing.rst
15+
doc-source\docutils.conf
16+
doc-source\git_download.png
17+
doc-source\index.rst
18+
doc-source\not-found.png
19+
doc-source\requirements.txt
20+
doc-source\Source.rst
21+
tests\requirements.txt
22+
.bumpversion.cfg
23+
.gitignore
24+
.imgbotconfig
25+
.isort.cfg
26+
.pre-commit-config.yaml
27+
.pylintrc
28+
.readthedocs.yml
29+
.style.yapf
30+
.travis.yml
31+
__pkginfo__.py
32+
CONTRIBUTING.rst
33+
lint_roller.sh
34+
MANIFEST.in
35+
pyproject.toml
36+
README.rst
37+
repo_helper.yml
38+
setup.cfg
39+
setup.py
40+
tox.ini
41+
42+
Committed as 6d8cf72fff6adc4e570cb046ca417db7f2e10a3b
43+
Nothing to commit

tests/test_core_/test_via_run_repo_helper_forward_stderr.txt

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
The following files will be committed:
3+
.dependabot/config.yml
4+
.github/ISSUE_TEMPLATE/bug_report.md
5+
.github/ISSUE_TEMPLATE/feature_request.md
6+
.github/workflows/docs_test_action.yml
7+
.github/workflows/octocheese.yml
8+
.github/workflows/python_ci.yml
9+
.github/workflows/python_ci_macos.yml
10+
.github/auto_assign.yml
11+
.github/stale.yml
12+
doc-source/404.rst
13+
doc-source/Source.rst
14+
doc-source/conf.py
15+
doc-source/contributing.rst
16+
doc-source/docutils.conf
17+
doc-source/git_download.png
18+
doc-source/index.rst
19+
doc-source/not-found.png
20+
doc-source/requirements.txt
21+
tests/requirements.txt
22+
.bumpversion.cfg
23+
.gitignore
24+
.imgbotconfig
25+
.isort.cfg
26+
.pre-commit-config.yaml
27+
.pylintrc
28+
.readthedocs.yml
29+
.style.yapf
30+
.travis.yml
31+
CONTRIBUTING.rst
32+
MANIFEST.in
33+
README.rst
34+
__pkginfo__.py
35+
lint_roller.sh
36+
pyproject.toml
37+
repo_helper.yml
38+
setup.cfg
39+
setup.py
40+
tox.ini
41+
42+
Committed as 6d8cf72fff6adc4e570cb046ca417db7f2e10a3b
43+
Nothing to commit

0 commit comments

Comments
 (0)