Esempio n. 1
0
def test_view(exopy_qtbot):
    """Test the FormulaTask view.

    """
    show_and_close_widget(exopy_qtbot,
                          DefinitionView(task=DefinitionTask(name='Test')))
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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
Esempio n. 5
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 teardown(self):
        del self.root.should_pause
        del self.root.should_stop
        # Ensure we collect the file descriptor of the events. Otherwise we can
        # get funny errors on MacOS.
        gc.collect()

    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