aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/PyHamcrest/tests/test_raises.py
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/python/PyHamcrest/tests/test_raises.py
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/python/PyHamcrest/tests/test_raises.py')
-rw-r--r--contrib/python/PyHamcrest/tests/test_raises.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/contrib/python/PyHamcrest/tests/test_raises.py b/contrib/python/PyHamcrest/tests/test_raises.py
new file mode 100644
index 0000000000..4c9ff4e040
--- /dev/null
+++ b/contrib/python/PyHamcrest/tests/test_raises.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+__author__ = 'asatarin@yandex-team.ru'
+
+
+class TestException(RuntimeError):
+ def __init__(self, *args, **kwargs):
+ super(TestException, self).__init__(*args, **kwargs)
+ self.prop = "property"
+
+
+def raises_exception():
+ raise TestException()
+
+
+def returns_value():
+ return 'my_return_value'
+
+
+def test_raises():
+ """
+ >>> from hamcrest import assert_that
+ >>> from hamcrest import has_property
+ >>> from hamcrest import not_, raises
+ >>> raises(TestException).matches(raises_exception)
+ True
+ >>> raises(TestException, matcher=has_property("prop", "property")).matches(raises_exception)
+ True
+ >>> raises(TestException, matcher=has_property("prop", "fail")).matches(raises_exception)
+ False
+ >>> raises(TestException, matcher=not_(has_property("prop", "fail"))).matches(raises_exception)
+ True
+ >>> raises(TestException, matcher=not_(has_property("prop", "property"))).matches(raises_exception)
+ False
+
+ >>> assert_that(returns_value, raises(TestException), 'message')
+ Traceback (most recent call last):
+ ...
+ AssertionError: message
+ Expected: Expected a callable raising <class '__tests__.test_raises.TestException'>
+ but: No exception raised and actual return value = 'my_return_value'
+ <BLANKLINE>
+ """