def test_Matcher_match_returns_False_on_ParseException(): class DummyPyparsingThingy: def parseString(self, obj): raise ParseException(None, None, None) m = Matcher("foo") assert not m.match(DummyPyparsingThingy())
def test_Matcher_match_returns_True_when_no_raise(): class DummyPyparsingThingy: def parseString(self, obj): pass m = Matcher("foo") assert m.match(DummyPyparsingThingy())
def test_Matcher_passes_same_argument_to_matches(): class DummyPyparsingThingy: def parseString(self, obj): assert obj is sentinel sentinel = object() m = Matcher(sentinel) m.match(DummyPyparsingThingy())
def test_Matcher_match_sets_result_on_success(): sentinel = object() class DummyPyparsingThingy: def parseString(self, obj): return sentinel m = Matcher("foo") m.match(DummyPyparsingThingy()) assert m.results is sentinel
def deafDistributor(actor, rest, lineinfo): matcher = Matcher(rest.lower()) if matcher.match(on_pattern): deafOn(actor) elif matcher.match(off_pattern): deafOff(actor) else: badSyntax(actor, syntaxmessage)
def test_Matcher_match_doesnt_touch_results_on_failure(): class DummyPyparsingThingy: def parseString(self, obj): raise ParseException(None, None, None) sentinel = object() m = Matcher("foo") m.results = sentinel m.match(DummyPyparsingThingy()) assert m.results is sentinel
def lookDistributor(actor, text, info): matcher = Matcher(text) if matcher.match(lookAtPattern): blob, = matcher.results try: target = get_from_rooms(blob, [actor.inventory, actor.room], info) except UnfoundError: unfoundObject(actor) else: lookAt(actor, target) else: lookRoom(actor)
def speakToWrapper(actor, text, info): matcher = Matcher(text) if matcher.match(speakToPattern): blob, saying = matcher.results try: target = get_from_rooms(blob, [actor.inventory, actor.room], info) except UnfoundError: unfoundObject(actor) else: speakTo(actor, target, saying) else: badSyntax(actor, "Can't find the end of the target identifier. Use " "',' at its end to specify it.")
def speakToWrapper(actor, text, info): matcher = Matcher(text) if matcher.match(speakToPattern): blob, saying = matcher.results try: target = get_from_rooms(blob, [actor.inventory, actor.room], info) except UnfoundError: unfoundObject(actor) else: speakTo(actor, target, saying) else: badSyntax( actor, "Can't find the end of the target identifier. Use " "',' at its end to specify it.")
def targetDistributor(actor, text, info): if info.instigator is not actor: permissionDenied(info.instigator) return matcher = Matcher(text) if matcher.match(target_set_pattern): (name, ), blob = matcher.results try: target = get_from_rooms(blob, [actor.inventory, actor.room], info) except UnfoundError: unfoundObject(actor) else: targetSet(actor, name.lower(), target) elif matcher.match(target_clear_pattern): (name, ), = matcher.results targetClear(actor, name.lower()) elif matcher.match(target_list_pattern): targetList(actor) else: badSyntax(actor)
def targetDistributor(actor, text, info): if info.instigator is not actor: permissionDenied(info.instigator) return matcher = Matcher(text) if matcher.match(target_set_pattern): (name,), blob = matcher.results try: target = get_from_rooms(blob, [actor.inventory, actor.room], info) except UnfoundError: unfoundObject(actor) else: targetSet(actor, name.lower(), target) elif matcher.match(target_clear_pattern): (name,), = matcher.results targetClear(actor, name.lower()) elif matcher.match(target_list_pattern): targetList(actor) else: badSyntax(actor)
def test_Matcher_results_is_None_default(): assert Matcher('').results is None