diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/python/PyHamcrest/tests | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/python/PyHamcrest/tests')
-rw-r--r-- | contrib/python/PyHamcrest/tests/test_raises.py | 45 | ||||
-rw-r--r-- | contrib/python/PyHamcrest/tests/test_string_description.py | 17 | ||||
-rw-r--r-- | contrib/python/PyHamcrest/tests/ya.make | 16 |
3 files changed, 78 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> + """ diff --git a/contrib/python/PyHamcrest/tests/test_string_description.py b/contrib/python/PyHamcrest/tests/test_string_description.py new file mode 100644 index 0000000000..40cbdd226e --- /dev/null +++ b/contrib/python/PyHamcrest/tests/test_string_description.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from hamcrest import assert_that, empty, equal_to + +__author__ = 'asatarin@yandex-team.ru' + + +def test_string_description_is_fast(): + list_of_very_long_strings = ["aa"*1000 for _ in range(10000)] + try: + assert_that(list_of_very_long_strings, empty()) + x = 0 + except AssertionError as e: + x = len(str(e)) + + assert_that(x, equal_to(20040048)) diff --git a/contrib/python/PyHamcrest/tests/ya.make b/contrib/python/PyHamcrest/tests/ya.make new file mode 100644 index 0000000000..6519301793 --- /dev/null +++ b/contrib/python/PyHamcrest/tests/ya.make @@ -0,0 +1,16 @@ +OWNER(g:python-contrib) + +PY23_TEST() + +NO_LINT() + +TEST_SRCS( + test_raises.py + test_string_description.py +) + +PEERDIR( + contrib/python/PyHamcrest +) + +END() |