o (]^@sHddlmZmZmZmZmZddlmZddlm Z ddl m Z ddl m Z ddlmZddlmZddlmZdd lmZd Zd Zd Zed ZGddde eZddededeeefdeefddZedeeeefdeefddZedeeeeeeffdeefddZededeefddZddZdS))AnyMappingTypeVarUnionoverload) described_as)anything) BaseMatcher)AllOf) Description) wrap_matcher)Matcher)StringDescriptionz Chris RosezCopyright 2011 hamcrest.orgzBSD, see License.txtVc@sheZdZdedeeddfddZdedefdd Z d e ddfd d Z ded e ddfddZ ddZ dS)IsObjectWithProperty property_name value_matcherreturnNcCs||_||_dSN)rr)selfrrrE/usr/lib/python3/dist-packages/hamcrest/library/object/hasproperty.py__init__s zIsObjectWithProperty.__init__itemcCs4|durdSt||jsdSt||j}|j|S)NF)hasattrrgetattrrmatches)rrvaluerrr_matchess    zIsObjectWithProperty._matches descriptioncCs$|d|jd|jdS)Nzan object with a property 'z ' matching ) append_textrappend_description_ofr)rrrrr describe_to"s z IsObjectWithProperty.describe_tomismatch_descriptioncCsz|dur |ddSt||js"||d|jddS|d|jdt||j}|j||dS)Nzwas Nonez did not have the z propertyz property  )r rrr!rrdescribe_mismatch)rrr#rrrrr%'s     z&IsObjectWithProperty.describe_mismatchcCst}||t|Sr)rr"str)rdrrr__str__8s zIsObjectWithProperty.__str__)__name__ __module__ __qualname__r&r rrobjectboolrr r"r%r(rrrrrs   rNnamematchrcCs|durt}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') N)rr wrap_shortcut)r.r/rrr has_property>sr1keys_valuematcherscKdSrrr2rrrhas_properties`r5cCr3rrr4rrrr5fr6cGr3rrr4rrrr5lr6c Osft|dkr'z|d}|D] }t||||<qWn4ty&tdwt|dr1tdi}ttt|dD]}t|d|d||d|<q=|D] \}}t|||<qTt|dkrt d}t t |D]\}\}} | | d | |t|dkr| dqst t|td d t |Dd d d S|\}} t|| S)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 cSsg|] \}}t||qSr)r1).0rproperty_value_matcherrrr sz"has_properties..TF)describe_all_mismatchesdescribe_matcher_in_mismatch)lencopyr0AttributeError ValueErrorrangeintitemsrr enumeratesortedr!rr&r popitemr1) r2kv_args base_dictkeyindexrrirr:rrrr5qsT .         r) typingrrrrrhamcrestr hamcrest.corerhamcrest.core.base_matcherr hamcrest.core.core.allofr hamcrest.core.descriptionr "hamcrest.core.helpers.wrap_matcherr r0hamcrest.core.matcherr hamcrest.core.string_descriptionr __author__ __copyright__ __license__rr,rr&r1r5rrrrs,        *+"$,