예제 #1
0
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())
예제 #2
0
def test_Matcher_match_returns_True_when_no_raise():
    class DummyPyparsingThingy:
        def parseString(self, obj):
            pass

    m = Matcher("foo")
    assert m.match(DummyPyparsingThingy())
예제 #3
0
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())
예제 #4
0
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())
예제 #5
0
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
예제 #6
0
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)
예제 #7
0
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
예제 #8
0
파일: deaf.py 프로젝트: ViKingIX/grailmud
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)
예제 #9
0
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
예제 #10
0
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
예제 #11
0
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)
예제 #12
0
파일: look.py 프로젝트: ViKingIX/grailmud
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)
예제 #13
0
파일: says.py 프로젝트: ViKingIX/grailmud
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.")
예제 #14
0
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.")
예제 #15
0
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)
예제 #16
0
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)
예제 #17
0
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())
예제 #18
0
def test_Matcher_results_is_None_default():
    assert Matcher('').results is None
예제 #19
0
def test_Matcher_match_returns_True_when_no_raise():
    class DummyPyparsingThingy:
        def parseString(self, obj):
            pass
    m = Matcher("foo")
    assert m.match(DummyPyparsingThingy())