evddlmZmZmZmZmZddlmZddlm Z ddl m Z ddl m Z ddlmZddlmZddlmZdd lmZd Zd Zd Zed ZGdde eZddededeeefdeefdZedeeeefdeefdZedeeeeeeffdeefdZededeefdZdZy))AnyMappingTypeVarUnionoverload) described_as)anything) BaseMatcher)AllOf) Description) wrap_matcher)Matcher)StringDescriptionz Chris RosezCopyright 2011 hamcrest.orgzBSD, see License.txtVc`eZdZdedeeddfdZdedefdZ de ddfd Z ded e ddfd Z d Z y) IsObjectWithProperty property_name value_matcherreturnNc ||_||_yN)rr)selfrrs E/usr/lib/python3/dist-packages/hamcrest/library/object/hasproperty.py__init__zIsObjectWithProperty.__init__s**itemc|yt||jsyt||j}|jj |S)NF)hasattrrgetattrrmatches)rrvalues r_matcheszIsObjectWithProperty._matchessF <tT//0d001!!))%00r descriptionc|jdj|jjdj|jy)Nzan object with a property 'z ' matching ) append_textrappend_description_ofr)rr#s r describe_toz IsObjectWithProperty.describe_to"s@ =>JJ    +m $%:%:4;M;M%Nrmismatch_descriptionc||jdyt||jsI|j|jdj|jjdy|jdj|jjdt ||j}|j j ||y)Nzwas Nonez did not have the z propertyz property  )r%rrr&rrdescribe_mismatch)rrr(r!s rr+z&IsObjectWithProperty.describe_mismatch's < , ,Z 8 tT//0 6 6t < H H$ ##D$6$67 K8P ((5KK    +c d001 ,,U4HIrcNt}|j|t|Sr)rr'str)rds r__str__zIsObjectWithProperty.__str__8s!   1v r)__name__ __module__ __qualname__r-rrrobjectboolr"r r'r+r/rrrrsm+c+'!*++1V11O{OtO JfJKJTXJ"rrNnamematchrcD| t}t|t|S)aMatches if object has a property with a given name whose value satisfies a given matcher. :param name: The name of the property. :param match: Optional matcher to satisfy. This matcher determines if the evaluated object has a property with a given name. If no such property is found, ``has_property`` is not satisfied. If the property is found, its value is passed to a given matcher for evaluation. If the ``match`` argument is not a matcher, it is implicitly wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher to check for equality. If the ``match`` argument is not provided, the :py:func:`~hamcrest.core.core.isanything.anything` matcher is used so that ``has_property`` is satisfied if a matching property is found. Examples:: has_property('name', starts_with('J')) has_property('name', 'Jon') has_property('name') )r r wrap_shortcut)r6r7s r has_propertyr:>s"6 }  mE&: ;;rkeys_valuematchersc yrr5r;s rhas_propertiesr>`rcyrr5r=s rr>r>fr?rcyrr5r=s rr>r>lr?rc t|dk(r- |dj}|D]}t||||<n]t|dzr t di}t t t|dz D]}t|d|zdz||d|z<!|jD]\}}t|||<t|dkDrtjd}tt|jD]Z\}\}} |j|jdj| |t|dz ksJ|jd\tt|tt|jD cgc]\}} t!|| c} }d d d S|j#\}} t!|| S#t$r t dwxYwcc} }w) aXMatches if an object has properties satisfying all of a dictionary of string property names and corresponding value matchers. :param matcher_dict: A dictionary mapping keys to associated value matchers, or to expected values for :py:func:`~hamcrest.core.core.isequal.equal_to` matching. Note that the keys must be actual keys, not matchers. Any value argument that is not a matcher is implicitly wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher to check for equality. Examples:: has_properties({'foo':equal_to(1), 'bar':equal_to(2)}) has_properties({'foo':1, 'bar':2}) ``has_properties`` also accepts a list of keyword arguments: .. function:: has_properties(keyword1=value_matcher1[, keyword2=value_matcher2[, ...]]) :param keyword1: A keyword to look up. :param valueMatcher1: The matcher to satisfy for the value, or an expected value for :py:func:`~hamcrest.core.core.isequal.equal_to` matching. Examples:: has_properties(foo=equal_to(1), bar=equal_to(2)) has_properties(foo=1, bar=2) Finally, ``has_properties`` also accepts a list of alternating keys and their value matchers: .. function:: has_properties(key1, value_matcher1[, ...]) :param key1: A key (not a matcher) to look up. :param valueMatcher1: The matcher to satisfy for the value, or an expected value for :py:func:`~hamcrest.core.core.isequal.equal_to` matching. Examples:: has_properties('foo', equal_to(1), 'bar', equal_to(2)) has_properties('foo', 1, 'bar', 2) rzHsingle-argument calls to has_properties must pass a dict as the argumentz'has_properties requires key-value pairszan object with properties z matching z and TF)describe_all_mismatchesdescribe_matcher_in_mismatch)lencopyr9AttributeError ValueErrorrangeintitemsrr% enumeratesortedr&rr-r r:popitem) r;kv_args base_dictkeyindexr!r#irproperty_value_matchers rr>r>qs\ !# *1-224I  ?!.y~!> # ? ! "Q &FG G 3s#56:;< E7D"1u9q=18I(U3 4  mmo. U&u- #. 9~')556RS :CF9??K\D]:^ 1 6A6 5  - -m < H H ##$:;3y>A%%''0  1   BH HYAZ= '=!0FG)--2    1:0A0A0C- -M+ABBM Z  8s+GG/G,r) typingrrrrrhamcrestr hamcrest.corer hamcrest.core.base_matcherr hamcrest.core.core.allofr hamcrest.core.descriptionr "hamcrest.core.helpers.wrap_matcherr r9hamcrest.core.matcherr hamcrest.core.string_descriptionr __author__ __copyright__ __license__rr3rr-r:r>r5rrrcs99!"2*1L)>  - $  CL(;v.(V