Exemplo n.º 1
0
    def test_parse_module(self):
        groups = (('a = b c = d END',
                   PVLModule(a='b',
                             c='d')), ('a =b GROUP = g f=g END_GROUP END',
                                       PVLModule(a='b', g=PVLGroup(f='g'))),
                  ('GROUP = g f=g END_GROUP END',
                   PVLModule(g=PVLGroup(f='g'))),
                  ('GROUP = g f=g END_GROUP a = b OBJECT = o END_OBJECT END',
                   PVLModule(g=PVLGroup(f='g'), a='b', o=PVLObject())))
        for g in groups:
            with self.subTest(groups=g):
                tokens = Lexer(g[0])
                self.assertEqual(g[1], self.p.parse_module(tokens))

        tokens = Lexer('blob')
        self.assertRaises(ParseError, self.p.parse_module, tokens)

        tokens = Lexer('blob =')
        self.assertRaises(ParseError, self.p.parse_module, tokens)

        tokens = Lexer('GROUP GROUP')
        self.assertRaises(LexerError, self.p.parse_module, tokens)

        tokens = Lexer('BEGIN_OBJECT = foo END_OBJECT = bar')
        self.assertRaises(ValueError, self.p.parse_module, tokens)

        tokens = Lexer(""" mixed = 'mixed"\\'quotes'
                           number = '123' """)
        self.assertRaises(LexerError, self.p.parse_module, tokens)
Exemplo n.º 2
0
    def test_parse_module(self):
        groups = (
            ("a = b c = d END", PVLModule(a="b", c="d")),
            (
                "a =b GROUP = g f=g END_GROUP END",
                PVLModule(a="b", g=PVLGroup(f="g")),
            ),
            ("GROUP = g f=g END_GROUP END", PVLModule(g=PVLGroup(f="g"))),
            (
                "GROUP = g f=g END_GROUP a = b OBJECT = o END_OBJECT END",
                PVLModule(g=PVLGroup(f="g"), a="b", o=PVLObject()),
            ),
        )
        for g in groups:
            with self.subTest(groups=g):
                tokens = Lexer(g[0])
                self.assertEqual(g[1], self.p.parse_module(tokens))

        tokens = Lexer("blob")
        self.assertRaises(ParseError, self.p.parse_module, tokens)

        tokens = Lexer("blob =")
        self.assertRaises(ParseError, self.p.parse_module, tokens)

        tokens = Lexer("GROUP GROUP")
        self.assertRaises(LexerError, self.p.parse_module, tokens)

        tokens = Lexer("BEGIN_OBJECT = foo END_OBJECT = bar")
        self.assertRaises(ValueError, self.p.parse_module, tokens)

        tokens = Lexer(""" mixed = 'mixed"\\'quotes'
                           number = '123' """)
        self.assertRaises(LexerError, self.p.parse_module, tokens)
Exemplo n.º 3
0
    def test_parse_aggregation_block(self):
        groups = (
            (
                "GROUP = name bob = uncle END_GROUP",
                ("name", PVLGroup(bob="uncle")),
            ),
            (
                "GROUP = name OBJECT = uncle name = bob END_OBJECT END_GROUP",
                ("name", PVLGroup(uncle=PVLObject(name="bob"))),
            ),
            (
                "GROUP = name bob = uncle END_GROUP = name next = token",
                ("name", PVLGroup(bob="uncle")),
            ),
        )
        for g in groups:
            with self.subTest(groups=g):
                tokens = Lexer(g[0])
                self.assertEqual(g[1], self.p.parse_aggregation_block(tokens))

        bad_blocks = (
            "Group = name bob = uncle END_OBJECT",
            "GROUP= name = bob = uncle END_GROUP",
            "",
        )
        for b in bad_blocks:
            with self.subTest(block=b):
                tokens = Lexer(b)
                self.assertRaises(ValueError, self.p.parse_aggregation_block,
                                  tokens)
Exemplo n.º 4
0
    def test_parse(self):
        groups = (('a = b c = d END',
                   PVLModule(a='b',
                             c='d')), ('a =b GROUP = g f=g END_GROUP END',
                                       PVLModule(a='b', g=PVLGroup(f='g'))),
                  ('GROUP = g f=g END_GROUP END',
                   PVLModule(g=PVLGroup(f='g'))),
                  ('GROUP = g f=g END_GROUP a = b OBJECT = o END_OBJECT END',
                   PVLModule(g=PVLGroup(f='g'), a='b', o=PVLObject())))
        for g in groups:
            with self.subTest(groups=g):
                self.assertEqual(g[1], self.p.parse(g[0]))

        self.assertRaises(ParseError, self.p.parse, 'blob')
Exemplo n.º 5
0
    def test_parse(self):
        groups = (
            ("a = b c = d END", PVLModule(a="b", c="d")),
            (
                "a =b GROUP = g f=g END_GROUP END",
                PVLModule(a="b", g=PVLGroup(f="g")),
            ),
            ("GROUP = g f=g END_GROUP END", PVLModule(g=PVLGroup(f="g"))),
            (
                "GROUP = g f=g END_GROUP a = b OBJECT = o END_OBJECT END",
                PVLModule(g=PVLGroup(f="g"), a="b", o=PVLObject()),
            ),
        )
        for g in groups:
            with self.subTest(groups=g):
                self.assertEqual(g[1], self.p.parse(g[0]))

        self.assertRaises(ParseError, self.p.parse, "blob")
Exemplo n.º 6
0
    def test_parse_aggregation_block(self):
        groups = (
            ('GROUP = name bob = uncle END_GROUP', ('name',
                                                    PVLGroup(bob='uncle'))),
            ('GROUP = name OBJECT = uncle name = bob END_OBJECT END_GROUP',
             ('name', PVLGroup(uncle=PVLObject(name='bob')))),
            ('GROUP = name bob = uncle END_GROUP = name next = token',
             ('name', PVLGroup(bob='uncle'))))
        for g in groups:
            with self.subTest(groups=g):
                tokens = Lexer(g[0])
                self.assertEqual(g[1], self.p.parse_aggregation_block(tokens))

        bad_blocks = ('Group = name bob = uncle END_OBJECT',
                      'GROUP= name = bob = uncle END_GROUP', '')
        for b in bad_blocks:
            with self.subTest(block=b):
                tokens = Lexer(b)
                self.assertRaises(ValueError, self.p.parse_aggregation_block,
                                  tokens)
Exemplo n.º 7
0
 def test_convert_grp_to_obj(self):
     g = PVLGroup(a="b", c="d")
     o = PVLObject(a="b", c="d")
     converted = PVLObject(g)
     self.assertEqual(o, converted)
     self.assertIsInstance(converted, PVLObject)
Exemplo n.º 8
0
 def test_count_aggs(self):
     m = PVLModule(a=PVLGroup(), b=PVLObject(), c=PVLObject())
     self.assertEqual((2, 1), self.e.count_aggs(m))