Ejemplo n.º 1
0
    def test_apply_predicate(self):
        predicate = grammar.Predicate(True)
        Y = grammar.TypeExpression('Y')
        X = grammar.TypeExpression('X', fields=(Y, ))

        result = X._apply_predicate_(predicate)
        self.assertIsInstance(result, grammar.TypeExpression)
        self.assertEqual(result.fields, (Y, ))
Ejemplo n.º 2
0
    def test_hashable(self):
        a = grammar.TypeExpression('X')
        b = grammar.TypeExpression('Y', fields=(a, ))
        c = grammar.TypeExpression('Y', fields=(a, ))
        d = grammar.TypeExpression('Z', predicate=grammar.Predicate("stuff"))

        self.assertIsInstance(a, collections.Hashable)
        # There really shouldn't be a collision between these:
        self.assertNotEqual(hash(a), hash(d))

        self.assertEqual(b, c)
        self.assertEqual(hash(b), hash(c))
Ejemplo n.º 3
0
 def test_mod_w_none_predicate(self):
     X = grammar.TypeExpression('X', predicate=None)
     predicate = grammar.Predicate("Truthy")
     self.assertIs((X % predicate).predicate, predicate)
Ejemplo n.º 4
0
 def test_mod_w_existing_predicate(self):
     X = grammar.TypeExpression('X', predicate=grammar.Predicate('Truthy'))
     with self.assertRaisesRegex(TypeError, 'predicate'):
         X % grammar.Predicate('Other')
Ejemplo n.º 5
0
 def test_validate_predicate_w_valid(self):
     predicate = grammar.Predicate(True)
     X = grammar.TypeExpression('X')
     X._validate_predicate_(predicate)