<s> """<STR_LIT>""" <EOL> from hamcrest . core import anything <EOL> from hamcrest . core . base_matcher import BaseMatcher <EOL> from hamcrest . core . helpers . wrap_matcher import wrap_matcher <EOL> from pyherc . data import get_items <EOL> class ContainsItem ( BaseMatcher ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , item , amount ) : <EOL> """<STR_LIT>""" <EOL> super ( ) . __init__ ( ) <EOL> self . item = item <EOL> self . amount = amount <EOL> def _matches ( self , item ) : <EOL> """<STR_LIT>""" <EOL> count = <NUM_LIT:0> <EOL> for item in get_items ( item ) : <EOL> if item . name == self . item : <EOL> count = count + <NUM_LIT:1> <EOL> return self . amount . matches ( count ) <EOL> def describe_to ( self , description ) : <EOL> """<STR_LIT>""" <EOL> if self . amount is None : <EOL> description . append ( '<STR_LIT>' <EOL> . format ( self . item ) ) <EOL> else : <EOL> description . append ( '<STR_LIT>' <EOL> . format ( self . amount , self . item ) ) <EOL> def describe_mismatch ( self , item , mismatch_description ) : <EOL> """<STR_LIT>""" <EOL> names = [ x . name for x in item . items ] <EOL> mismatch_description . append ( '<STR_LIT>' <EOL> . format ( names ) ) <EOL> class HasDamage ( BaseMatcher ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , damage_amount , damage_type ) : <EOL> """<STR_LIT>""" <EOL> super ( ) . __init__ ( ) <EOL> self . damage_amount = damage_amount <EOL> self . damage_type = damage_type <EOL> def _matches ( self , item ) : <EOL> """<STR_LIT>""" <EOL> for damage in item . weapon_data . damage : <EOL> if not self . damage_amount . _matches ( damage [ <NUM_LIT:0> ] ) : <EOL> return False <EOL> if not self . damage_type . _matches ( damage [ <NUM_LIT:1> ] ) : <EOL> return False <EOL> return True <EOL> def describe_to ( self , description ) : <EOL> """<STR_LIT>""" <EOL> description . append ( '<STR_LIT>' ) <EOL> self . damage_amount . describe_to ( description ) <EOL> description . append ( '<STR_LIT>' ) <EOL> self . damage_type . describe_to ( description ) <EOL> description . append ( '<STR_LIT>' ) <EOL> def describe_mismatch ( self , item , mismatch_description ) : <EOL> """<STR_LIT>""" <EOL> mismatch_description . append ( '<STR_LIT>' <EOL> . format ( item . weapon_data . damage ) ) <EOL> def does_have_item ( item , amount = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> return ContainsItem ( item , wrap_matcher ( amount ) ) <EOL> def does_not_have_item ( item ) : <EOL> """<STR_LIT>""" <EOL> return ContainsItem ( item , wrap_matcher ( <NUM_LIT:0> ) ) <EOL> def has_damage ( damage_amount = None , damage_type = None ) : <EOL> """<STR_LIT>""" <EOL> if damage_amount is not None and damage_type is not None : <EOL> return HasDamage ( wrap_matcher ( damage_amount ) , <EOL> wrap_matcher ( damage_type ) ) <EOL> elif damage_amount is None : <EOL> return HasDamage ( anything ( ) , wrap_matcher ( damage_type ) ) <EOL> else : <EOL> return HasDamage ( wrap_matcher ( damage_amount ) , anything ( ) ) </s>
