コード例 #1
0
ファイル: test_base_tasks.py プロジェクト: zoulianmp/HQCMeas
def test_ex_access_handling3():
    # Test moving a task with whose one entry has an ex_access.
    root = RootTask()
    task1 = ComplexTask(task_name='task1')
    root.children_task.append(task1)
    task2 = SimpleTask(task_name='task2', task_database_entries={'val2': 'r'})
    task1.children_task.append(task2)

    task1.add_access_exception('task2_val2')
    assert_equal(root.get_from_database('task2_val2'), 'r')
    task1.children_task = []
    assert_raises(KeyError, root.get_from_database, 'task2_val2')
    task1.children_task.append(task2)
    assert_equal(root.get_from_database('task2_val2'), 'r')
コード例 #2
0
def test_ex_access_handling3():
    # Test moving a task with whose one entry has an ex_access.
    root = RootTask()
    task1 = ComplexTask(task_name='task1')
    root.children_task.append(task1)
    task2 = SimpleTask(task_name='task2',
                       task_database_entries={'val2': 'r'})
    task1.children_task.append(task2)

    task1.add_access_exception('task2_val2')
    assert_equal(root.get_from_database('task2_val2'), 'r')
    task1.children_task = []
    assert_raises(KeyError, root.get_from_database, 'task2_val2')
    task1.children_task.append(task2)
    assert_equal(root.get_from_database('task2_val2'), 'r')
コード例 #3
0
ファイル: test_log_task.py プロジェクト: floubar/HQCMeas
class TestLogTask(object):
    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = LogTask(task_name='Test')
        self.root.children_task.append(self.task)

    def test_check1(self):
        # Simply test that everything is ok message is evaluable.
        self.task.message = 'True'

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

    def test_check2(self):
        # Test handling a wrong message.
        self.task.message = 'True{'

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

    def test_perform(self):
        # Test performing when condition is True.
        self.task.message = 'toro'

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_message'), 'toro')
コード例 #4
0
class TestLogTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = LogTask(task_name='Test')
        self.root.children_task.append(self.task)

    def test_check1(self):
        # Simply test that everything is ok message is evaluable.
        self.task.message = 'True'

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

    def test_check2(self):
        # Test handling a wrong message.
        self.task.message = 'True{'

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

    def test_perform(self):
        # Test performing when condition is True.
        self.task.message = 'toro'

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_message'), 'toro')
コード例 #5
0
ファイル: test_pna_tasks.py プロジェクト: zoulianmp/HQCMeas
class TestPNASetRFFrequencyTask(object):
    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = SetRFFrequencyTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        self.task.unit = 'GHz'

        # This is set simply to make sure the test of InstrTask pass.
        self.task.selected_driver = 'Test'
        self.task.selected_profile = 'Test1'

    def test_check_pna_interface1(self):
        # Simply test that everything is ok if frequency can be evaluated.
        self.task.interface = PNASetRFFrequencyInterface(task=self.task,
                                                         channel=1)
        self.task.frequency = '1.0'

        profile = {'Test1': ({'defined_channels': [[1]]}, {})}
        self.root.run_time['profiles'] = profile

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

    def test_check_pna_interface2(self):
        # Check handling a wrong channel.
        self.task.interface = PNASetRFFrequencyInterface(task=self.task,
                                                         channel=1)
        self.task.frequency = '1.0'

        profile = {'Test1': ({'defined_channels': [[2]]}, {})}
        self.root.run_time['profiles'] = profile

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_perform_pna_interface(self):
        self.task.interface = PNASetRFFrequencyInterface(task=self.task)
        self.task.frequency = '1.0'

        profile = {
            'Test1': ({
                'frequency': [0.0],
                'owner': [None]
            }, {
                'get_channel': lambda x, i: x
            })
        }
        self.root.run_time['profiles'] = profile

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_frequency'), 1.0e9)
コード例 #6
0
class TestPNASetRFFrequencyTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = SetRFFrequencyTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        self.task.unit = 'GHz'

        # This is set simply to make sure the test of InstrTask pass.
        self.task.selected_driver = 'Test'
        self.task.selected_profile = 'Test1'

    def test_check_pna_interface1(self):
        # Simply test that everything is ok if frequency can be evaluated.
        self.task.interface = PNASetRFFrequencyInterface(task=self.task,
                                                         channel=1)
        self.task.frequency = '1.0'

        profile = {'Test1': ({'defined_channels': [[1]]},
                             {})}
        self.root.run_time['profiles'] = profile

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

    def test_check_pna_interface2(self):
        # Check handling a wrong channel.
        self.task.interface = PNASetRFFrequencyInterface(task=self.task,
                                                         channel=1)
        self.task.frequency = '1.0'

        profile = {'Test1': ({'defined_channels': [[2]]},
                             {})}
        self.root.run_time['profiles'] = profile

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_perform_pna_interface(self):
        self.task.interface = PNASetRFFrequencyInterface(task=self.task)
        self.task.frequency = '1.0'

        profile = {'Test1': ({'frequency': [0.0],
                              'owner': [None]},
                             {'get_channel': lambda x, i: x}
                             )}
        self.root.run_time['profiles'] = profile

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_frequency'), 1.0e9)
コード例 #7
0
ファイル: test_base_tasks.py プロジェクト: zoulianmp/HQCMeas
def test_child_addition_handling1():
    # Test that adding a task to the root task is correctly handled.
    root = RootTask()
    task1 = ComplexTask(task_name='task1', task_database_entries={'val1': 2.0})
    root.children_task.append(task1)

    assert_equal(task1.task_depth, 1)
    assert_equal(task1.task_path, 'root')
    assert_is(task1.task_database, root.task_database)
    assert_is(task1.root_task, root)
    assert_is(task1.parent_task, root)

    assert_equal(task1.get_from_database('task1_val1'), 2.0)
    assert_equal(root.get_from_database('task1_val1'), 2.0)
コード例 #8
0
def test_child_addition_handling1():
    # Test that adding a task to the root task is correctly handled.
    root = RootTask()
    task1 = ComplexTask(task_name='task1',
                        task_database_entries={'val1': 2.0})
    root.children_task.append(task1)

    assert_equal(task1.task_depth, 1)
    assert_equal(task1.task_path, 'root')
    assert_is(task1.task_database, root.task_database)
    assert_is(task1.root_task, root)
    assert_is(task1.parent_task, root)

    assert_equal(task1.get_from_database('task1_val1'), 2.0)
    assert_equal(root.get_from_database('task1_val1'), 2.0)
コード例 #9
0
class TestSetRFOnOffTask(object):
    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = SetRFOnOffTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        # This is set simply to make sure the test of InstrTask pass.
        self.task.selected_driver = 'Test'
        self.task.selected_profile = 'Test1'

    def test_check_base_interface1(self):
        # Simply test that everything is ok if voltage can be evaluated.
        self.task.switch = '1.0'

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

    def test_check_base_interface2(self):
        # Check handling a wrong voltage.
        self.task.switch = '*1.0*'

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_perform_base_interface(self):
        self.task.switch = '1.0'

        self.root.run_time['profiles'] = {
            'Test1': ({
                'output': [0.0],
                'owner': [None]
            }, {})
        }

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_output'), 1.0)
コード例 #10
0
class TestSetRFOnOffTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = SetRFOnOffTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        # This is set simply to make sure the test of InstrTask pass.
        self.task.selected_driver = 'Test'
        self.task.selected_profile = 'Test1'

    def test_check_base_interface1(self):
        # Simply test that everything is ok if voltage can be evaluated.
        self.task.switch = '1.0'

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

    def test_check_base_interface2(self):
        # Check handling a wrong voltage.
        self.task.switch = '*1.0*'

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_perform_base_interface(self):
        self.task.switch = '1.0'

        self.root.run_time['profiles'] = {'Test1': ({'output': [0.0],
                                                     'owner': [None]}, {})}

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_output'), 1.0)
コード例 #11
0
class TestSetDCVoltageTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = MeasDCVoltageTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        # This is set simply to make sure the test of InstrTask pass.
        self.task.selected_driver = 'Test'
        self.task.selected_profile = 'Test1'

    def test_perform(self):
        self.task.wait_time = 1.0

        self.root.run_time['profiles'] = {'Test1': ({},
                                                    {'read_voltage_dc': [2.0]})
                                                    }

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_voltage'), 2.0)
コード例 #12
0
class TestSetDCVoltageTask(object):
    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = MeasDCVoltageTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        # This is set simply to make sure the test of InstrTask pass.
        self.task.selected_driver = 'Test'
        self.task.selected_profile = 'Test1'

    def test_perform(self):
        self.task.wait_time = 1.0

        self.root.run_time['profiles'] = {
            'Test1': ({}, {
                'read_voltage_dc': [2.0]
            })
        }

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_voltage'), 2.0)
コード例 #13
0
class TestApplyMagFieldTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ApplyMagFieldTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        # This is set simply to make sure the test of InstrTask pass.
        self.task.selected_driver = 'Test'
        self.task.selected_profile = 'Test1'

    def test_check1(self):
        # Simply test that everything is ok if field can be evaluated.
        self.task.target_field = '3.0'

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

        assert_equal(self.task.get_from_database('Test_Bfield'), 3.0)

    def test_check2(self):
        # Check handling a wrong field.
        self.task.target_field = '*1.0*'

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

        assert_equal(self.task.get_from_database('Test_Bfield'), 0.01)

    def test_perform1(self):
        # Simple test when everything is right.
        self.task.target_field = '2.0'

        self.root.run_time['profiles'] = {'Test1': ({'owner': []},
                                                    {'make_ready': [None],
                                                     'go_to_field': [None]}
                                                    )}

        self.root.task_database.prepare_for_running()

        self.task.perform()
        join_threads(self.root)
        assert_equal(self.root.get_from_database('Test_Bfield'), 2.0)

    def test_perform2(self):
        # Test multiple run when connection is maintained.
        self.task.target_field = '2.0'

        self.root.run_time['profiles'] = {'Test1': ({'owner': []},
                                                    {'make_ready': [None],
                                                     'go_to_field': [None],
                                                     'check_connection': [True]
                                                     }
                                                    )}

        self.root.task_database.prepare_for_running()

        self.task.perform()
        join_threads(self.root)
        self.task.perform()
        join_threads(self.root)
        # In case of fail make_ready would be called twice.
        assert_equal(self.root.get_from_database('Test_Bfield'), 2.0)
コード例 #14
0
class TestSetDCVoltageTask(object):
    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = SetDCVoltageTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        self.task.back_step = 0.1
        self.task.delay = 0.1

        # This is set simply to make sure the test of InstrTask pass.
        self.task.selected_driver = 'Test'
        self.task.selected_profile = 'Test1'

    def test_check_base_interface1(self):
        # Simply test that everything is ok if voltage can be evaluated.
        self.task.target_value = '1.0'

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

    def test_check_base_interface2(self):
        # Check handling a wrong voltage.
        self.task.target_value = '*1.0*'

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_check_multichannel_interface1(self):
        # Check the multichannel specific tests, passing.
        interface = MultiChannelVoltageSourceInterface(task=self.task)
        interface.channel = 1
        self.task.interface = interface
        self.task.target_value = '1.0'

        profile = {'Test1': ({'defined_channels': [[1]]}, {})}
        self.root.run_time['profiles'] = profile

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

    def test_check_multichannel_interface2(self):
        # Check the multichannel specific tests, failing = driver.
        interface = MultiChannelVoltageSourceInterface(task=self.task)
        interface.channel = 1
        self.task.interface = interface
        self.task.target_value = '1.0'

        self.root.run_time['drivers'] = {}
        profile = {'Test1': ({'defined_channels': [[1]]}, {})}
        self.root.run_time['profiles'] = profile

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_check_multichannel_interface3(self):
        # Check the multichannel specific tests, failing =profile.
        interface = MultiChannelVoltageSourceInterface(task=self.task)
        interface.channel = 1
        self.task.interface = interface
        self.task.target_value = '1.0'
        self.task.selected_profile = ''

        self.root.run_time['drivers'] = {'Test': InstrHelper}

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_check_multichannel_interface4(self):
        # Check the multichannel specific tests, failing = channel.
        interface = MultiChannelVoltageSourceInterface(task=self.task)
        interface.channel = 2
        self.task.interface = interface
        self.task.target_value = '1.0'

        profile = {'Test1': ({'defined_channels': [[1]]}, {})}
        self.root.run_time['profiles'] = profile
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_smooth_set_stopping(self):
        self.root.run_time['profiles'] = {
            'Test1': ({
                'voltage': [0.0],
                'funtion': ['VOLT'],
                'owner': [None]
            }, {})
        }

        self.root.task_database.prepare_for_running()
        self.root.should_stop.set()

        setter = lambda value: setattr(self.driver, 'voltage', value)

        self.task.smooth_set(1.0, setter, 0.0)
        assert_equal(self.root.get_from_database('Test_voltage'), 0.0)

    def test_perform_base_interface(self):
        # Test also that a target which is not a multiple of the back step
        # is correctly handled.
        self.task.target_value = '0.05'

        self.root.run_time['profiles'] = {
            'Test1': ({
                'voltage': [0.0],
                'funtion': ['VOLT'],
                'owner': [None]
            }, {})
        }

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_voltage'), 0.05)
        self.task.target_value = '1.06'
        self.task.perform()
        assert_equal(self.root.get_from_database('Test_voltage'), 1.06)

    def test_perform_multichannel_interface(self):
        interface = MultiChannelVoltageSourceInterface(task=self.task)
        interface.channel = 1
        self.task.interface = interface
        self.task.target_value = '1.0'

        profile = {
            'Test1': ({
                'voltage': [0.0],
                'funtion': ['VOLT'],
                'owner': [None]
            }, {
                'get_channel': lambda x, i: x
            })
        }
        self.root.run_time['profiles'] = profile

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_voltage'), 1.0)
コード例 #15
0
ファイル: test_loop_task.py プロジェクト: zoulianmp/HQCMeas
class TestLoopTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = LoopTask(task_name='Test')
        self.root.children_task.append(self.task)

    def test_task_handling(self):
        # Test adding removing a task.
        aux = CheckTask()
        self.task.task = aux

        # Check value is not written in database if a task is present.
        assert_not_in('value', self.task.task_database_entries)
        # Confirm the child was added (_child_added called)
        assert_is(aux.root_task, self.root)

        del self.task.task

        # Check value is written in database if no task is present.
        assert_in('value', self.task.task_database_entries)
        # Confirm the child was added (_child_removed called)
        assert_is(aux.root_task, None)

    def test_timing_handling(self):
        # Test enabling/disabling the timing.
        assert_not_in('elapsed_time', self.task.task_database_entries)

        self.task.timing = True

        assert_in('elapsed_time', self.task.task_database_entries)

        self.task.timing = False

        assert_not_in('elapsed_time', self.task.task_database_entries)

    def test_check_linspace_interface1(self):
        # Simply test that everything is ok when all formulas are true.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.1'
        self.task.interface = interface

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_equal(self.task.get_from_database('Test_point_number'), 11)

    def test_check_linspace_interface2(self):
        # Test handling a wrong start.
        interface = LinspaceLoopInterface()
        interface.start = '1.0*'
        interface.stop = '2.0'
        interface.step = '0.1'
        self.task.interface = interface

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

    def test_check_linspace_interface3(self):
        # Test handling a wrong stop.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0*'
        interface.step = '0.1'
        self.task.interface = interface

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

    def test_check_linspace_interface4(self):
        # Test handling a wrong step.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.1*'
        self.task.interface = interface

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

    def test_check_linspace_interface5(self):
        # Test handling a wrong number of point.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.0'
        self.task.interface = interface

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 2)
        assert_in('root/Test-points', traceback)
        assert_in('root/Test-linspace', traceback)

    def test_check_iterable_interface1(self):
        # Simply test that everything is ok when all formulas are true.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_equal(self.task.get_from_database('Test_point_number'), 11)

        interface.iterable = 'dict(a=1)'
        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_equal(self.task.get_from_database('Test_point_number'), 1)
        assert_equal(self.task.get_from_database('Test_value'), 'a')

    def test_check_iterable_interface2(self):
        # Test handling a wrong iterable formula.
        interface = IterableLoopInterface()
        interface.iterable = '*range(11)'
        self.task.interface = interface

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

    def test_check_iterable_interface3(self):
        # Test handling a wrong iterable type.
        interface = IterableLoopInterface()
        interface.iterable = '1.0'
        self.task.interface = interface

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

    def test_check_execution_order(self):
        # Test that the interface checks are run before the children checks.
        interface = IterableLoopInterface()
        interface.iterable = '[(1, 0)]'
        self.task.interface = interface

        subiter = IterableLoopInterface(iterable='{Test_value}')
        self.task.children_task = [LoopTask(interface=subiter)]

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

    def test_perform1(self):
        # Test performing a simple loop no timing. Iterable interface.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 10)

    def test_perform2(self):
        # Test performing a simple loop no timing. Linspace interface.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.1'
        self.task.interface = interface

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 2.0)

    def test_perform3(self):
        # Test performing a simple loop no timing. Break.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_value} == 5')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 5)

    def test_perform4(self):
        # Test performing a simple loop no timing. Continue
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_false(self.task.children_task[1].perform_called)

    def test_perform_task1(self):
        # Test performing a loop with an embedded task no timing.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.task = CheckTask(task_name='check')

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)

    def test_perform_task2(self):
        # Test performing a loop with an embedded task no timing. Break.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_index} == 6')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 6)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 5)

    def test_perform_task3(self):
        # Test performing a loop with an embedded task no timing. Continue.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)
        assert_false(self.task.children_task[1].perform_called)

    def test_perform_timing1(self):
        # Test performing a simple loop timing.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 10)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing2(self):
        # Test performing a simple loop timing. Break
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_value} == 0')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 0)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing3(self):
        # Test performing a simple loop timing. Continue
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_false(self.task.children_task[1].perform_called)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing_task1(self):
        # Test performing a loop with an embedded task no timing.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.task = CheckTask(task_name='check')

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing_task2(self):
        # Test performing a loop with an embedded task no timing. Break.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_index} == 1')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 1)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 0)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing_task3(self):
        # Test performing a loop with an embedded task no timing. Continue.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)
        assert_false(self.task.children_task[1].perform_called)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)
コード例 #16
0
class TestSetDCVoltageTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = SetDCVoltageTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        self.task.back_step = 0.1
        self.task.delay = 0.1

        # This is set simply to make sure the test of InstrTask pass.
        self.task.selected_driver = 'Test'
        self.task.selected_profile = 'Test1'

    def test_check_base_interface1(self):
        # Simply test that everything is ok if voltage can be evaluated.
        self.task.target_value = '1.0'

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

    def test_check_base_interface2(self):
        # Check handling a wrong voltage.
        self.task.target_value = '*1.0*'

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_check_multichannel_interface1(self):
        # Check the multichannel specific tests, passing.
        interface = MultiChannelVoltageSourceInterface(task=self.task)
        interface.channel = 1
        self.task.interface = interface
        self.task.target_value = '1.0'

        profile = {'Test1': ({'defined_channels': [[1]]},
                             {})}
        self.root.run_time['profiles'] = profile

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

    def test_check_multichannel_interface2(self):
        # Check the multichannel specific tests, failing = driver.
        interface = MultiChannelVoltageSourceInterface(task=self.task)
        interface.channel = 1
        self.task.interface = interface
        self.task.target_value = '1.0'

        self.root.run_time['drivers'] = {}
        profile = {'Test1': ({'defined_channels': [[1]]},
                             {})}
        self.root.run_time['profiles'] = profile

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_check_multichannel_interface3(self):
        # Check the multichannel specific tests, failing =profile.
        interface = MultiChannelVoltageSourceInterface(task=self.task)
        interface.channel = 1
        self.task.interface = interface
        self.task.target_value = '1.0'
        self.task.selected_profile = ''

        self.root.run_time['drivers'] = {'Test': InstrHelper}

        test, traceback = self.task.check()
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_check_multichannel_interface4(self):
        # Check the multichannel specific tests, failing = channel.
        interface = MultiChannelVoltageSourceInterface(task=self.task)
        interface.channel = 2
        self.task.interface = interface
        self.task.target_value = '1.0'

        profile = {'Test1': ({'defined_channels': [[1]]},
                             {})}
        self.root.run_time['profiles'] = profile
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 1)

    def test_smooth_set_stopping(self):
        self.root.run_time['profiles'] = {'Test1': ({'voltage': [0.0],
                                                     'funtion': ['VOLT'],
                                                     'owner': [None]}, {})}

        self.root.task_database.prepare_for_running()
        self.root.should_stop.set()

        setter = lambda value: setattr(self.driver, 'voltage', value)

        self.task.smooth_set(1.0, setter, 0.0)
        assert_equal(self.root.get_from_database('Test_voltage'), 0.0)

    def test_perform_base_interface(self):
        # Test also that a target which is not a multiple of the back step
        # is correctly handled.
        self.task.target_value = '0.05'

        self.root.run_time['profiles'] = {'Test1': ({'voltage': [0.0],
                                                     'funtion': ['VOLT'],
                                                     'owner': [None]}, {})}

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_voltage'), 0.05)
        self.task.target_value = '1.06'
        self.task.perform()
        assert_equal(self.root.get_from_database('Test_voltage'), 1.06)

    def test_perform_multichannel_interface(self):
        interface = MultiChannelVoltageSourceInterface(task=self.task)
        interface.channel = 1
        self.task.interface = interface
        self.task.target_value = '1.0'

        profile = {'Test1': ({'voltage': [0.0],
                              'funtion': ['VOLT'],
                              'owner': [None]},
                             {'get_channel': lambda x, i: x}
                             )}
        self.root.run_time['profiles'] = profile

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_voltage'), 1.0)
コード例 #17
0
ファイル: test_base_tasks.py プロジェクト: zoulianmp/HQCMeas
def test_register_in_database1():
    # Check that the root task does write its default entries in the database
    # when instantiated.
    root = RootTask()
    assert_equal(root.get_from_database('default_path'), '')
コード例 #18
0
def test_register_in_database1():
    # Check that the root task does write its default entries in the database
    # when instantiated.
    root = RootTask()
    assert_equal(root.get_from_database('default_path'), '')
コード例 #19
0
ファイル: test_loop_task.py プロジェクト: jf---/HQCMeas
class TestLoopTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = LoopTask(task_name='Test')
        self.root.children_task.append(self.task)

    def test_task_handling(self):
        # Test adding removing a task.
        aux = CheckTask()
        self.task.task = aux

        # Check value is not written in database if a task is present.
        assert_not_in('value', self.task.task_database_entries)
        # Confirm the child was added (_child_added called)
        assert_is(aux.root_task, self.root)

        del self.task.task

        # Check value is written in database if no task is present.
        assert_in('value', self.task.task_database_entries)
        # Confirm the child was added (_child_removed called)
        assert_is(aux.root_task, None)

    def test_timing_handling(self):
        # Test enabling/disabling the timing.
        assert_not_in('elapsed_time', self.task.task_database_entries)

        self.task.timing = True

        assert_in('elapsed_time', self.task.task_database_entries)

        self.task.timing = False

        assert_not_in('elapsed_time', self.task.task_database_entries)

    def test_check_linspace_interface1(self):
        # Simply test that everything is ok when all formulas are true.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.1'
        self.task.interface = interface

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_equal(self.task.get_from_database('Test_point_number'), 11)

    def test_check_linspace_interface2(self):
        # Test handling a wrong start.
        interface = LinspaceLoopInterface()
        interface.start = '1.0*'
        interface.stop = '2.0'
        interface.step = '0.1'
        self.task.interface = interface

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

    def test_check_linspace_interface3(self):
        # Test handling a wrong stop.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0*'
        interface.step = '0.1'
        self.task.interface = interface

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

    def test_check_linspace_interface4(self):
        # Test handling a wrong step.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.1*'
        self.task.interface = interface

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

    def test_check_linspace_interface5(self):
        # Test handling a wrong number of point.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.0'
        self.task.interface = interface

        test, traceback = self.task.check(test_instr=True)
        assert_false(test)
        assert_equal(len(traceback), 2)
        assert_in('root/Test-points', traceback)
        assert_in('root/Test-linspace', traceback)

    def test_check_iterable_interface1(self):
        # Simply test that everything is ok when all formulas are true.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface

        test, traceback = self.task.check()
        assert_true(test)
        assert_false(traceback)
        assert_equal(self.task.get_from_database('Test_point_number'), 11)

    def test_check_iterable_interface2(self):
        # Test handling a wrong iterable formula.
        interface = IterableLoopInterface()
        interface.iterable = '*range(11)'
        self.task.interface = interface

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

    def test_check_iterable_interface3(self):
        # Test handling a wrong iterable type.
        interface = IterableLoopInterface()
        interface.iterable = '1.0'
        self.task.interface = interface

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

    def test_perform1(self):
        # Test performing a simple loop no timing. Iterable interface.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 10)

    def test_perform2(self):
        # Test performing a simple loop no timing. Linspace interface.
        interface = LinspaceLoopInterface()
        interface.start = '1.0'
        interface.stop = '2.0'
        interface.step = '0.1'
        self.task.interface = interface

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 2.0)

    def test_perform3(self):
        # Test performing a simple loop no timing. Break.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_value} == 5')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 5)

    def test_perform4(self):
        # Test performing a simple loop no timing. Continue
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_false(self.task.children_task[1].perform_called)

    def test_perform_task1(self):
        # Test performing a loop with an embedded task no timing.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.task = CheckTask(task_name='check')

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)

    def test_perform_task2(self):
        # Test performing a loop with an embedded task no timing. Break.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_index} == 6')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 6)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 5)

    def test_perform_task3(self):
        # Test performing a loop with an embedded task no timing. Continue.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)
        assert_false(self.task.children_task[1].perform_called)

    def test_perform_timing1(self):
        # Test performing a simple loop timing.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 10)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing2(self):
        # Test performing a simple loop timing. Break
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_value} == 0')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_value'), 0)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing3(self):
        # Test performing a simple loop timing. Continue
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_false(self.task.children_task[1].perform_called)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing_task1(self):
        # Test performing a loop with an embedded task no timing.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.task = CheckTask(task_name='check')

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing_task2(self):
        # Test performing a loop with an embedded task no timing. Break.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(BreakTask(task_name='break',
                                                 condition='{Test_index} == 1')
                                       )

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 1)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 0)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)

    def test_perform_timing_task3(self):
        # Test performing a loop with an embedded task no timing. Continue.
        interface = IterableLoopInterface()
        interface.iterable = 'range(11)'
        self.task.interface = interface
        self.task.timing = True
        self.task.task = CheckTask(task_name='check')
        self.task.children_task.append(ContinueTask(task_name='break',
                                                    condition='True')
                                       )
        self.task.children_task.append(CheckTask(task_name='check'))

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_index'), 11)
        assert_true(self.task.task.perform_called)
        assert_equal(self.task.task.perform_value, 10)
        assert_false(self.task.children_task[1].perform_called)
        assert_not_equal(self.root.get_from_database('Test_elapsed_time'), 1.0)
コード例 #20
0
class TestSetDCVoltageTask(object):
    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = LockInMeasureTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        # This is set simply to make sure the test of InstrTask pass.
        self.task.selected_driver = 'Test'
        self.task.selected_profile = 'Test1'

    def test_mode_observation(self):
        # Check database is correctly updated when the mode change.
        self.task.mode = 'X'

        assert_equal(self.task.get_from_database('Test_x'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_y', aux)
        assert_not_in('Test_amplitude', aux)
        assert_not_in('Test_phase', aux)

        self.task.mode = 'Y'

        assert_equal(self.task.get_from_database('Test_y'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_x', aux)
        assert_not_in('Test_amplitude', aux)
        assert_not_in('Test_phase', aux)

        self.task.mode = 'X&Y'

        assert_equal(self.task.get_from_database('Test_x'), 1.0)
        assert_equal(self.task.get_from_database('Test_y'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_amplitude', aux)
        assert_not_in('Test_phase', aux)

        self.task.mode = 'Amp'

        assert_equal(self.task.get_from_database('Test_amplitude'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_x', aux)
        assert_not_in('Test_y', aux)
        assert_not_in('Test_phase', aux)

        self.task.mode = 'Phase'

        assert_equal(self.task.get_from_database('Test_phase'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_x', aux)
        assert_not_in('Test_y', aux)
        assert_not_in('Test_amplitude', aux)

        self.task.mode = 'Amp&Phase'

        assert_equal(self.task.get_from_database('Test_amplitude'), 1.0)
        assert_equal(self.task.get_from_database('Test_phase'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_x', aux)
        assert_not_in('Test_y', aux)

    def test_perform1(self):
        self.task.mode = 'X'

        self.root.run_time['profiles'] = {'Test1': ({}, {'read_x': [2.0]})}

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_x'), 2.0)

    def test_perform2(self):
        self.task.mode = 'Y'

        self.root.run_time['profiles'] = {'Test1': ({}, {'read_y': [2.0]})}

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_y'), 2.0)

    def test_perform3(self):
        self.task.mode = 'X&Y'

        self.root.run_time['profiles'] = {
            'Test1': ({}, {
                'read_xy': [(2.0, 3.0)]
            })
        }

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_x'), 2.0)
        assert_equal(self.root.get_from_database('Test_y'), 3.0)

    def test_perform4(self):
        self.task.mode = 'Amp'

        self.root.run_time['profiles'] = {
            'Test1': ({}, {
                'read_amplitude': [2.0]
            })
        }

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_amplitude'), 2.0)

    def test_perform5(self):
        self.task.mode = 'Phase'

        self.root.run_time['profiles'] = {'Test1': ({}, {'read_phase': [2.0]})}

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_phase'), 2.0)

    def test_perform6(self):
        self.task.mode = 'Amp&Phase'

        self.root.run_time['profiles'] = {
            'Test1': ({}, {
                'read_amp_and_phase': [(2.0, 3.0)]
            })
        }

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_amplitude'), 2.0)
        assert_equal(self.root.get_from_database('Test_phase'), 3.0)
コード例 #21
0
class TestSetDCVoltageTask(object):

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = LockInMeasureTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        # This is set simply to make sure the test of InstrTask pass.
        self.task.selected_driver = 'Test'
        self.task.selected_profile = 'Test1'

    def test_mode_observation(self):
        # Check database is correctly updated when the mode change.
        self.task.mode = 'X'

        assert_equal(self.task.get_from_database('Test_x'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_y', aux)
        assert_not_in('Test_amplitude', aux)
        assert_not_in('Test_phase', aux)

        self.task.mode = 'Y'

        assert_equal(self.task.get_from_database('Test_y'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_x', aux)
        assert_not_in('Test_amplitude', aux)
        assert_not_in('Test_phase', aux)

        self.task.mode = 'X&Y'

        assert_equal(self.task.get_from_database('Test_x'), 1.0)
        assert_equal(self.task.get_from_database('Test_y'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_amplitude', aux)
        assert_not_in('Test_phase', aux)

        self.task.mode = 'Amp'

        assert_equal(self.task.get_from_database('Test_amplitude'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_x', aux)
        assert_not_in('Test_y', aux)
        assert_not_in('Test_phase', aux)

        self.task.mode = 'Phase'

        assert_equal(self.task.get_from_database('Test_phase'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_x', aux)
        assert_not_in('Test_y', aux)
        assert_not_in('Test_amplitude', aux)

        self.task.mode = 'Amp&Phase'

        assert_equal(self.task.get_from_database('Test_amplitude'), 1.0)
        assert_equal(self.task.get_from_database('Test_phase'), 1.0)
        aux = self.task.accessible_database_entries()
        assert_not_in('Test_x', aux)
        assert_not_in('Test_y', aux)

    def test_perform1(self):
        self.task.mode = 'X'

        self.root.run_time['profiles'] = {'Test1': ({}, {'read_x': [2.0]})}

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_x'), 2.0)

    def test_perform2(self):
        self.task.mode = 'Y'

        self.root.run_time['profiles'] = {'Test1': ({}, {'read_y': [2.0]})}

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_y'), 2.0)

    def test_perform3(self):
        self.task.mode = 'X&Y'

        self.root.run_time['profiles'] = {'Test1': ({},
                                                    {'read_xy': [(2.0, 3.0)]})}

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_x'), 2.0)
        assert_equal(self.root.get_from_database('Test_y'), 3.0)

    def test_perform4(self):
        self.task.mode = 'Amp'

        self.root.run_time['profiles'] = {'Test1': ({},
                                                    {'read_amplitude': [2.0]})}

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_amplitude'), 2.0)

    def test_perform5(self):
        self.task.mode = 'Phase'

        self.root.run_time['profiles'] = {'Test1': ({}, {'read_phase': [2.0]})}

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_phase'), 2.0)

    def test_perform6(self):
        self.task.mode = 'Amp&Phase'

        self.root.run_time['profiles'] = {'Test1': ({},
                                          {'read_amp_and_phase': [(2.0, 3.0)]})
                                          }

        self.root.task_database.prepare_for_running()

        self.task.perform()
        assert_equal(self.root.get_from_database('Test_amplitude'), 2.0)
        assert_equal(self.root.get_from_database('Test_phase'), 3.0)
コード例 #22
0
class TestApplyMagFieldTask(object):
    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ApplyMagFieldTask(task_name='Test')
        self.root.children_task.append(self.task)
        self.root.run_time['drivers'] = {'Test': InstrHelper}

        # This is set simply to make sure the test of InstrTask pass.
        self.task.selected_driver = 'Test'
        self.task.selected_profile = 'Test1'

    def test_check1(self):
        # Simply test that everything is ok if field can be evaluated.
        self.task.target_field = '3.0'

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

        assert_equal(self.task.get_from_database('Test_Bfield'), 3.0)

    def test_check2(self):
        # Check handling a wrong field.
        self.task.target_field = '*1.0*'

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

        assert_equal(self.task.get_from_database('Test_Bfield'), 0.01)

    def test_perform1(self):
        # Simple test when everything is right.
        self.task.target_field = '2.0'

        self.root.run_time['profiles'] = {
            'Test1': ({
                'owner': []
            }, {
                'make_ready': [None],
                'go_to_field': [None]
            })
        }

        self.root.task_database.prepare_for_running()

        self.task.perform()
        join_threads(self.root)
        assert_equal(self.root.get_from_database('Test_Bfield'), 2.0)

    def test_perform2(self):
        # Test multiple run when connection is maintained.
        self.task.target_field = '2.0'

        self.root.run_time['profiles'] = {
            'Test1': ({
                'owner': []
            }, {
                'make_ready': [None],
                'go_to_field': [None],
                'check_connection': [True]
            })
        }

        self.root.task_database.prepare_for_running()

        self.task.perform()
        join_threads(self.root)
        self.task.perform()
        join_threads(self.root)
        # In case of fail make_ready would be called twice.
        assert_equal(self.root.get_from_database('Test_Bfield'), 2.0)