示例#1
0
    def test_owner(self):
        expr2 = Expression('test', 'fish', op=OP_SUB)
        expr1 = Expression(1, 2, expr2, op=OP_ADD)
        mock_owner = MockOwner()

        expr1.owner = mock_owner
        self.assertEqual(id(expr1._owner_ref()), id(expr2._owner_ref()))
示例#2
0
    def test_copy(self):
        expr = Expression(1, 2, 3, Expression(1, 3, 4), op=OP_SUB)
        mock_owner = MockOwner()
        expr.owner = mock_owner
        expr_copy = copy.copy(expr)

        self.assertNotEqual(id(expr), id(expr_copy))
        self.assertNotEqual(id(expr._tokens), id(expr_copy._tokens))
        self.assertEqual(
            [id(t) for t in expr._tokens],
            [id(t) for t in expr_copy._tokens])
        self.assertEqual(expr.alias, expr_copy.alias)
        self.assertEqual(id(expr._owner_ref()), id(expr_copy._owner_ref()))
示例#3
0
    def test_hash(self):
        expr1 = Expression(1, 2, op=OP_ADD)
        expr2 = Expression(1, 2, op=OP_ADD)
        expr3 = Expression(1, 2, op=OP_SUB)

        mock_owner1 = MockOwner(hash_value=3)
        mock_owner2 = MockOwner(hash_value=2)

        self.assertEqual(hash(expr1), hash(expr2))
        self.assertNotEqual(hash(expr1), hash(expr3))

        expr1.owner = mock_owner1
        expr2.owner = mock_owner1

        self.assertEqual(hash(expr1), hash(expr2))

        expr2.owner = mock_owner2
        self.assertNotEqual(hash(expr1), hash(expr2))