{"id":349581,"date":"2023-06-30T03:00:20","date_gmt":"2023-06-30T03:00:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=349581"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=349581","title":{"rendered":"<span>\u041b\u0435\u0433\u043a\u0438\u0439 \u0444\u0430\u0437\u0437\u0438\u043d\u0433 \u0432 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u0430\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0hypothesis<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0415\u0441\u043b\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438 \u043e\u00a0hypothesis\u00a0\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b \u0447\u0435\u043c-\u0442\u043e \u043d\u043e\u0432\u044b\u043c \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0439\u0442\u0438 \u0431\u0430\u0433\u0438 \u0442\u0430\u043c, \u0433\u0434\u0435 \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u0443\u0436\u0435 \u0438\u0441\u043a\u0430\u043b\u0438 \u2013 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u044e.\u00a0<\/p>\n<h2>\u041e\u0447\u0435\u043d\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u043e \u0441\u0430\u043c\u043e\u043c\u00a0hypothesis<\/h2>\n<p>\u042d\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 (\u043d\u043e \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c) \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0445\u0438\u0442\u0440\u044b\u0435 \u0431\u0430\u0433\u0438. \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">from hypothesis import given, strategies as st   @given(st.integers(), st.integers()) def test_ints_are_commutative(x, y):     assert x + y == y + x<\/code><\/pre>\n<p><code>st.integers()<\/code> \u2013 \u044d\u0442\u043e \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u201c\u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u201d \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445\u00a0hypothesis, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432\u00a0<code>x<\/code>,\u00a0<code>y<\/code>\u00a0\u0431\u0443\u0434\u0443\u0442 \u0447\u0438\u0441\u043b\u0430. \u0410 \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u2013 \u0432\u044b\u0431\u0435\u0440\u0435\u0442 \u0441\u0430\u043c\u00a0hypothesis. \u0427\u0442\u043e\u0431\u044b \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u043a\u0435\u0439\u0441\u043e\u0432 \u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0432 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0447\u0438\u0441\u043b\u0430 \u043d\u0430\u0434\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u0422.\u0435. \u043c\u043e\u0436\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u0438\u043d\/\u043c\u0430\u043a\u0441 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">from hypothesis import given, strategies as st   @given(     st.integers(min_value=0, max_value=100),      st.integers(min_value=0, max_value=100) ) def test_ints_are_commutative(x: int, y: int):     assert x + y == y + x<\/code><\/pre>\n<p>\u041f\u043e \u043c\u0438\u043c\u043e \u0447\u0438\u0441\u0435\u043b, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e &#8212; \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0435\u0441\u0442\u044c \u043d\u0430 \u0432\u0441\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0436\u0438\u0437\u043d\u0438, \u043f\u0440\u0438\u043c\u0435\u0440\u044b <a href=\"https:\/\/hypothesis.readthedocs.io\/en\/latest\/data.html\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h2>\u041d\u043e \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u0442\u0435\u0441\u0442\u0430\u043c<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0438\u0445 \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438, \u0430 \u0432\u0441\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u2013 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438 \u0445\u043e\u0442\u0438\u043c \u0435\u0451 \u043f\u043e-\u0432\u0441\u044f\u043a\u043e\u043c\u0443 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041d\u0430\u0441 \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b &#8212; \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043b\u043e\u0432\u0430\u0440\u044f. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043a\u00a0hypothesis.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u0430\u044f \u0432\u0435\u0449\u044c \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c &#8212;\u00a0<a href=\"https:\/\/hypothesis.readthedocs.io\/en\/latest\/stateful.html#rule-based-state-machines\" rel=\"noopener noreferrer nofollow\">Rule-based\u00a0state\u00a0machine<\/a>. \u041f\u043e \u0441\u0443\u0442\u0438, \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044d\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443. \u041c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0430 \u0441\u0430\u043c\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0438\u043f\u0430\u00a0<code>Bundle<\/code>\u00a0\u0438 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439\u00a0<code>self<\/code>.\u00a0<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435. \u041d\u043e \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0438\u043f\u0430\u00a0<code>Bundle<\/code>\u00a0\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u0430 <code>@precondition<\/code>. \u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>@rule<\/code>:<\/p>\n<pre><code class=\"python\">keys = Bundle(\"keys\")  @rule(     target=keys,     key=st.text(alphabet=string.ascii_letters, min_size=1),     value=st.integers(min_value=0, max_value=100) ) @precondition(lambda self: self.dictionary_under_test is not None) def add_element(self, key, value):     self.dictionary_under_test[key] = value     self.ideal_dictionary[key] = value     return key<\/code><\/pre>\n<p>\u0423 <code>@rule<\/code>\u00a0\u0435\u0441\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2013\u00a0<code>target<\/code>, \u043e\u043d \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u043c-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u043a\u043b\u044e\u0447 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043a\u043b\u0430\u0441\u0441\u0430\u00a0<code>keys<\/code>. \u0414\u0432\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u2013\u00a0<code>key<\/code>\u00a0\u0438\u00a0<code>value<\/code>, \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0443\u0436\u0435 \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430. \u0418\u0445 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u043c\u0438\u00a0<code>text()<\/code> \u0438\u00a0<code>integers()<\/code>.\u00a0<\/p>\n<p>\u041f\u0440\u043e <code>@precondition<\/code>\u00a0&#8212; \u0432 \u043d\u0435\u043c \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f\u00a0<em>\u0434\u043e<\/em>\u00a0\u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434-\u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0432\u044b\u0437\u0432\u0430\u043d \u0438\u043b\u0438 \u043d\u0435\u0442. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2013 \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0430 \u043c\u044b \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442 \u2013 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.\u00a0<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0431\u0440\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0438\u043f\u0430\u00a0Bundle, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u00a0<code>consumes<\/code>:<\/p>\n<pre><code class=\"python\">@rule(key=consumes(keys)) def remove_element(self, key):     assert self.dictionary_under_test.pop(key) == self.ideal_dictionary.pop(key)<\/code><\/pre>\n<p>\u041a\u043b\u044e\u0447 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0<code>keys<\/code>. \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u2013 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439\u00a0<code>keys<\/code>. \u0415\u0441\u043b\u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0consumes\u00a0\u2013 \u043a\u043b\u044e\u0447 \u043d\u0435 \u0443\u0434\u0430\u043b\u0438\u0442\u0441\u044f \u0438 \u043c\u0435\u0442\u043e\u0434\u044b\u00a0<code>remove_element<\/code>\u00a0\u0438\u00a0<code>add_element<\/code>\u00a0\u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0441 \u0443\u0436\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c.\u00a0<\/p>\n<p>\u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u2013 <code>@invariant<\/code><\/p>\n<pre><code class=\"python\">@invariant() def length_are_equal(self):     assert len(self.dictionary_under_test) == len(self.ideal_dictionary)<\/code><\/pre>\n<p>\u041e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0434\u043e \u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432\u0441\u0435 \u0435\u0449\u0435 \u0432\u0435\u0440\u043d\u043e.\u00a0<\/p>\n<p>\u0418 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0432\u0430\u0436\u043d\u0430\u044f \u0432\u0435\u0449\u044c \u2013 \u043c\u0435\u0442\u043e\u0434\u00a0<code>teardown<\/code>:<\/p>\n<pre><code class=\"python\">def teardown(self):     self.dictionary_under_test = {}     self.ideal_dictionary = {} <\/code><\/pre>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u0435\u0439\u0441\u0430 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u0437\u0430 \u0441\u043e\u0431\u043e\u0439.<\/p>\n<p>\u041f\u043e \u043c\u0438\u043c\u043e \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e, \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0435\u0439\u0441\u043e\u0432 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043a\u0435\u0439\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u00a0hypothesis. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:<\/p>\n<pre><code class=\"python\">StorageSystemTest.TestCase.settings = settings(     max_examples=10, stateful_step_count=5 )<\/code><\/pre>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u043e \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"bash\">pytest -s --hypothesis-show-statistics --hypothesis-verbosity=debug test_python_dictionary.py<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u0430\u0440\u044b \u043a\u0435\u0439\u0441\u043e\u0432 (\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 &#8212;hypothesis-verbosity=debug):<\/p>\n<pre><code>Trying example: state = DictionaryTest() state.length_are_equal() v1 = state.add_element(key='Kv', value=86) state.length_are_equal() v2 = state.add_element(key='YecDWVUvWC', value=64) state.length_are_equal() v3 = state.add_element(key='AdHM', value=93) state.length_are_equal() v4 = state.add_element(key='SXz', value=50) state.length_are_equal() v5 = state.add_element(key='pHZMnSmadRbZfUAvJ', value=45) state.length_are_equal() state.teardown() Trying example: state = DictionaryTest() state.length_are_equal() v1 = state.add_element(key='bTRLj', value=43) state.length_are_equal() state.remove_element(key=v1) state.length_are_equal() v2 = state.add_element(key='TuSdbcM', value=42) state.length_are_equal() v3 = state.add_element(key='JshrNbJJ', value=72) state.length_are_equal() state.remove_element(key=v3) state.length_are_equal() state.teardown()<\/code><\/pre>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0432\u0438\u0434 \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"python\">import string  import hypothesis.strategies as st from hypothesis import settings from hypothesis.stateful import Bundle, RuleBasedStateMachine, rule, precondition, invariant, consumes   class DictionaryTest(RuleBasedStateMachine):     def __init__(self):         super().__init__()         self.dictionary_under_test = {}         self.ideal_dictionary = {}      keys = Bundle(\"keys\")      @rule(         target=keys,         key=st.text(alphabet=string.ascii_letters, min_size=1),         value=st.integers(min_value=0, max_value=100)     )     @precondition(lambda self: self.dictionary_under_test is not None)     def add_element(self, key: str, value: int) -> str:         self.dictionary_under_test[key] = value         self.ideal_dictionary[key] = value         return key      @rule(key=consumes(keys))     def remove_element(self, key: str):         assert self.dictionary_under_test.pop(key) == self.ideal_dictionary.pop(key)      @rule(key=keys)     def values_agree(self, key: str):         assert self.dictionary_under_test[key] == self.ideal_dictionary[key]      @invariant()     def length_are_equal(self):         assert len(self.dictionary_under_test) == len(self.ideal_dictionary)      def teardown(self):         self.dictionary_under_test = {}         self.ideal_dictionary = {}   DictionaryTest.TestCase.settings = settings(     max_examples=10, stateful_step_count=5 )  GoodTest = DictionaryTest.TestCase <\/code><\/pre>\n<p>\u0421\u0441\u044b\u043b\u043a\u0438:<br \/><a href=\"https:\/\/hypothesis.readthedocs.io\/en\/latest\/quickstart.html\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/hypothesis.readthedocs.io\/en\/latest\/quickstart.html<\/u><\/a><u><br \/><\/u><a href=\"https:\/\/hypothesis.works\/articles\/rule-based-stateful-testing\/\" rel=\"noopener noreferrer nofollow\">https:\/\/hypothesis.works\/articles\/rule-based-stateful-testing\/<\/a><br \/><a href=\"https:\/\/hypothesis.works\/articles\/how-not-to-die-hard-with-hypothesis\/\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/hypothesis.works\/articles\/how-not-to-die-hard-with-hypothesis\/<\/u><\/a><br \/><a href=\"https:\/\/hypothesis.readthedocs.io\/en\/latest\/stateful.html\" rel=\"noopener noreferrer nofollow\">https:\/\/hypothesis.readthedocs.io\/en\/latest\/stateful.html<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/744946\/\"> https:\/\/habr.com\/ru\/articles\/744946\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0415\u0441\u043b\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438 \u043e\u00a0hypothesis\u00a0\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b \u0447\u0435\u043c-\u0442\u043e \u043d\u043e\u0432\u044b\u043c \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0439\u0442\u0438 \u0431\u0430\u0433\u0438 \u0442\u0430\u043c, \u0433\u0434\u0435 \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u0443\u0436\u0435 \u0438\u0441\u043a\u0430\u043b\u0438 \u2013 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u044e.\u00a0<\/p>\n<h2>\u041e\u0447\u0435\u043d\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u043e \u0441\u0430\u043c\u043e\u043c\u00a0hypothesis<\/h2>\n<p>\u042d\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 (\u043d\u043e \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c) \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0445\u0438\u0442\u0440\u044b\u0435 \u0431\u0430\u0433\u0438. \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">from hypothesis import given, strategies as st   @given(st.integers(), st.integers()) def test_ints_are_commutative(x, y):     assert x + y == y + x<\/code><\/pre>\n<p><code>st.integers()<\/code> \u2013 \u044d\u0442\u043e \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u201c\u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u201d \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445\u00a0hypothesis, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432\u00a0<code>x<\/code>,\u00a0<code>y<\/code>\u00a0\u0431\u0443\u0434\u0443\u0442 \u0447\u0438\u0441\u043b\u0430. \u0410 \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u2013 \u0432\u044b\u0431\u0435\u0440\u0435\u0442 \u0441\u0430\u043c\u00a0hypothesis. \u0427\u0442\u043e\u0431\u044b \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u043a\u0435\u0439\u0441\u043e\u0432 \u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0432 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0447\u0438\u0441\u043b\u0430 \u043d\u0430\u0434\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u0422.\u0435. \u043c\u043e\u0436\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u0438\u043d\/\u043c\u0430\u043a\u0441 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">from hypothesis import given, strategies as st   @given(     st.integers(min_value=0, max_value=100),      st.integers(min_value=0, max_value=100) ) def test_ints_are_commutative(x: int, y: int):     assert x + y == y + x<\/code><\/pre>\n<p>\u041f\u043e \u043c\u0438\u043c\u043e \u0447\u0438\u0441\u0435\u043b, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e &#8212; \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0435\u0441\u0442\u044c \u043d\u0430 \u0432\u0441\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0436\u0438\u0437\u043d\u0438, \u043f\u0440\u0438\u043c\u0435\u0440\u044b <a href=\"https:\/\/hypothesis.readthedocs.io\/en\/latest\/data.html\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h2>\u041d\u043e \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u0442\u0435\u0441\u0442\u0430\u043c<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0438\u0445 \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438, \u0430 \u0432\u0441\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u2013 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438 \u0445\u043e\u0442\u0438\u043c \u0435\u0451 \u043f\u043e-\u0432\u0441\u044f\u043a\u043e\u043c\u0443 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041d\u0430\u0441 \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b &#8212; \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043b\u043e\u0432\u0430\u0440\u044f. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043a\u00a0hypothesis.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u0430\u044f \u0432\u0435\u0449\u044c \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c &#8212;\u00a0<a href=\"https:\/\/hypothesis.readthedocs.io\/en\/latest\/stateful.html#rule-based-state-machines\" rel=\"noopener noreferrer nofollow\">Rule-based\u00a0state\u00a0machine<\/a>. \u041f\u043e \u0441\u0443\u0442\u0438, \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044d\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443. \u041c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0430 \u0441\u0430\u043c\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0438\u043f\u0430\u00a0<code>Bundle<\/code>\u00a0\u0438 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439\u00a0<code>self<\/code>.\u00a0<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435. \u041d\u043e \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0438\u043f\u0430\u00a0<code>Bundle<\/code>\u00a0\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u0430 <code>@precondition<\/code>. \u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>@rule<\/code>:<\/p>\n<pre><code class=\"python\">keys = Bundle(\"keys\")  @rule(     target=keys,     key=st.text(alphabet=string.ascii_letters, min_size=1),     value=st.integers(min_value=0, max_value=100) ) @precondition(lambda self: self.dictionary_under_test is not None) def add_element(self, key, value):     self.dictionary_under_test[key] = value     self.ideal_dictionary[key] = value     return key<\/code><\/pre>\n<p>\u0423 <code>@rule<\/code>\u00a0\u0435\u0441\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2013\u00a0<code>target<\/code>, \u043e\u043d \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u043c-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u043a\u043b\u044e\u0447 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043a\u043b\u0430\u0441\u0441\u0430\u00a0<code>keys<\/code>. \u0414\u0432\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u2013\u00a0<code>key<\/code>\u00a0\u0438\u00a0<code>value<\/code>, \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0443\u0436\u0435 \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430. \u0418\u0445 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u043c\u0438\u00a0<code>text()<\/code> \u0438\u00a0<code>integers()<\/code>.\u00a0<\/p>\n<p>\u041f\u0440\u043e <code>@precondition<\/code>\u00a0&#8212; \u0432 \u043d\u0435\u043c \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f\u00a0<em>\u0434\u043e<\/em>\u00a0\u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434-\u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0432\u044b\u0437\u0432\u0430\u043d \u0438\u043b\u0438 \u043d\u0435\u0442. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2013 \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0430 \u043c\u044b \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442 \u2013 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.\u00a0<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0431\u0440\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0438\u043f\u0430\u00a0Bundle, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u00a0<code>consumes<\/code>:<\/p>\n<pre><code class=\"python\">@rule(key=consumes(keys)) def remove_element(self, key):     assert self.dictionary_under_test.pop(key) == self.ideal_dictionary.pop(key)<\/code><\/pre>\n<p>\u041a\u043b\u044e\u0447 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0<code>keys<\/code>. \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u2013 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439\u00a0<code>keys<\/code>. \u0415\u0441\u043b\u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0consumes\u00a0\u2013 \u043a\u043b\u044e\u0447 \u043d\u0435 \u0443\u0434\u0430\u043b\u0438\u0442\u0441\u044f \u0438 \u043c\u0435\u0442\u043e\u0434\u044b\u00a0<code>remove_element<\/code>\u00a0\u0438\u00a0<code>add_element<\/code>\u00a0\u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0441 \u0443\u0436\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c.\u00a0<\/p>\n<p>\u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u2013 <code>@invariant<\/code><\/p>\n<pre><code class=\"python\">@invariant() def length_are_equal(self):     assert len(self.dictionary_under_test) == len(self.ideal_dictionary)<\/code><\/pre>\n<p>\u041e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0434\u043e \u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432\u0441\u0435 \u0435\u0449\u0435 \u0432\u0435\u0440\u043d\u043e.\u00a0<\/p>\n<p>\u0418 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0432\u0430\u0436\u043d\u0430\u044f \u0432\u0435\u0449\u044c \u2013 \u043c\u0435\u0442\u043e\u0434\u00a0<code>teardown<\/code>:<\/p>\n<pre><code class=\"python\">def teardown(self):     self.dictionary_under_test = {}     self.ideal_dictionary = {} <\/code><\/pre>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u0435\u0439\u0441\u0430 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u0437\u0430 \u0441\u043e\u0431\u043e\u0439.<\/p>\n<p>\u041f\u043e \u043c\u0438\u043c\u043e \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e, \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0435\u0439\u0441\u043e\u0432 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043a\u0435\u0439\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u00a0hypothesis. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:<\/p>\n<pre><code class=\"python\">StorageSystemTest.TestCase.settings = settings(     max_examples=10, stateful_step_count=5 )<\/code><\/pre>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u043e \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"bash\">pytest -s --hypothesis-show-statistics --hypothesis-verbosity=debug test_python_dictionary.py<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u0430\u0440\u044b \u043a\u0435\u0439\u0441\u043e\u0432 (\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 &#8212;hypothesis-verbosity=debug):<\/p>\n<pre><code>Trying example: state = DictionaryTest() state.length_are_equal() v1 = state.add_element(key='Kv', value=86) state.length_are_equal() v2 = state.add_element(key='YecDWVUvWC', value=64) state.length_are_equal() v3 = state.add_element(key='AdHM', value=93) state.length_are_equal() v4 = state.add_element(key='SXz', value=50) state.length_are_equal() v5 = state.add_element(key='pHZMnSmadRbZfUAvJ', value=45) state.length_are_equal() state.teardown() Trying example: state = DictionaryTest() state.length_are_equal() v1 = state.add_element(key='bTRLj', value=43) state.length_are_equal() state.remove_element(key=v1) state.length_are_equal() v2 = state.add_element(key='TuSdbcM', value=42) state.length_are_equal() v3 = state.add_element(key='JshrNbJJ', value=72) state.length_are_equal() state.remove_element(key=v3) state.length_are_equal() state.teardown()<\/code><\/pre>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0432\u0438\u0434 \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"python\">import string  import hypothesis.strategies as st from hypothesis import settings from hypothesis.stateful import Bundle, RuleBasedStateMachine, rule, precondition, invariant, consumes   class DictionaryTest(RuleBasedStateMachine):     def __init__(self):         super().__init__()         self.dictionary_under_test = {}         self.ideal_dictionary = {}      keys = Bundle(\"keys\")      @rule(         target=keys,         key=st.text(alphabet=string.ascii_letters, min_size=1),         value=st.integers(min_value=0, max_value=100)     )     @precondition(lambda self: self.dictionary_under_test is not None)     def add_element(self, key: str, value: int) -> str:         self.dictionary_under_test[key] = value         self.ideal_dictionary[key] = value         return key      @rule(key=consumes(keys))     def remove_element(self, key: str):         assert self.dictionary_under_test.pop(key) == self.ideal_dictionary.pop(key)      @rule(key=keys)     def values_agree(self, key: str):         assert self.dictionary_under_test[key] == self.ideal_dictionary[key]      @invariant()     def length_are_equal(self):         assert len(self.dictionary_under_test) == len(self.ideal_dictionary)      def teardown(self):         self.dictionary_under_test = {}         self.ideal_dictionary = {}   DictionaryTest.TestCase.settings = settings(     max_examples=10, stateful_step_count=5 )  GoodTest = DictionaryTest.TestCase <\/code><\/pre>\n<p>\u0421\u0441\u044b\u043b\u043a\u0438:<br \/><a href=\"https:\/\/hypothesis.readthedocs.io\/en\/latest\/quickstart.html\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/hypothesis.readthedocs.io\/en\/latest\/quickstart.html<\/u><\/a><u><br \/><\/u><a href=\"https:\/\/hypothesis.works\/articles\/rule-based-stateful-testing\/\" rel=\"noopener noreferrer nofollow\">https:\/\/hypothesis.works\/articles\/rule-based-stateful-testing\/<\/a><br \/><a href=\"https:\/\/hypothesis.works\/articles\/how-not-to-die-hard-with-hypothesis\/\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/hypothesis.works\/articles\/how-not-to-die-hard-with-hypothesis\/<\/u><\/a><br \/><a href=\"https:\/\/hypothesis.readthedocs.io\/en\/latest\/stateful.html\" rel=\"noopener noreferrer nofollow\">https:\/\/hypothesis.readthedocs.io\/en\/latest\/stateful.html<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/744946\/\"> https:\/\/habr.com\/ru\/articles\/744946\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-349581","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/349581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=349581"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/349581\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=349581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=349581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=349581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}