Skip to content

Commit

Permalink
ok forget testing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hjwp committed Nov 20, 2019
1 parent c97f6c0 commit bbafe7d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 64 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ install:
- gem install asciidoctor coderay
- pip install -r requirements.txt
script:
- make html update-code code-venv test
- make html update-code test
git:
submodules: false
before_install:
- sudo apt-get install -y tree python-pygments
- python3.8 -m ensurepip
- sed -i [email protected]:_https://github.com/_ .gitmodules
- git submodule update --init --recursive
8 changes: 0 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ update-code:
cd code && git fetch
./checkout-branches-for-ci.py

code-venv:
cd code && \
python3.8 -m venv .venv && \
.venv/bin/pip install -r requirements.txt && \
.venv/bin/pip install -e src



count-todos:
ls *.asciidoc | xargs grep -c TODO | sed s/:/\\t/

Expand Down
86 changes: 32 additions & 54 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=redefined-outer-name
import re
import subprocess
from contextlib import contextmanager
from dataclasses import dataclass
from pathlib import Path
from lxml import html
Expand Down Expand Up @@ -71,6 +72,36 @@ def test_chapter(chapter):
check_listing(listing, chapter)


@contextmanager
def checked_out(chapter):
subprocess.run(
['git', 'checkout', f'{chapter}'],
cwd=Path(__file__).parent / 'code',
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
check=True
)
try:
yield

finally:
subprocess.run(
['git', 'checkout', '-'],
cwd=Path(__file__).parent / 'code',
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
check=True
)


def tree_for_branch(chapter_name):
with checked_out(chapter_name):
return subprocess.run(
['tree', '-I', '__pycache__|*.egg-info'],
cwd=Path(__file__).parent / 'code',
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
check=True
).stdout.decode()


def check_listing(listing, chapter):
if 'tree' in listing.classes:
actual_contents = tree_for_branch(chapter)
Expand Down Expand Up @@ -129,6 +160,7 @@ def fixed_contents(self):
def lines(self):
return self.fixed_contents.split('\n')


def parse_listings(chapter_name):
raw_contents = Path(f'{chapter_name}.html').read_text()
parsed_html = html.fromstring(raw_contents)
Expand Down Expand Up @@ -193,57 +225,3 @@ def diff_for_tag(filename, chapter_name, tag):
).stdout.decode()
assert output.strip(), f'no commit found for [{tag}]'
return output


from contextlib import contextmanager

@contextmanager
def checked_out(chapter):
subprocess.run(
['git', 'checkout', f'{chapter}'],
cwd=Path(__file__).parent / 'code',
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
check=True
)
try:
yield

finally:
subprocess.run(
['git', 'checkout', '-'],
cwd=Path(__file__).parent / 'code',
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
check=True
)

def tree_for_branch(chapter_name):
with checked_out(chapter_name):
return subprocess.run(
['tree', '-I', '__pycache__|*.egg-info'],
cwd=Path(__file__).parent / 'code',
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
check=True
).stdout.decode()


@pytest.mark.parametrize('chapter', CHAPTERS)
def test_tests_pass(chapter):
with checked_out(chapter):
cwd = Path(__file__).parent / 'code'
pytest = cwd / '.venv/bin/pytest'
unit_tests_folder = cwd / 'tests/unit'
if unit_tests_folder.exists():
tests = [str(unit_tests_folder)]
elif '04' in chapter:
tests = ['test_batches.py', 'test_services.py']
else:
tests = []

if 'django' in chapter:
return # TODO - pip install pytest-django, djanog, set DJANGO_SETTINGS_MODULE=djangoproject.django_project.settings

subprocess.run(
[str(pytest), *tests],
cwd=cwd,
check=True,
)

0 comments on commit bbafe7d

Please sign in to comment.