File: helper.py

package info (click to toggle)
anytree 2.13.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,012 kB
  • sloc: python: 3,966; makefile: 64
file content (19 lines) | stat: -rw-r--r-- 543 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""Helper Methods for testing."""

from contextlib import contextmanager


def eq_(one, other):
    assert one == other, f"{one} != {other}"


# hack own assert_raises, because py26 has a different implementation
@contextmanager
def assert_raises(exccls, msg):
    """Check exception of class `exccls` to be raised with message `msg`."""
    try:
        yield
        raise AssertionError(f"{exccls!r} not raised")
    except Exception as exc:
        assert isinstance(exc, exccls), f"{exc!r} is not a {exccls!r}"
        eq_(str(exc), msg)