Пример #1
0
 def setup(self):
     self.root = RootTask(should_stop=Event(), should_pause=Event())
     self.task = ArrayFindValueTask(name="Test")
     self.root.add_child_task(0, self.task)
     array = np.zeros((5,), dtype={"names": ["var1", "var2"], "formats": ["f8", "f8"]})
     array["var1"][1] = -1.5
     array["var1"][3] = 1.6359
     array["var1"][4] = 1.6359
     self.root.write_in_database("array", array)
Пример #2
0
class TestArrayFindValueTask(object):
    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ArrayFindValueTask(name="Test")
        self.root.add_child_task(0, self.task)
        array = np.zeros((5,), dtype={"names": ["var1", "var2"], "formats": ["f8", "f8"]})
        array["var1"][1] = -1.5
        array["var1"][3] = 1.6359
        array["var1"][4] = 1.6359
        self.root.write_in_database("array", array)

    def test_check1(self):
        """Simply test that everything is ok if the array exists in the
        database and value can be evaluated.

        """
        self.root.write_in_database("array", np.zeros((5,)))
        self.task.target_array = "{array}"
        self.task.value = "1.6359"

        test, traceback = self.task.check()
        assert test
        assert not traceback

    def test_check2(self):
        """Simply test that everything is ok if the array exists in the
        database the column name is ok, and value can be evaluated.

        """
        self.task.target_array = "{array}"
        self.task.column_name = "var1"
        self.task.value = "1.6359"

        test, traceback = self.task.check()
        assert test
        assert not traceback

    def test_check3(self):
        """Test handling a wrong array name.

        """
        self.task.target_array = "*{array}"
        self.task.column_name = "var3"
        self.task.value = "1.6359"

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

    def test_check4(self):
        """Test handling an array without names when a name is given.

        """
        self.root.write_in_database("array", np.zeros((5,)))
        self.task.target_array = "{array}"
        self.task.column_name = "var1"
        self.task.value = "1.6359"

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

    def test_check5(self):
        """Test handling an array with names when no name is given.

        """
        self.task.target_array = "{array}"
        self.task.value = "1.6359"

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

    def test_check6(self):
        """Test handling a wrong column name.

        """
        self.task.target_array = "{array}"
        self.task.column_name = "var3"
        self.task.value = "1.6359"

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

    def test_check7(self):
        """Test handling a wrong value.

        """
        self.task.target_array = "{array}"
        self.task.column_name = "var1"
        self.task.value = "*1.6359"

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

    def test_check8(self):
        """Test handling a 2d array value.

        """
        self.task.target_array = "{array}"
        self.task.value = "1.6359"

        array = np.zeros((5, 5))
        self.root.write_in_database("array", array)

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

    def test_perform1(self):
        """Test performing.

        """
        self.task.value = "1.6359"
        self.task.target_array = "{array}"
        self.task.column_name = "var1"
        self.root.prepare()

        self.task.perform()

        assert self.task.get_from_database("Test_index") == 3