Exemple #1
0
    def test_bound_descriptor_proxies_to_xq_descriptor(self):
        descriptor = unittest.mock.Mock()

        bd = xso_query.BoundDescriptor(
            unittest.mock.sentinel.class_,
            descriptor,
            unittest.mock.sentinel.expr_class,
        )

        self.assertEqual(bd.foo, descriptor.foo)

        descriptor.foo = "fnord"

        self.assertEqual(bd.foo, descriptor.foo)

        del descriptor.foo

        with self.assertRaises(AttributeError):
            bd.foo
Exemple #2
0
    def test_xq_instantiate_with_extra_args(self):
        expr = unittest.mock.sentinel.expr
        class_ = unittest.mock.Mock()
        expr_class = unittest.mock.Mock()

        bd = xso_query.BoundDescriptor(
            class_,
            unittest.mock.sentinel.descriptor,
            expr_class,
            expr_kwargs={"mapping_type": unittest.mock.sentinel.mt})

        result = bd.xq_instantiate(expr)

        class_.xq_instantiate.assert_called_with(expr)

        expr_class.assert_called_with(class_.xq_instantiate(),
                                      unittest.mock.sentinel.descriptor,
                                      mapping_type=unittest.mock.sentinel.mt)

        self.assertEqual(result, expr_class())
Exemple #3
0
    def test_init(self):
        bd = xso_query.BoundDescriptor(
            unittest.mock.sentinel.class_,
            unittest.mock.sentinel.descriptor,
            unittest.mock.sentinel.expr_class,
        )

        self.assertEqual(
            bd.xq_xso_class,
            unittest.mock.sentinel.class_,
        )

        self.assertEqual(
            bd.xq_descriptor,
            unittest.mock.sentinel.descriptor,
        )
        self.assertEqual(
            bd.xq_expr_class,
            unittest.mock.sentinel.expr_class,
        )
Exemple #4
0
    def test_xq_instantiate(self):
        expr = unittest.mock.sentinel.expr
        class_ = unittest.mock.Mock()
        expr_class = unittest.mock.Mock()

        bd = xso_query.BoundDescriptor(
            class_,
            unittest.mock.sentinel.descriptor,
            expr_class,
        )

        result = bd.xq_instantiate(expr)

        class_.xq_instantiate.assert_called_with(expr)

        expr_class.assert_called_with(
            class_.xq_instantiate(),
            unittest.mock.sentinel.descriptor,
        )

        self.assertEqual(result, expr_class())
Exemple #5
0
    def test_as_expr_recursively_resolves_lhses(self):
        new_lhs = unittest.mock.sentinel.new_lhs

        cls = xso_query.Class()
        descriptor = xso_query.BoundDescriptor(
            cls,
            unittest.mock.sentinel.descriptor,
            xso_query.GetDescriptor,
        )

        result = xso_query.as_expr(descriptor, lhs=new_lhs)

        self.assertIsInstance(
            result,
            xso_query.GetDescriptor,
        )

        self.assertEqual(
            result.descriptor,
            unittest.mock.sentinel.descriptor,
        )

        self.assertIsInstance(
            result.expr,
            xso_query.GetInstances,
        )

        self.assertEqual(
            result.expr.class_,
            cls,
        )

        self.assertEqual(
            result.expr.expr,
            new_lhs,
        )