Esempio n. 1
0
    def test_maybe_evaluate(self):
        x = PromiseProxy(lambda: 30)
        assert not x.__evaluated__()
        assert maybe_evaluate(x) == 30
        assert maybe_evaluate(x) == 30

        assert maybe_evaluate(30) == 30
        assert x.__evaluated__()
Esempio n. 2
0
    def test_maybe_evaluate(self):
        x = PromiseProxy(lambda: 30)
        self.assertFalse(x.__evaluated__())
        self.assertEqual(maybe_evaluate(x), 30)
        self.assertEqual(maybe_evaluate(x), 30)

        self.assertEqual(maybe_evaluate(30), 30)
        self.assertTrue(x.__evaluated__())
Esempio n. 3
0
    def test_maybe_evaluate(self):
        x = PromiseProxy(lambda: 30)
        self.assertFalse(x.__evaluated__())
        self.assertEqual(maybe_evaluate(x), 30)
        self.assertEqual(maybe_evaluate(x), 30)

        self.assertEqual(maybe_evaluate(30), 30)
        self.assertTrue(x.__evaluated__())
Esempio n. 4
0
    def test_maybe_evaluate(self):
        x = PromiseProxy(lambda: 30)
        assert not x.__evaluated__()
        assert maybe_evaluate(x) == 30
        assert maybe_evaluate(x) == 30

        assert maybe_evaluate(30) == 30
        assert x.__evaluated__()
Esempio n. 5
0
    def test_callbacks(self):
        source = Mock(name='source')
        p = PromiseProxy(source)
        cbA = Mock(name='cbA')
        cbB = Mock(name='cbB')
        cbC = Mock(name='cbC')
        p.__then__(cbA, p)
        p.__then__(cbB, p)
        self.assertFalse(p.__evaluated__())
        self.assertTrue(object.__getattribute__(p, '__pending__'))

        self.assertTrue(repr(p))
        with self.assertRaises(AttributeError):
            object.__getattribute__(p, '__pending__')
        cbA.assert_called_with(p)
        cbB.assert_called_with(p)

        self.assertTrue(p.__evaluated__())
        p.__then__(cbC, p)
        cbC.assert_called_with(p)

        with self.assertRaises(AttributeError):
            object.__getattribute__(p, '__pending__')
Esempio n. 6
0
    def test_callbacks(self):
        source = Mock(name="source")
        p = PromiseProxy(source)
        cbA = Mock(name="cbA")
        cbB = Mock(name="cbB")
        cbC = Mock(name="cbC")
        p.__then__(cbA, p)
        p.__then__(cbB, p)
        self.assertFalse(p.__evaluated__())
        self.assertTrue(object.__getattribute__(p, "__pending__"))

        self.assertTrue(repr(p))
        with self.assertRaises(AttributeError):
            object.__getattribute__(p, "__pending__")
        cbA.assert_called_with(p)
        cbB.assert_called_with(p)

        self.assertTrue(p.__evaluated__())
        p.__then__(cbC, p)
        cbC.assert_called_with(p)

        with self.assertRaises(AttributeError):
            object.__getattribute__(p, "__pending__")
Esempio n. 7
0
    def test_callbacks(self):
        source = Mock(name='source')
        p = PromiseProxy(source)
        cbA = Mock(name='cbA')
        cbB = Mock(name='cbB')
        cbC = Mock(name='cbC')
        p.__then__(cbA, p)
        p.__then__(cbB, p)
        assert not p.__evaluated__()
        assert object.__getattribute__(p, '__pending__')

        assert repr(p)
        assert p.__evaluated__()
        with pytest.raises(AttributeError):
            object.__getattribute__(p, '__pending__')
        cbA.assert_called_with(p)
        cbB.assert_called_with(p)

        assert p.__evaluated__()
        p.__then__(cbC, p)
        cbC.assert_called_with(p)

        with pytest.raises(AttributeError):
            object.__getattribute__(p, '__pending__')
Esempio n. 8
0
    def test_callbacks(self):
        source = Mock(name='source')
        p = PromiseProxy(source)
        cbA = Mock(name='cbA')
        cbB = Mock(name='cbB')
        cbC = Mock(name='cbC')
        p.__then__(cbA, p)
        p.__then__(cbB, p)
        assert not p.__evaluated__()
        assert object.__getattribute__(p, '__pending__')

        assert repr(p)
        assert p.__evaluated__()
        with pytest.raises(AttributeError):
            object.__getattribute__(p, '__pending__')
        cbA.assert_called_with(p)
        cbB.assert_called_with(p)

        assert p.__evaluated__()
        p.__then__(cbC, p)
        cbC.assert_called_with(p)

        with pytest.raises(AttributeError):
            object.__getattribute__(p, '__pending__')