Skip to content

Commit

Permalink
refactor: Use pytest (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
last-partizan committed Feb 22, 2022
1 parent 9470cab commit d073171
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 96 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
strategy:
matrix:
python:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
Expand All @@ -23,7 +22,8 @@ jobs:
python-version: ${{ matrix.python }}
- name: Set up env
run: |
python -m pip install -q tox tox-gh-actions
python -m pip install -q poetry
poetry install
- name: Run tests
run: |
tox
poetry run tox
3 changes: 2 additions & 1 deletion doc/examples-django/pytilsex/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# Local time zone for this installation. All choices can be found here:
# http://www.postgresql.org/docs/current/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
TIME_ZONE = 'UTC'
USE_TZ = False

# Language code for this installation. All choices can be found here:
# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
Expand Down Expand Up @@ -60,7 +61,7 @@
'django.middleware.common.CommonMiddleware',
)

ROOT_URLCONF = 'urls'
ROOT_URLCONF = 'pytilsex.urls'

TEMPLATES = [
{
Expand Down
43 changes: 19 additions & 24 deletions doc/examples/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
import sys

import pytest

EXAMPLES = [
'dt.distance_of_time_in_words.py',
Expand Down Expand Up @@ -63,33 +64,27 @@ def run_test(self, name, i):
"Real output %r doesn't match to expected %r for example #%s" % (self.real_output[i], self.expected_output[i], i)


def test_example():
def test_python_version():
# check that `python something.py` will run the same version interepreter as it is running
import sys
current_version = str(sys.version_info)
exec_version = subprocess.check_output(
['python', '-c', 'import sys; print(sys.version_info)'],
stderr=subprocess.STDOUT,
).strip()
assert current_version == exec_version.decode('utf-8')


def generate_example_tests():
for example in EXAMPLES:
runner = ExampleFileTestSuite(example)
# we want to have granular test, one test case per line
# nose show each test as "executable, arg1, arg2", that's
# why we want pass example name again, even test runner already knows it
for i in runner.test_cases():
yield runner.run_test, example, i
yield runner, example, i


def assert_python_version(current_version):
exec_version = subprocess.check_output(
['python', '-c', 'import sys; print(sys.version_info)'], stderr=subprocess.STDOUT).strip()
assert current_version == exec_version.decode('utf-8')


def test_python_version():
# check that `python something.py` will run the same version interepreter as it is running
import sys
current_version = str(sys.version_info)
# do a yield to show in the test output the python version
yield assert_python_version, current_version


if __name__ == '__main__':
import sys

import nose2
if not nose2.main():
sys.exit(1)
@pytest.mark.parametrize("runner,name,i", generate_example_tests())
def test_examples(runner: ExampleFileTestSuite, name: str, i: int):
runner.run_test(name, i)
Loading

0 comments on commit d073171

Please sign in to comment.