Skip to content

Commit

Permalink
use match argument of pytest.raises added in 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
xflr6 committed May 24, 2017
1 parent e4fc60b commit a7d9936
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -8,6 +8,6 @@ python:
cache: pip
install:
- pip install -e .[visualization]
- pip install "pytest>=3" pytest-cov coveralls
- pip install "pytest>=3.1" pytest-cov coveralls
script: pytest
after_success: if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then coveralls; fi
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,7 +1,7 @@
# exact (optional) dependency versions used in development
graphviz==0.7.1
# dependencies for testing and building
pytest>=3
pytest>=3.1
pytest-cov
flake8
pep8-naming
Expand Down
6 changes: 2 additions & 4 deletions tests/test_bases.py
Expand Up @@ -27,9 +27,8 @@ def test_frombits(Ints):


def test_frombits_invalid(Ints):
with pytest.raises(ValueError) as e:
with pytest.raises(ValueError, match=r'too many bits'):
Ints.frombits('1000001')
e.match(r'too many bits')


def test_copy(Ints):
Expand Down Expand Up @@ -163,9 +162,8 @@ def test_powerset_start(Ints):


def test_powerset_invalid_start(Ints):
with pytest.raises(ValueError) as e:
with pytest.raises(ValueError, match=r'no subset'):
Ints('1').powerset(Ints('111'))
e.match(r'no subset')


def test_count(Ints):
Expand Down
21 changes: 7 additions & 14 deletions tests/test_init.py
Expand Up @@ -6,45 +6,38 @@


def test_empty_name():
with pytest.raises(ValueError) as e:
with pytest.raises(ValueError, match=r'empty'):
bitset('', 'abc')
e.match(r'empty')


def test_members_nonsequence():
with pytest.raises(ValueError) as e:
with pytest.raises(ValueError, match=r'sequence'):
bitset('Letters', frozenset('abc'))
e.match(r'sequence')


def test_no_member():
with pytest.raises(ValueError) as e:
with pytest.raises(ValueError, match=r'one'):
bitset('Letters', '')
e.match(r'one')


def test_duplicated_member():
with pytest.raises(ValueError) as e:
with pytest.raises(ValueError, match=r'duplicates'):
bitset('Letters', 'abca')
e.match(r'duplicates')


def test_unhashable_members():
with pytest.raises(TypeError) as e:
with pytest.raises(TypeError, match=r'unhashable'):
bitset('Letters', list('abc'))
e.match(r'unhashable')


def test_unhashable_member():
with pytest.raises(TypeError) as e:
with pytest.raises(TypeError, match=r'unhashable'):
bitset('Letters', ([], None))
e.match(r'unhashable')


def test_wrong_base():
with pytest.raises(ValueError) as e:
with pytest.raises(ValueError, match=r'subclass'):
bitset('Letters', 'abc', set)
e.match(r'subclass')


def test_one_member():
Expand Down
15 changes: 5 additions & 10 deletions tests/test_meta.py
Expand Up @@ -9,10 +9,8 @@


def test_memberbits_make_subclass_invalid(Ints):
with pytest.raises(RuntimeError) as e:
Ints._make_subclass('Ints', (1, 2, 3, 4, 5, 6),
None, None, None)
e.match(r'make_subclass')
with pytest.raises(RuntimeError, match=r'make_subclass'):
Ints._make_subclass('Ints', (1, 2, 3, 4, 5, 6), None, None, None)


def test_repr_ints_cls(Ints):
Expand All @@ -21,11 +19,9 @@ def test_repr_ints_cls(Ints):

def test_get_subclass(Ints):
with pytest.raises(RuntimeError):
MemberBits._get_subclass('Ints', (1, 2, 3, 4, 5, 6),
None, None, None)
MemberBits._get_subclass('Ints', (1, 2, 3, 4, 5, 6), None, None, None)
assert isinstance(
MemberBits._get_subclass('Ints', (1, 2, 3, 4, 5, 6),
-1, None, None),
MemberBits._get_subclass('Ints', (1, 2, 3, 4, 5, 6), -1, None, None),
MemberBits.__class__)


Expand Down Expand Up @@ -54,9 +50,8 @@ def test_reduce_or(Ints):


def test_series_make_subclass_invalid(Nums):
with pytest.raises(RuntimeError) as e:
with pytest.raises(RuntimeError, match=r'make_subclass'):
Nums.List._make_subclass('NumsList', Nums.List)
e.match(r'make_subclass')


def test_repr_nums_cls(Nums):
Expand Down

0 comments on commit a7d9936

Please sign in to comment.