Skip to content

Commit

Permalink
Made unit tests use pytest instead of unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
runfalk committed Mar 11, 2017
1 parent 22f38cd commit d9b3aff
Show file tree
Hide file tree
Showing 24 changed files with 900 additions and 769 deletions.
15 changes: 9 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
language: python
python:
- 2.7
- 3.3
- 3.4
- 3.5
- "2.7"
- "pypy"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
install:
- pip install codecov
- pip install -r requirements.txt
- pip install -r test-requirements.txt
script:
- coverage run -m unittest spans.tests.suite
- pytest
after_success:
- codecov
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
recursive-include spans *.py

include MANIFEST.in LICENSE README.rst Makefile setup.py setup.cfg tox.ini doc/*.rst
include MANIFEST.in LICENSE README.rst Makefile setup.py setup.cfg doc/*.rst
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ the 90s.
>>> date(2000, 1, 1) in the90s
False
>>> the90s.union(daterange(date(2000, 1, 1), date(2010, 1, 1)))
daterange([datetime.date(1990, 1, 1), datetime.date(2010, 1, 1))))
daterange([datetime.date(1990, 1, 1),datetime.date(2010, 1, 1)))
If you are making a booking application for a bed and breakfast hotel and want
to ensure no room gets double booked:
Expand Down
4 changes: 3 additions & 1 deletion doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Released on <unreleased>

- Fixed :class:`~spans.types.daterange` not accepting subclasses of ``date``
(`bug #5 <https://github.com/runfalk/spans/issues/5>`_)

- Fixed some broken doctests
- Moved unit tests to `pytest <http://docs.pytest.org/en/latest/>`_
- Removed `Tox <https://tox.readthedocs.io/en/latest/>`_ config

Version 0.3.0
-------------
Expand Down
13 changes: 13 additions & 0 deletions doc/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import spans
import pytest

from datetime import date, datetime, timedelta

@pytest.fixture(autouse=True)
def doctest_fixture(doctest_namespace):
for attr in spans.__all__:
doctest_namespace[attr] = getattr(spans, attr)

doctest_namespace["date"] = date
doctest_namespace["datetime"] = datetime
doctest_namespace["timedelta"] = timedelta
2 changes: 1 addition & 1 deletion doc/ranges.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Range sets are sets of intervals, where each element must be represented by one
.. code-block:: python
>>> intrangeset([intrange(1, 5), intrange(10, 15)])
intrangeset([intrange([1, 5)), intrange([10,15))])
intrangeset([intrange([1,5)), intrange([10,15))])
Like ranges, range sets support :class:`~spans.settypes.rangeset.union`, :class:`~spans.settypes.rangeset.difference` and :class:`~spans.settypes.rangeset.intersection`. Contrary to Python's built in sets these operations do not modify the range set in place. Instead it returns a new set. Unchanged ranges are reused to conserve memory since ranges are immutable.
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--index-url https://pypi.python.org/simple/
-e .
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
[bdist_wheel]
universal = 1

[coverage:run]
branch = True

[tool:pytest]
addopts = --doctest-glob="*.rst" --doctest-modules --cov=spans/
doctest_optionflags = ALLOW_UNICODE ALLOW_BYTES
norecursedirs = _build
testpaths = spans tests doc README.rst
20 changes: 7 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from setuptools import setup


class RstPreProcessor(object):
def __init__(self):
self.roles = {}
Expand Down Expand Up @@ -80,7 +81,7 @@ def process(self, text):
@rst_pre_processor.add_role("class")
@rst_pre_processor.add_role("attr")
@rst_pre_processor.add_role("meth")
def role_simplyfier(processor, role, argument, content):
def role_simplifier(processor, role, argument, content):
format = {
"attr": "``.{}``",
"meth": "``{}()``",
Expand All @@ -91,20 +92,16 @@ def role_simplyfier(processor, role, argument, content):
else:
return format.get(role, "``{}``").format(content + extra.get(role, ""))

@rst_pre_processor.add_block("image")
def image_remover(processor, block, args, extra, content):
if extra is not None:
processor.add_replacement(extra, "")
return ""

@rst_pre_processor.add_block("include")
def includer(processor, block, args, extra, content):
with open(args) as fp:
return fp.read().rstrip()


def rst_preprocess(file):
"""
Preprocess rST file to support Sphinx like include directive. Includes are
Preprocess reST file to support Sphinx like include directive. Includes are
relative to the current working directory.
"""

Expand All @@ -115,16 +112,14 @@ def rst_preprocess(file):
fp.read(),
flags=re.MULTILINE)


with open("README.rst") as fp:
long_desc = rst_pre_processor.process(fp.read())


with open("spans/__init__.py") as fp:
version = re.search('__version__\s+=\s+"([^"]+)', fp.read()).group(1)

requirements = []
if os.path.exists("requirements.txt"):
with open("requirements.txt") as fp:
requirements = fp.read().split("\n")

if __name__ == "__main__":
setup(
Expand All @@ -137,7 +132,7 @@ def rst_preprocess(file):
author_email="andreas@runfalk.se",
url="https://www.github.com/runfalk/spans",
packages=["spans"],
install_requires=requirements,
install_requires=[],
classifiers=(
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
Expand All @@ -152,5 +147,4 @@ def rst_preprocess(file):
"Topic :: Utilities"
),
zip_safe=False,
test_suite="spans.tests.suite"
)
2 changes: 1 addition & 1 deletion spans/settypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ class strrangeset(rangeset):
>>> strrangeset([
... strrange(u"a", u"f", upper_inc=True),
... strrange(u"0", u"9", upper_inc=True)]) # doctest: +IGNORE_UNICODE
... strrange(u"0", u"9", upper_inc=True)])
strrangeset([strrange([u'0',u':')), strrange([u'a',u'g'))])
Inherits methods from :class:`~spans.settypes.rangeset` and
Expand Down
68 changes: 0 additions & 68 deletions spans/tests/__init__.py

This file was deleted.

0 comments on commit d9b3aff

Please sign in to comment.