Example #1
0
    def test_update_values_appends(self):
        v = unittest.mock.Mock()
        vnew = unittest.mock.Mock()

        gd = xso_query.GetDescriptor(
            unittest.mock.sentinel.expr,
            unittest.mock.sentinel.descriptor,
        )

        gd.update_values(v, vnew)

        v.append.assert_called_with(vnew)
Example #2
0
    def test_eval_gets_descriptor(self):
        class Bar:
            pass

        i1 = Bar()
        i2 = Bar()

        def values():
            yield unittest.mock.sentinel.v1
            yield unittest.mock.sentinel.v2

        descriptor = unittest.mock.PropertyMock()
        descriptor.side_effect = values()

        expr = unittest.mock.Mock()
        ec = unittest.mock.sentinel

        expr.eval.return_value = [
            i1,
            i2,
        ]

        gd = xso_query.GetDescriptor(expr, descriptor)

        with contextlib.ExitStack() as stack:
            new_values = stack.enter_context(
                unittest.mock.patch.object(gd, "new_values"))

            update_values = stack.enter_context(
                unittest.mock.patch.object(gd, "update_values"))

            new_values.return_value = unittest.mock.sentinel.vs

            result = gd.eval(ec)

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

        self.assertSequenceEqual(update_values.mock_calls, [
            unittest.mock.call(
                unittest.mock.sentinel.vs,
                unittest.mock.sentinel.v1,
            ),
            unittest.mock.call(
                unittest.mock.sentinel.vs,
                unittest.mock.sentinel.v2,
            ),
        ])

        expr.eval.assert_called_with(ec)
Example #3
0
    def test_new_values_creates_empty_sequence(self):
        gd = xso_query.GetDescriptor(
            unittest.mock.sentinel.expr,
            unittest.mock.sentinel.descriptor,
        )

        s1 = gd.new_values()
        s2 = gd.new_values()

        self.assertSequenceEqual(s1, [])

        self.assertSequenceEqual(s2, [])

        self.assertIsNot(s1, s2)