Skip to content

Commit

Permalink
Merge pull request #644 from neliseiska/replace_assert_with_raise
Browse files Browse the repository at this point in the history
Replace `assert` with `raise AssertionError`
  • Loading branch information
hartwork authored Jun 22, 2023
2 parents 29e4221 + a79356c commit 8b97fd6
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions vcr/matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,57 @@


def method(r1, r2):
assert r1.method == r2.method, "{} != {}".format(r1.method, r2.method)
if r1.method != r2.method:
raise AssertionError("{} != {}".format(r1.method, r2.method))


def uri(r1, r2):
assert r1.uri == r2.uri, "{} != {}".format(r1.uri, r2.uri)
if r1.uri != r2.uri:
raise AssertionError("{} != {}".format(r1.uri, r2.uri))


def host(r1, r2):
assert r1.host == r2.host, "{} != {}".format(r1.host, r2.host)
if r1.host != r2.host:
raise AssertionError("{} != {}".format(r1.host, r2.host))


def scheme(r1, r2):
assert r1.scheme == r2.scheme, "{} != {}".format(r1.scheme, r2.scheme)
if r1.scheme != r2.scheme:
raise AssertionError("{} != {}".format(r1.scheme, r2.scheme))


def port(r1, r2):
assert r1.port == r2.port, "{} != {}".format(r1.port, r2.port)
if r1.port != r2.port:
raise AssertionError("{} != {}".format(r1.port, r2.port))


def path(r1, r2):
assert r1.path == r2.path, "{} != {}".format(r1.path, r2.path)
if r1.path != r2.path:
raise AssertionError("{} != {}".format(r1.path, r2.path))


def query(r1, r2):
assert r1.query == r2.query, "{} != {}".format(r1.query, r2.query)
if r1.query != r2.query:
raise AssertionError("{} != {}".format(r1.query, r2.query))


def raw_body(r1, r2):
assert read_body(r1) == read_body(r2)
if read_body(r1) != read_body(r2):
raise AssertionError


def body(r1, r2):
transformer = _get_transformer(r1)
r2_transformer = _get_transformer(r2)
if transformer != r2_transformer:
transformer = _identity
assert transformer(read_body(r1)) == transformer(read_body(r2))
if transformer(read_body(r1)) != transformer(read_body(r2)):
raise AssertionError


def headers(r1, r2):
assert r1.headers == r2.headers, "{} != {}".format(r1.headers, r2.headers)
if r1.headers != r2.headers:
raise AssertionError("{} != {}".format(r1.headers, r2.headers))


def _header_checker(value, header="Content-Type"):
Expand Down

0 comments on commit 8b97fd6

Please sign in to comment.