Пример #1
0
 def setup(self):
     self.root = RootTask(should_stop=Event(), should_pause=Event())
     self.task = ArrayFindValueTask(task_name='Test')
     self.root.children_task.append(self.task)
     array = np.zeros((5, ), dtype=[('var1', 'f8'), ('var2', '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
 def setup(self):
     self.root = RootTask(should_stop=Event(), should_pause=Event())
     self.task = ArrayFindValueTask(task_name='Test')
     self.root.children_task.append(self.task)
     array = np.zeros((5,), dtype=[('var1', 'f8'), ('var2', 'f8')])
     array['var1'][1] = -1.5
     array['var1'][3] = 1.6359
     array['var1'][4] = 1.6359
     self.root.write_in_database('array', array)
Пример #3
0
    def setup(self):
        self.workbench = Workbench()
        self.workbench.register(CoreManifest())
        self.workbench.register(StateManifest())
        self.workbench.register(PreferencesManifest())
        self.workbench.register(TaskManagerManifest())

        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ArrayFindValueTask(task_name='Test')
        self.root.children_task.append(self.task)
Пример #4
0
class TestArrayFindValueTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ArrayFindValueTask(task_name='Test')
        self.root.children_task.append(self.task)
        array = np.zeros((5,), dtype=[('var1', 'f8'), ('var2', '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 = '{Root_array}'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(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 = '{Root_array}'
        self.task.column_name = 'var1'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)

    def test_check3(self):
        # Test handling a wrong array name.
        self.task.target_array = '*{Root_array}'
        self.task.column_name = 'var3'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-array', 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 = '{Root_array}'
        self.task.column_name = 'var1'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-column', traceback)

    def test_check5(self):
        # Test handling an array with names when no name is given.
        self.task.target_array = '{Root_array}'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-column', traceback)

    def test_check6(self):
        # Test handling a wrong column name.
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var3'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_true(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-column', traceback)

    def test_check7(self):
        # Test handling a wrong value.
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var1'
        self.task.value = '*1.6359'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-value', traceback)

    def test_check8(self):
        # Test handling a 2d array value.
        self.task.target_array = '{Root_array}'
        self.task.value = '1.6359'

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

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-dim', traceback)

    def test_perform1(self):
        # Test performing when mode is 'Max'.
        self.task.value = '1.6359'
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var1'
        self.root.task_database.prepare_for_running()

        self.task.perform()

        assert_equal(self.task.get_from_database('Test_index'), 3)
Пример #5
0
class TestArrayFindValueTask(object):
    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ArrayFindValueTask(task_name='Test')
        self.root.children_task.append(self.task)
        array = np.zeros((5, ), dtype=[('var1', 'f8'), ('var2', '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 = '{Root_array}'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(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 = '{Root_array}'
        self.task.column_name = 'var1'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)

    def test_check3(self):
        # Test handling a wrong array name.
        self.task.target_array = '*{Root_array}'
        self.task.column_name = 'var3'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-array', 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 = '{Root_array}'
        self.task.column_name = 'var1'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-column', traceback)

    def test_check5(self):
        # Test handling an array with names when no name is given.
        self.task.target_array = '{Root_array}'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-column', traceback)

    def test_check6(self):
        # Test handling a wrong column name.
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var3'
        self.task.value = '1.6359'

        test, traceback = self.task.check()
        assert_true(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-column', traceback)

    def test_check7(self):
        # Test handling a wrong value.
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var1'
        self.task.value = '*1.6359'

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-value', traceback)

    def test_check8(self):
        # Test handling a 2d array value.
        self.task.target_array = '{Root_array}'
        self.task.value = '1.6359'

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

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)
        assert_in('root/Test-dim', traceback)

    def test_perform1(self):
        # Test performing when mode is 'Max'.
        self.task.value = '1.6359'
        self.task.target_array = '{Root_array}'
        self.task.column_name = 'var1'
        self.root.task_database.prepare_for_running()

        self.task.perform()

        assert_equal(self.task.get_from_database('Test_index'), 3)