コード例 #1
0
ファイル: test_log_task.py プロジェクト: prismv/exopy
class TestLogTask(object):
    """Test LogTask.

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

    def test_check1(self):
        """Test checking that a message that cannot be formatted will result in a fail

        """
        self.task.message = 'TestMessage {aa}'

        test, traceback = self.task.check()

        assert not test
        assert len(traceback) == 1
        assert 'root/Test-message' in traceback
        assert not self.task.get_from_database('Test_message')

    def test_perform1(self):
        """Test checking that the message value gets written to the database

        """
        self.task.write_in_database('val', 'World')
        self.task.message = 'Hello {Test_val}'
        self.root.prepare()

        self.task.perform()
        assert self.task.get_from_database('Test_message') == 'Hello World'
コード例 #2
0
ファイル: test_formula_task.py プロジェクト: Ecpy/ecpy
class TestFormulaTask(object):
    """Test FormulaTask.

    """

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = FormulaTask(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 evaluated formula gets written to the
        database

        """
        self.task.formulas = OrderedDict([('key1', "1.0+3.0"),
                                          ('key2', '3.0+4.0')])
        self.root.prepare()

        self.task.perform()
        assert (self.task.get_from_database('Test_key1') == 4.0 and
                self.task.get_from_database('Test_key2') == 7.0)

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

        """
        self.task.write_in_database('pi', 3.1)
        self.task.formulas = \
            ordered_dict_from_pref(self, self.task.formulas,
                                   ("[(u'key1', '1.0+3.0'), "
                                    "(u'key2', '3.0 + {Test_pi}')]"))
        self.root.prepare()

        self.task.perform()
        assert (self.task.get_from_database('Test_key1') == 4.0 and
                self.task.get_from_database('Test_key2') == 6.1)

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

        """
        self.task.formulas = 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
コード例 #3
0
ファイル: test_definition_task.py プロジェクト: prismv/exopy
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
コード例 #4
0
ファイル: test_formula_task.py プロジェクト: prismv/exopy
class TestFormulaTask(object):
    """Test FormulaTask.

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

    def test_perform1(self):
        """Test checking that the evaluated formula gets written to the
        database

        """
        self.task.formulas = OrderedDict([('key1', "1.0+3.0"),
                                          ('key2', '3.0+4.0')])
        self.root.prepare()

        self.task.perform()
        assert (self.task.get_from_database('Test_key1') == 4.0
                and self.task.get_from_database('Test_key2') == 7.0)

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

        """
        self.task.write_in_database('pi', 3.1)
        self.task.formulas = \
            ordered_dict_from_pref(self, self.task.formulas,
                                   ("[(u'key1', '1.0+3.0'), "
                                    "(u'key2', '3.0 + {Test_pi}')]"))
        self.root.prepare()

        self.task.perform()
        assert (self.task.get_from_database('Test_key1') == 4.0
                and self.task.get_from_database('Test_key2') == 6.1)

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

        """
        self.task.formulas = 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
コード例 #5
0
ファイル: test_log_task.py プロジェクト: Ecpy/ecpy
class TestLogTask(object):
    """Test LogTask.

    """

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = LogTask(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_check1(self):
        """Test checking that a message that cannot be formatted will result in a fail

        """
        self.task.message = 'TestMessage {aa}'

        test, traceback = self.task.check()

        assert not test
        assert len(traceback) == 1
        assert 'root/Test-message' in traceback
        assert not self.task.get_from_database('Test_message')

    def test_perform1(self):
        """Test checking that the message value gets written to the database

        """
        self.task.write_in_database('val', 'World')
        self.task.message = 'Hello {Test_val}'
        self.root.prepare()

        self.task.perform()
        assert self.task.get_from_database('Test_message') == 'Hello World'
コード例 #6
0
ファイル: test_log_task.py プロジェクト: rassouly/exopy
class TestLogTask(object):
    """Test LogTask.

    """
    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = LogTask(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_check1(self):
        """Test checking that a message that cannot be formatted will result in a fail

        """
        self.task.message = 'TestMessage {aa}'

        test, traceback = self.task.check()

        assert not test
        assert len(traceback) == 1
        assert 'root/Test-message' in traceback
        assert not self.task.get_from_database('Test_message')

    def test_perform1(self):
        """Test checking that the message value gets written to the database

        """
        self.task.write_in_database('val', 'World')
        self.task.message = 'Hello {Test_val}'
        self.root.prepare()

        self.task.perform()
        assert self.task.get_from_database('Test_message') == 'Hello World'
コード例 #7
0
ファイル: test_definition_task.py プロジェクト: Ecpy/ecpy
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