Пример #1
0
 def test_it_evaluates_hook_with_weakref_for_node_values(self):
     node = parsing.Node()
     parser = mock.Mock(spec=parsing.BasicParser,
                        **{'rule_nodes': {
                            'hooknode': node
                        }})
     hook = parsing.Hook('hook', [('hooknode', parsing.Node)])
     hook(parser)
     parser.eval_hook.assert_called_once_with('hook', [node])
Пример #2
0
 def test_it_wraps_boolean_result_in_node(self):
     res = mock.Mock()
     parser = mock.Mock(rule_nodes=collections.ChainMap(),
                        **{'get_tag.return_value': res})
     clause = mock.Mock(return_value=True)
     capture = parsing.Capture('tagname', clause)
     expected_res = parsing.Node(True)
     expected_res.value = res
     self.assertEqual(capture(parser), expected_res)
     clause.assert_called_once_with(parser)
Пример #3
0
 def test_000_Node(self):
     d = parsing.Node()
     d.tata = [1, 2, 3, 4, 5]
     d["chuchu"] = 'bla'
     d['papa'] = d
     ndict = {}
     res = d.check(ndict)
     out = ""
     for k, v in ndict.items():
         out += "[%s]=%s\n" % (k, v)
     self.assertTrue(res, "Failed detect recursive node:\n%s" % out)
     d = parsing.Node()
     d.tata = [1, 2, 3, 4, 5]
     d["chuchu"] = 'bla'
     ndict = {}
     res = d.check(ndict)
     out = ""
     for k, v in ndict.items():
         out += "[%s]=%s\n" % (k, v)
     self.assertFalse(res, "Failed detect recursive node:\n%s" % out)
Пример #4
0
 def dummy(self):
     res = parsing.Node()
     res.text = "cool"
     self.rule_nodes["_"] = res
     return True
Пример #5
0
 def test_it_is_true_when_initialized_with_true(self):
     node = parsing.Node(True)
     self.assertTrue(node)
Пример #6
0
 def test_it_raises_typeerror_when_initialized_with_badtype(self):
     with self.assertRaises(TypeError):
         parsing.Node(0)
Пример #7
0
 def test_it_is_false_when_initialized_with_false_node(self):
     node = parsing.Node(parsing.Node(False))
     self.assertFalse(node)