Skip to content

Commit

Permalink
Unittests for python 3.5-3.7 (#29)
Browse files Browse the repository at this point in the history
* Unittests for python 3.5-3.7

* Fix subprocess call for python 3.5 3.6

* Remove f-string for python 3.5 compatibility

* PosixPath to str for py3.5

* remove os.path.join for python 3.5 test compatibility

* more python 3.5 compat

* drop encoding parameter to support python 3.5

* decode stdout for python 3.5 compatibility

* remove unused import
  • Loading branch information
timvink committed Mar 14, 2020
1 parent 870b269 commit 852c11c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.5, 3.6, 3.7]
steps:
- uses: actions/checkout@master
- name: Setup Python
uses: actions/setup-python@master
with:
python-version: 3.7
python-version: ${{ matrix.python-version }}
- name: Static code checking with pyflakes
run: |
pip install pyflakes
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/unittests_codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.5, 3.6, 3.7]
steps:
- uses: actions/checkout@master
- name: Setup Python
uses: actions/setup-python@master
with:
python-version: 3.7
python-version: ${{ matrix.python-version }}
- name: Static code checking with pyflakes
run: |
pip install pyflakes
Expand Down
19 changes: 10 additions & 9 deletions mkdocs_git_authors_plugin/git/command.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import subprocess


class GitCommandError(Exception):
"""
Exception thrown by a GitCommand.
Expand Down Expand Up @@ -59,8 +58,9 @@ def run(self):
args.extend(self._args)
p = subprocess.run(
args,
encoding='utf8',
capture_output=True
# encoding='utf8', # Uncomment after dropping support for python 3.5
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
try:
p.check_returncode()
Expand All @@ -69,16 +69,17 @@ def run(self):
msg.append('Command "%s" failed' % ' '.join(args))
msg.append('Return code: %s' % p.returncode)
msg.append('Output:')
msg.append(p.stdout)
msg.append(p.stdout.decode("utf-8"))
msg.append('Error messages:')
msg.append(p.stderr)
msg.append(p.stderr.decode("utf-8"))
raise GitCommandError('\n'.join(msg))

self._stdout = p.stdout.strip('\'\n').split('\n')
self._stderr = p.stderr.strip('\'\n').split('\n')

self._stdout = p.stdout.decode("utf-8").strip('\'\n').split('\n')
self._stderr = p.stderr.decode("utf-8").strip('\'\n').split('\n')


self._completed = True
return p.returncode
return int(str(p.returncode))

def set_args(self, args: list):
"""
Expand Down
6 changes: 1 addition & 5 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import re
import yaml
from click.testing import CliRunner
from mkdocs.__main__ import build_command


def load_config(mkdocs_path):
return yaml.load(open(mkdocs_path, 'rb'), Loader=yaml.Loader)

def build_docs_setup(mkdocs_path, output_path):
runner = CliRunner()
return runner.invoke(build_command,
Expand All @@ -21,7 +17,7 @@ def test_basic_working(tmp_path):
assert result.exit_code == 0, "'mkdocs build' command failed"

index_file = tmp_path/'index.html'
assert index_file.exists(), f"{index_file} does not exist"
assert index_file.exists(), "%s does not exist" % index_file

contents = index_file.read_text()
assert re.search("<span class='git-authors'>", contents)
3 changes: 2 additions & 1 deletion tests/test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pytest
pytest-cov
codecov
click
GitPython
GitPython
mkdocs
16 changes: 8 additions & 8 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ def setup_commit_history(testproject_path):

# Change the working directory
cwd = os.getcwd()
os.chdir(testproject_path)
os.chdir(str(testproject_path))

try:
repo.git.add('mkdocs.yml')
repo.git.commit(message = 'add mkdocs', author = author)

repo.git.add('docs/first_page.md')
repo.git.commit(message = 'first page', author = author)
file_name = os.path.join(testproject_path, 'docs/first_page.md')
file_name = testproject_path / 'docs/first_page.md'
with open(file_name, 'w+') as the_file:
the_file.write('Hello\n')
repo.git.add('docs/first_page.md')
Expand All @@ -112,9 +112,9 @@ def setup_commit_history(testproject_path):
repo.git.commit(message = 'homepage', author = author)
repo.git.add('docs/page_with_tag.md')
repo.git.commit(message = 'homepage', author = author)
os.chdir(cwd)
os.chdir(str(cwd))
except:
os.chdir(cwd)
os.chdir(str(cwd))
raise

return repo
Expand All @@ -125,10 +125,10 @@ def setup_commit_history(testproject_path):
def test_empty_file(tmp_path):

# Change working directory
os.chdir(tmp_path)
os.chdir(str(tmp_path))

# Create empty file
file_name = os.path.join(tmp_path, 'new-file')
file_name = str(tmp_path / 'new-file')
open(file_name, 'a').close()

# Get authors of empty, uncommitted file
Expand Down Expand Up @@ -162,10 +162,10 @@ def test_retrieve_authors(tmp_path):
Args:
tmp_path (PosixPath): Directory of a tempdir
"""
os.chdir(tmp_path)
os.chdir(str(tmp_path))

# Create file
file_name = os.path.join(tmp_path, 'new-file')
file_name = str(tmp_path / 'new-file')
with open(file_name, 'w') as the_file:
the_file.write('Hello\n')

Expand Down

0 comments on commit 852c11c

Please sign in to comment.