Exemple #1
0
def test_level_parser_properties():
    parser = LevelParser()
    assert parser.levels == 1
    assert parser.parsers == [Parser()]

    with pytest.raises(ValueError):
        parser.levels = 0
    with pytest.raises(ValueError):
        parser.levels = -1
    assert parser.levels == 1

    parser.levels = 2
    assert parser.parsers == [Parser(), Parser()]

    level = Parser(state_sizes=[2, 3])
    parser.parsers = level
    assert parser.parsers == [level, level]

    parser.parsers = [Parser(), level, Parser()]
    assert parser.parsers == [Parser(), level]

    parser.levels = 1
    assert parser.parsers == [Parser()]

    parser.levels = 2
    assert parser.parsers[1] is level
Exemple #2
0
    def test_properties(self):
        parser = LevelParser()
        self.assertEqual(parser.levels, 1)
        self.assertEqual(parser.parsers, [Parser()])

        with self.assertRaises(ValueError):
            parser.levels = 0
        with self.assertRaises(ValueError):
            parser.levels = -1
        self.assertEqual(parser.levels, 1)

        parser.levels = 2
        self.assertEqual(parser.parsers, [Parser(), Parser()])

        level = Parser(state_sizes=[2, 3])
        parser.parsers = level
        self.assertEqual(parser.parsers, [level, level])

        parser.parsers = [Parser(), level, Parser()]
        self.assertEqual(parser.parsers, [Parser(), level])

        parser.levels = 1
        self.assertEqual(parser.parsers, [Parser()])

        parser.levels = 2
        self.assertIs(parser.parsers[1], level)