Esempio n. 1
0
    def test_in_operator(self):
        afx = Artifax(p=(3, 4))
        self.assertTrue('p' in afx)
        self.assertFalse('q' in afx)

        afx.pop('p')
        self.assertFalse('p' in afx)

        afx.set('q', (1, 2))
        self.assertTrue('q' in afx)
Esempio n. 2
0
    def test_incremental_build(self):
        class ExpensiveObject:
            def __init__(self):
                self.counter = 0

            def expensive_method(self, _):
                self.counter += 1
                return 'foobar'

        exo = ExpensiveObject()
        afx = Artifax(
            p=(3, 4),
            q=(12, 13),
            exo=lambda q: exo.expensive_method(q),
        )

        # pool_async silently fails to get trigger callback that resolves
        # the nodes, I guess because it can't pickle ExpensiveObject
        # from the unittest thread
        result = afx.build(solver='linear')
        self.assertEqual(exo.counter, 1)

        afx.set('p', (1, 1))
        result = afx.build(solver='linear')
        self.assertEqual(exo.counter, 1)

        afx.set('q', (0, 0))
        result = afx.build(solver='linear')
        self.assertEqual(exo.counter, 2)

        afx.set('new', 'hello')
        result = afx.build(solver='linear')
        self.assertEqual(result['new'], 'hello')
        self.assertEqual(exo.counter, 2)

        afx.pop('new')
        result = afx.build(solver='linear')
        self.assertEqual(exo.counter, 2)
Esempio n. 3
0
 def test_pop(self):
     afx = Artifax()
     afx.set('c', 'C')
     c = afx.pop('c')
     self.assertTrue(len(afx) == 0)
     self.assertEqual(c, 'C')