class TestFormulaTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = FormulaTask(task_name='Test')
        self.root.children_task.append(self.task)

    def test_formulas_observation(self):
        # Test that the database is correctly updated when defs change.
        self.task.formulas = [('1', '2.0'), ('2', "['a', 1.0]")]

        assert_equal(self.task.get_from_database('Test_1'), 1.0)
        assert_equal(self.task.get_from_database('Test_2'), 1.0)

        self.task.formulas = []

        aux = self.task.accessible_database_entries()
        assert_not_in('Test_1', aux)
        assert_not_in('Test_2', aux)

    def test_check1(self):
        # Simply test that everything is ok if formulas are corrects.
        self.task.formulas = [('1', '2.0'), ('2', "['a', 1.0]")]

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_equal(self.task.get_from_database('Test_1'), 2.0)
        assert_equal(self.task.get_from_database('Test_2'), ['a', 1.0])

    def test_check2(self):
        # Test handling a wrong formula.
        self.task.formulas = [('1', '2.0'), ('2', "*['a', 1.0]")]

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-2', traceback)
        assert_equal(self.task.get_from_database('Test_1'), 2.0)
        assert_equal(self.task.get_from_database('Test_2'), 1.0)

    def test_perform(self):
        # Test performing.
        self.task.formulas = [('1', '2.0'), ('2', "['a', 1.0]")]

        self.root.task_database.prepare_for_running()

        self.task.perform()

        assert_equal(self.task.get_from_database('Test_1'), 2.0)
        assert_equal(self.task.get_from_database('Test_2'), ['a', 1.0])
Esempio n. 2
0
 def setup(self):
     self.root = RootTask(should_stop=Event(), should_pause=Event())
     self.task = FormulaTask(task_name='Test')
     self.root.children_task.append(self.task)