Commits

Jonathan Eunice  committed f92a8e7

Added pytest-cov to testing discipline. Used its report of lines
not tested to add tests. Coverage now ~100%, though not all lines
are executed on all versions of Python (py2 vs py3, eg).

  • Participants
  • Parent commits e50624e

Comments (0)

Files changed (6)

 .DS_Store
 build/*
 dist/*
+test/.coverage
 *.egg-info
 setup.cfg
 PKG-INFO
     Thank you, Jeff!
 
  *  Automated multi-version testing managed with the wonderful
-    `pytest <http://pypi.python.org/pypi/pytest>`_
+    `pytest <http://pypi.python.org/pypi/pytest>`_,
+    `pytest-cov <http://pypi.python.org/pypi/pytest>`_,
     and `tox <http://pypi.python.org/pypi/tox>`_. 
     Successfully packaged for, and tested against, all late-model verions of
     Python: 2.6, 2.7, 3.2, and 3.3, as well as PyPy 1.9 (based on 2.7.2).
+    Test line coverage ~100%.
  
  *  The author, `Jonathan Eunice <mailto:jonathan.eunice@gmail.com>`_ or
     `@jeunice on Twitter <http://twitter.com/jeunice>`_
     basestring = str
     
 SPANRE = re.compile(r'^\s*(?P<start>-?\d+)\s*(-\s*(?P<stop>-?\d+))?\s*$')
+class ParseError(ValueError):
+    pass
         
 class intspan(set):
     def __init__(self, initial=None):
                     return list(range(start, stop+1))
                 return [ start ]
             else:
-                raise ValueError("Can't parse chunk '{0}'".format(chunk))
+                raise ParseError("Can't parse chunk '{0}'".format(chunk))
         
         if isinstance(datum, basestring):
             result = []
 
 setup(
     name='intspan',
-    version='0.71',
+    version='0.72',
     author='Jonathan Eunice',
     author_email='jonathan.eunice@gmail.com',
     description="Sets of integers like 1,3-7,33. Inspired by Perl's Set::IntSpan",
     url='https://bitbucket.org/jeunice/intspan',
     py_modules=['intspan'],
     install_requires=[],
-    tests_require = ['tox', 'pytest'],
+    tests_require = ['tox', 'pytest', 'pytest-cov'],
     zip_safe = True,
     keywords='integer set span range intspan intrange',
     classifiers=linelist("""

File test/test_intspan.py

 
-from intspan import intspan
+import pytest
+from intspan import *
 
 def test_basic():
     s = intspan()
         s = intspan(t)
         assert str(s) == t
         
+def test_parse_error():
+    with pytest.raises(ParseError):
+        s = intspan('7*99')
+    with pytest.raises(ParseError):
+        s = intspan('1-4,5-')
+        
 def test_negatives():
     assert list(intspan('-2')) == [-2]
     assert list(intspan('-2-1')) == [-2, -1, 0, 1]
     s.discard('2,13,92')
     assert str(s) == '1,3,14,29,93-97'
 
+def test_remove():
+    s = intspan('1-3,14,29,92-97')
+    s.remove('2,92')
+    assert str(s) == '1,3,14,29,93-97'
+    with pytest.raises(KeyError):
+        s.remove(1000)
+    
 def test_add():
     s = intspan('1-2')
     s.add('3,29')
     assert intspan.from_ranges([ (1,3) ]) == intspan('1-3')
     assert intspan.from_ranges([ (2,2) ]) == intspan('2')
     assert intspan.from_ranges([]) == intspan()
-
+    
+def test_repr():
+    s = intspan('10-20,50-55')
+    s.add(9)
+    s.discard('15-40')
+    assert str(s) == '9-14,50-55'
+    assert repr(s) == "intspan('" + str(s) + "')"
 changedir=test
 deps=
     pytest 
-commands=py.test {posargs}
+    pytest-cov
+commands=py.test {posargs: --cov-report term-missing --cov intspan}