예제 #1
0
 def setup(self):
     self.root = RootTask(should_stop=Event(), should_pause=Event())
     self.task = DefinitionTask(name='Test')
     self.root.add_child_task(0, self.task)
예제 #2
0
def test_view(windows):
    """Test the FormulaTask view.

    """
    show_and_close_widget(DefinitionView(task=DefinitionTask(name='Test')))
예제 #3
0
class TestDefinitionTask(object):
    """Test DefinitionTask.

    """

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = DefinitionTask(name='Test')
        self.root.add_child_task(0, self.task)

    def test_perform1(self):
        """Test checking that the formatted definition gets written to the
        database

        """
        self.task.write_in_database('it', 'World')
        self.task.definitions = OrderedDict([('key1', "2.0+3.0"),
                                             ('key2', 'Hello')])
        self.root.prepare()

        self.task.check()
        assert self.task.get_from_database('Test_key1') == safe_eval(
            "1.0+4.0", {})
        assert self.task.get_from_database('Test_key2') == "Hello"

    def test_check_after_load(self):
        """Test checking for correct loading from pref and that we can still
        recall values from the database

        """
        self.task.write_in_database('it', 'World')

        pref = "[(u'key1', u'1.0+3.0'), (u'key2', u'Hello')]"
        self.task.definitions = ordered_dict_from_pref(self,
                                                       self.task.definitions,
                                                       pref)

        self.root.prepare()

        self.task.check()
        assert self.task.get_from_database('Test_key1') == safe_eval(
            "1.0+3.0", {})
        assert self.task.get_from_database('Test_key2') == "Hello"

    def test_check(self):
        """Test checking that an unformattable definition gives an error

        """
        self.task.definitions = OrderedDict([('key1', "1.0+3.0"),
                                             ('key2', '3.0+4.0 + {Test_pi}')])

        test, traceback = self.task.check()
        assert not test
        assert len(traceback) == 1
        assert 'root/Test-key2' in traceback