예제 #1
0
def test_parser_errors():
    assert_raises(parser.ParserError, parser.parse_verb,
                  lexicon.scan("something go"))
    assert_raises(parser.ParserError, parser.parse_object,
                  lexicon.scan("something princess"))
    assert_raises(parser.ParserError, parser.parse_subject,
                  lexicon.scan("something south"), ('noun', 'princess'))
    #try:
    #    result = parser.parse_sentence( lexicon.scan("new princess go south") )
    #except parser.ParserError:
    #    return True
    # Use assert_raises for excception catching and comparison but takes Exception type, the callable
    # arguments
    assert_raises(parser.ParserError, parser.parse_sentence,
                  lexicon.scan("new princess go south"))
예제 #2
0
def test_directions():
    assert_equal(lexicon.scan('north'), [('direction', 'north')])
    result = lexicon.scan('north south east')
    assert_equal(result, [('direction', 'north'), ('direction', 'south'),
                          ('direction', 'east')])
예제 #3
0
def test_errors():
    assert_equal(lexicon.scan('ASDFADFASDF'), [('error', "ASDFADFASDF")])
    result = lexicon.scan('bear IAS princess')
    assert_equal(result, [('noun', 'bear'), ('error', 'IAS'),
                          ('noun', 'princess')])
예제 #4
0
def test_nouns():
    assert_equal(lexicon.scan('bear'), [('noun', 'bear')])
    result = lexicon.scan("3 91234")
    assert_equal(result, [('number', 3), ('number', 91234)])
예제 #5
0
def test_stops():
    assert_equal(lexicon.scan('the'), [('stop', 'the')])
    result = lexicon.scan('the in of')
    assert_equal(result, [('stop', 'the'), ('stop', 'in'), ('stop', 'of')])
예제 #6
0
def test_verbs():
    assert_equal(lexicon.scan('go'), [('verb', 'go')])
    result = lexicon.scan('go kill eat')
    assert_equal(result, [('verb', 'go'), ('verb', 'kill'), ('verb', 'eat')])
예제 #7
0
def test_parser_sentence():
    result = parser.parse_sentence(lexicon.scan("the princess go south"))
    expected = parser.Sentence(('noun', 'princess'), ('verb', 'go'),
                               ('direction', 'south'))
    assert_equal(result, expected)
예제 #8
0
def test_parser_subject():
    result = parser.parse_subject(lexicon.scan('go south'), ('noun', 'player'))
    assert_equal(
        result,
        parser.Sentence(('noun', 'player'), ('verb', 'go'),
                        ('direction', 'south')))
예제 #9
0
def test_parser_object():
    assert_equal(parser.parse_object(lexicon.scan('south')),
                 ('direction', 'south'))  # direction check
    assert_equal(parser.parse_object(lexicon.scan('princess')),
                 ('noun', 'princess'))  # noun check
예제 #10
0
def test_parser_verb():
    """test the parser for verb, object, subject then for sentence with subject start and verb start"""
    # single word sentence
    assert_equal(parser.parse_verb(lexicon.scan('go')),
                 ('verb', 'go'))  # verb test