Skip to content

Commit

Permalink
Add Python unit tests & coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Feb 25, 2017
1 parent 88f139a commit ba1b5f4
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 12 deletions.
29 changes: 29 additions & 0 deletions .coveragerc
@@ -0,0 +1,29 @@
# .coveragerc to control coverage.py
[run]
branch = True

source = ./wagtaildraftail

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
return NotImplemented

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

ignore_errors = True

[html]
directory = coverage_html_report
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -18,7 +18,7 @@ indent_size = 4
indent_style = tab
indent_size = 8

[*.yml]
[*.{js,json,yml}]
indent_size = 2

# Rules for markdown documents.
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -17,8 +17,8 @@ install:
- pip install tox coveralls
script:
- make test-ci
# after_success:
# - coveralls
after_success:
- coveralls
notifications:
email: false
slack:
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Expand Up @@ -12,10 +12,12 @@ lint: ## Lint the project.
isort --check-only --diff --recursive wagtaildraftail tests setup.py

test: ## Test the project.
./tests/manage.py test
npm run test

test-coverage: ## Run the tests while generating test coverage data.
coverage run -m unittest discover && coverage report
coverage run ./tests/manage.py test && coverage report
npm run test:coverage

test-ci: ## Continuous integration test suite.
tox
Expand Down
9 changes: 8 additions & 1 deletion setup.py
Expand Up @@ -13,13 +13,20 @@


install_requires = [
'draftjs-exporter==0.7.0',
'draftjs_exporter==0.7.0',
]

# Testing dependencies
testing_extras = [
# Required for running the tests
'tox>=2.3.1',

# For coverage and PEP8 linting
'coverage>=4.1.0',
'flake8>=3.2.0',
'isort>=4.2.5',

# For test site
'wagtail==1.9',
]

Expand Down
9 changes: 4 additions & 5 deletions tests/home/migrations/0003_homepage_body.py
Expand Up @@ -2,10 +2,9 @@
# Generated by Django 1.10.5 on 2017-02-24 10:15
from __future__ import absolute_import, unicode_literals

import wagtail.wagtailcore.fields
from django.db import migrations

import wagtaildraftail.fields
from wagtail.wagtailcore.fields import RichTextField
from wagtaildraftail.fields import DraftailTextField


class Migration(migrations.Migration):
Expand All @@ -18,11 +17,11 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='homepage',
name='body_draftail',
field=wagtaildraftail.fields.DraftailTextField(blank=True),
field=DraftailTextField(blank=True),
),
migrations.AddField(
model_name='homepage',
name='body_hallo',
field=wagtail.wagtailcore.fields.RichTextField(blank=True),
field=RichTextField(blank=True),
),
]
11 changes: 11 additions & 0 deletions tests/test_decorators.py
@@ -0,0 +1,11 @@
from __future__ import absolute_import, unicode_literals

from django.test import TestCase

from draftjs_exporter.dom import DOM
from wagtaildraftail.decorators import HR, Icon


class TestIcon(TestCase):
def test_render(self):
self.assertEqual(DOM.render(DOM.create_element(Icon, {'name': 'rocket'})), '<svg class="icon"><use xlink:href="#icon-rocket"></use></svg>')
4 changes: 2 additions & 2 deletions tox.ini
Expand Up @@ -20,5 +20,5 @@ commands = make test

[testenv:py27]
commands =
# make lint
make test
make lint
make test-coverage

0 comments on commit ba1b5f4

Please sign in to comment.