Skip to content

Commit af27821

Browse files
authored
Merge pull request #32 from timvink/update-unit-tests
Extend unit tests to cover more python versions
2 parents 790a9cc + 5196442 commit af27821

File tree

5 files changed

+143
-46
lines changed

5 files changed

+143
-46
lines changed

.github/workflows/unittests.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Unit tests
2+
on: [pull_request]
3+
jobs:
4+
run:
5+
name: Run unit tests with codecov upload
6+
runs-on: ${{ matrix.os }}
7+
env:
8+
USING_COVERAGE: '3.7'
9+
strategy:
10+
matrix:
11+
os: [ubuntu-latest, macos-latest, windows-latest]
12+
python-version: [3.5, 3.6, 3.7]
13+
steps:
14+
- uses: actions/checkout@master
15+
16+
- name: Setup Python
17+
uses: actions/setup-python@master
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
21+
# https://github.com/actions/virtual-environments/issues/294
22+
- name: Configure path to rc.exe for Python 3.5
23+
run: |
24+
function Invoke-VSDevEnvironment {
25+
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
26+
$installationPath = & $vswhere -prerelease -legacy -latest -property installationPath
27+
$Command = Join-Path $installationPath "Common7\Tools\vsdevcmd.bat"
28+
& "${env:COMSPEC}" /s /c "`"$Command`" -no_logo && set" | Foreach-Object {
29+
if ($_ -match '^([^=]+)=(.*)') {
30+
[System.Environment]::SetEnvironmentVariable($matches[1], $matches[2])
31+
}
32+
}
33+
}
34+
Invoke-VSDevEnvironment
35+
Get-Command rc.exe | Format-Table -AutoSize
36+
if: matrix.os == 'windows-latest' && matrix.python-version == '3.5'
37+
38+
- name: Install dependencies
39+
run: |
40+
pip3 install --upgrade pip
41+
pip3 install --upgrade setuptools
42+
pip3 install --upgrade wheel
43+
pip3 install pyflakes
44+
pip3 install -r tests/test_requirements.txt
45+
pip3 install -e .
46+
47+
- name: Static code checking with pyflakes
48+
run: |
49+
pyflakes mkdocs_git_revision_date_localized_plugin
50+
51+
- name: Run unit tests
52+
run: |
53+
git config --global user.name "Github Action"
54+
git config --global user.email "[email protected]"
55+
pytest --cov=mkdocs_git_revision_date_localized_plugin --cov-report=xml
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: pytest
2+
on:
3+
# Trigger the workflow on push or pull request,
4+
# but only for the master branch
5+
push:
6+
branches:
7+
- master
8+
pull_request:
9+
branches:
10+
- master
11+
jobs:
12+
run:
13+
name: Run unit tests with codecov upload
14+
runs-on: ${{ matrix.os }}
15+
env:
16+
USING_COVERAGE: '3.7'
17+
strategy:
18+
matrix:
19+
os: [ubuntu-latest, macos-latest, windows-latest]
20+
python-version: [3.5, 3.6, 3.7]
21+
steps:
22+
- uses: actions/checkout@master
23+
24+
- name: Setup Python
25+
uses: actions/setup-python@master
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
# https://github.com/actions/virtual-environments/issues/294
30+
- name: Configure path to rc.exe for Python 3.5
31+
run: |
32+
function Invoke-VSDevEnvironment {
33+
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
34+
$installationPath = & $vswhere -prerelease -legacy -latest -property installationPath
35+
$Command = Join-Path $installationPath "Common7\Tools\vsdevcmd.bat"
36+
& "${env:COMSPEC}" /s /c "`"$Command`" -no_logo && set" | Foreach-Object {
37+
if ($_ -match '^([^=]+)=(.*)') {
38+
[System.Environment]::SetEnvironmentVariable($matches[1], $matches[2])
39+
}
40+
}
41+
}
42+
Invoke-VSDevEnvironment
43+
Get-Command rc.exe | Format-Table -AutoSize
44+
if: matrix.os == 'windows-latest' && matrix.python-version == '3.5'
45+
46+
- name: Install dependencies
47+
run: |
48+
pip3 install --upgrade pip
49+
pip3 install --upgrade setuptools
50+
pip3 install --upgrade wheel
51+
pip3 install pyflakes
52+
pip3 install -r tests/test_requirements.txt
53+
pip3 install -e .
54+
55+
- name: Static code checking with pyflakes
56+
run: |
57+
pyflakes mkdocs_git_revision_date_localized_plugin
58+
59+
- name: Generate coverage report
60+
run: |
61+
git config --global user.name "Github Action"
62+
git config --global user.email "[email protected]"
63+
pytest --cov=mkdocs_git_revision_date_localized_plugin --cov-report=xml
64+
65+
- name: Upload coverage to Codecov
66+
if: "contains(env.USING_COVERAGE, matrix.python-version)"
67+
uses: codecov/codecov-action@v1
68+
with:
69+
token: ${{ secrets.CODECOV_TOKEN }}
70+
file: ./coverage.xml
71+
flags: unittests
72+
fail_ci_if_error: true

.github/workflows/workflow.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

mkdocs_git_revision_date_localized_plugin/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def get_revision_date_for_file(
9292
logging.warning(
9393
"Unable to read git logs of '%s'."
9494
" Is git log readable?"
95-
" Option 'fallback_to_build_date' enabled: so keep building..." % path
95+
" Option 'fallback_to_build_date' enabled: so keep building..."
96+
% path
9697
)
9798
else:
9899
logging.error(

tests/test_basic.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ def setup_clean_mkdocs_folder(mkdocs_yml_path, output_path):
8484
testproject_path = output_path / "testproject"
8585

8686
# Create empty 'testproject' folder
87-
if os.path.exists(testproject_path):
87+
if os.path.exists(str(testproject_path)):
8888
logging.warning(
8989
"""This command does not work on windows.
9090
Refactor your test to use setup_clean_mkdocs_folder() only once"""
9191
)
92-
shutil.rmtree(testproject_path)
92+
shutil.rmtree(str(testproject_path))
9393

9494
# Copy correct mkdocs.yml file and our test 'docs/'
95-
shutil.copytree("tests/basic_setup/docs", testproject_path / "docs")
96-
shutil.copyfile(mkdocs_yml_path, testproject_path / "mkdocs.yml")
95+
shutil.copytree("tests/basic_setup/docs", str(testproject_path / "docs"))
96+
shutil.copyfile(mkdocs_yml_path, str(testproject_path / "mkdocs.yml"))
9797

9898
return testproject_path
9999

@@ -112,7 +112,8 @@ def setup_commit_history(testproject_path):
112112
Returns:
113113
repo (repo): git.Repo object
114114
"""
115-
assert not os.path.exists(testproject_path / ".git")
115+
assert not os.path.exists(str(testproject_path / ".git"))
116+
testproject_path = str(testproject_path)
116117

117118
repo = git.Repo.init(testproject_path, bare=False)
118119
author = "Test Person <[email protected]>"
@@ -164,7 +165,7 @@ def build_docs_setup(testproject_path):
164165

165166
# TODO: Try specifying path in CliRunner, this function could be one-liner
166167
cwd = os.getcwd()
167-
os.chdir(testproject_path)
168+
os.chdir(str(testproject_path))
168169

169170
try:
170171
runner = CliRunner()
@@ -183,21 +184,21 @@ def validate_build(testproject_path, plugin_config: dict):
183184
Args:
184185
testproject_path (Path): Path to test project
185186
"""
186-
assert os.path.exists(testproject_path / "site")
187+
assert os.path.exists(str(testproject_path / "site"))
187188

188189
# Make sure index file exists
189190
index_file = testproject_path / "site/index.html"
190-
assert index_file.exists(), f"{index_file} does not exist"
191+
assert index_file.exists(), "%s does not exist" % index_file
191192

192193
# Make sure with markdown tag has valid
193194
# git revision date tag
194195
page_with_tag = testproject_path / "site/page_with_tag/index.html"
195196
contents = page_with_tag.read_text(encoding="utf8")
196197
assert re.search(r"Markdown tag\:\s[<span>|\w].+", contents)
197198

198-
repo = Util(testproject_path)
199+
repo = Util(str(testproject_path))
199200
date_formats = repo.get_revision_date_for_file(
200-
path=testproject_path / "docs/page_with_tag.md",
201+
path=str(testproject_path / "docs/page_with_tag.md"),
201202
locale=plugin_config.get("locale"),
202203
fallback_to_build_date=plugin_config.get("fallback_to_build_date"),
203204
)
@@ -333,14 +334,14 @@ def test_low_fetch_depth(tmp_path, caplog):
333334
repo = setup_commit_history(testproject_path)
334335

335336
# Create a second, clean folder to clone to
336-
cloned_folder = tmp_path.parent / "clonedrepo"
337+
cloned_folder = str(tmp_path.parent / "clonedrepo")
337338
if os.path.exists(cloned_folder):
338339
shutil.rmtree(cloned_folder)
339-
os.mkdir(cloned_folder)
340+
# os.mkdir(cloned_folder)
340341

341342
# Clone the local repo with fetch depth of 1
342343
repo = git.Repo.init(cloned_folder, bare=False)
343-
origin = repo.create_remote("origin", testproject_path)
344+
origin = repo.create_remote("origin", str(testproject_path))
344345
origin.fetch(depth=1, prune=True)
345346
repo.create_head(
346347
"master", origin.refs.master

0 commit comments

Comments
 (0)