def test_override_saved_measure(self): """ Test that overriding a measure does override evrything. """ plugin = self.workbench.get_plugin(u'hqc_meas.measure') measure = Measure(plugin=plugin, name='Test', status='Under test') measure.root_task = RootTask(default_path=self.test_dir) # Needed because of Atom returning a _DictProxy measure.checks = dict(plugin.checks) # Needed because of Atom returning a _DictProxy measure.headers = dict(plugin.headers) # Adding a monitor. monitor_decl = plugin.monitors[u'monitor1'] measure.add_monitor(monitor_decl.id, monitor_decl.factory(monitor_decl, self.workbench)) measure.monitors[u'monitor1'].save_test = True path = os.path.join(self.test_dir, 'saved_measure.ini') # Save measure. measure.save_measure(path) # Create a new measure without headers and checks and test that the old # values are not in the config file. plugin = self.workbench.get_plugin(u'hqc_meas.measure') measure = Measure(plugin=plugin, name='Test', status='Under test') measure.root_task = RootTask(default_path=self.test_dir) measure.save_measure(path) conf = ConfigObj(path) assert_equal(conf['checks'], '[]') assert_equal(conf['headers'], '[]')
def setup(self): self.root = RootTask(should_stop=Event(), should_pause=Event()) self.task = LoadArrayTask(task_name='Test') self.task.interface = CSVLoadInterface() self.task.folder = FOLDER_PATH self.task.filename = 'fake.dat' self.root.children_task.append(self.task)
def test_child_deletion_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) root.children_task = []
def test_add_monitor1(self): """ Test adding a new monitor. """ plugin = self.workbench.get_plugin(u'hqc_meas.measure') measure = Measure(plugin=plugin, name='Test', status='Under test') measure.root_task = RootTask() # Be sure that there is no observers for the database assert_false(measure.root_task.task_database.has_observers('notifier')) monitor_decl = plugin.monitors[u'monitor1'] measure.add_monitor(monitor_decl.id, monitor_decl.factory(monitor_decl, self.workbench)) # Check the monitor is now in the list of the measure monitors assert_in(u'monitor1', measure.monitors) # Check that all values have been correctly updated. monitor = measure.monitors[u'monitor1'] assert_equal(monitor.measure_name, measure.name) assert_equal(monitor.measure_status, measure.status) assert_equal(monitor.updated, {'root/default_path': 1}) assert_equal(measure.collect_entries_to_observe(), ['root/default_path']) # Check that the notifier is correctly observed. assert_true(measure.root_task.task_database.has_observers('notifier'))
def setup(self): root = RootTask() root.should_pause = Event() root.should_stop = Event() root.paused = Event() root.default_path = 'toto' self.root = root
def setup(self): self.root = RootTask(should_stop=Event(), should_pause=Event()) self.task = ArrayExtremaTask(task_name='Test') self.root.children_task.append(self.task) array = np.zeros((5, ), dtype=[('var1', 'f8'), ('var2', 'f8')]) array['var1'][1] = -1 array['var1'][3] = 1 self.root.write_in_database('array', array)
def test_run_checks4(self): """ Test running checks for a measure. Passing without added. """ plugin = self.workbench.get_plugin(u'hqc_meas.measure') measure = Measure(plugin=plugin) measure.root_task = RootTask() measure.root_task = RootTask(default_path=self.test_dir) # Needed because of Atom returning a _DictProxy measure.checks = dict(plugin.checks) Checker.test_pass = False res, errors = measure.run_checks(self.workbench, internal_only=True) assert_true(res) assert_equal(errors, {})
def setup(self): self.root = RootTask(should_stop=Event(), should_pause=Event()) self.task = SaveFileTask(task_name='Test') self.root.children_task.append(self.task) self.root.write_in_database('int', 1) self.root.write_in_database('float', 2.0) self.root.write_in_database('array', np.array(range(10)))
def setup(self): self.root = RootTask(should_stop=Event(), should_pause=Event()) self.task = SaveTask(task_name='Test') self.root.children_task.append(self.task) self.root.write_in_database('int', 1) self.root.write_in_database('float', 2.0) self.root.write_in_database('str', 'a')
def test_remove_monitor2(self): """ Test removing a non-existent monitor (should be a no-op). """ plugin = self.workbench.get_plugin(u'hqc_meas.measure') measure = Measure(plugin=plugin, name='Test', status='Under test') measure.root_task = RootTask() measure.remove_monitor(u'monitor1')
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 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 = self.excep_class(task_name='Test', condition='rr') self.root.children_task.append(self.task)
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 = SaveArrayTask(task_name='Test') self.root.children_task.append(self.task)
def test_ex_access_handling1(): # Test adding an ex_access for an entry. 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) assert_raises(KeyError, root.get_from_database, 'task2_val2') task1.add_access_exception('task2_val2') assert_equal(root.get_from_database('task2_val2'), 'r')
def setup(self): self.root = RootTask(should_stop=Event(), should_pause=Event()) self.task = SaveArrayTask(task_name='Test') self.root.children_task.append(self.task) array = np.empty(2, dtype=np.dtype([('a', 'f8'), ('b', 'f8')])) array[0] = (0, 1) array[1] = (2, 3) self.root.write_in_database('array', array) self.root.write_in_database('float', 2.0) self.root.write_in_database('str', 'a')
def test_build_from_config1(self): # Test building a interfaceable task from a config. aux = RootTask() aux.children_task = [IMixin()] bis = RootTask.build_from_config( aux.task_preferences, {'tasks': { 'IMixin': IMixin, 'RootTask': RootTask }}) assert_equal(type(bis.children_task[0]).__name__, 'IMixin')
def setup(self): self.workbench = Workbench() self.workbench.register(CoreManifest()) self.workbench.register(StateManifest()) self.workbench.register(PreferencesManifest()) self.workbench.register(InstrManagerManifest()) self.workbench.register(TaskManagerManifest()) 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}
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)
def test_collect_headers(self): """ Test header collection. """ plugin = self.workbench.get_plugin(u'hqc_meas.measure') measure = Measure(plugin=plugin) measure.root_task = RootTask() # Needed because of Atom returning a _DictProxy measure.headers = dict(plugin.headers) measure.collect_headers(self.workbench) assert_equal(measure.root_task.default_header, 'Test header\nTest header')
def test_observer_root_task(self): """ Test the behavior of the root_task observer. """ plugin = self.workbench.get_plugin(u'hqc_meas.measure') measure = Measure(plugin=plugin, name='Test', status='Under test') root_task1 = RootTask() root_task2 = RootTask() measure.root_task = root_task1 monitor_decl = plugin.monitors[u'monitor1'] measure.add_monitor(monitor_decl.id, monitor_decl.factory(monitor_decl, self.workbench)) measure.root_task = root_task2 assert_equal(measure.monitors[u'monitor1'].updated, {'root/default_path': 1}) assert_equal(measure.collect_entries_to_observe(), ['root/default_path']) assert_false(root_task1.task_database.has_observers('notifier')) assert_true(root_task2.task_database.has_observers('notifier'))
def test_observer_status(self): """ Test observer for measure status. """ plugin = self.workbench.get_plugin(u'hqc_meas.measure') measure = Measure(plugin=plugin, name='Test', status='Under test') measure.root_task = RootTask() monitor_decl = plugin.monitors[u'monitor1'] measure.add_monitor(monitor_decl.id, monitor_decl.factory(monitor_decl, self.workbench)) measure.status = 'Test over' assert_equal(measure.monitors[u'monitor1'].measure_status, 'Test over')
def test_ex_access_handling5(): # Test removing a task with whose one entry has an ex_access, and then # adding a different task (same name, same class, etc) 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') task3 = SimpleTask(task_name='task2', task_database_entries={'val2': 'r'}) task1.children_task.append(task3) assert_raises(KeyError, root.get_from_database, 'task2_val2')
def test_child_addition_handling2(): # Test that adding a task to a complex task below the root task is # correctly handled. root = RootTask() task1 = ComplexTask(task_name='task1', task_database_entries={'val1': 2.0}) root.children_task.append(task1) task2 = SimpleTask(task_name='task2', task_database_entries={'val2': 'r'}) task1.children_task.append(task2) assert_equal(task2.task_depth, 2) assert_equal(task2.task_path, 'root/task1') assert_is(task2.task_database, root.task_database) assert_is(task2.root_task, root) assert_is(task2.parent_task, task1) assert_equal(task2.get_from_database('task2_val2'), 'r')
def test_run_checks2(self): """ Test running checks for a measure. Failing because added check. """ plugin = self.workbench.get_plugin(u'hqc_meas.measure') measure = Measure(plugin=plugin) measure.root_task = RootTask(default_path=self.test_dir) # Needed because of Atom returning a _DictProxy measure.checks = dict(plugin.checks) Checker.test_pass = False res, errors = measure.run_checks(self.workbench) assert_false(res) assert_equal(errors, {u'check1': {'test': 'Failed'}})
def test_ex_access_handling4(): # Test removing a task with whose one entry has an ex_access, adding a new # one and re-adding the first. 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') task3 = SimpleTask(task_name='task3', task_database_entries={'val3': 'r'}) task1.children_task.append(task3) task1.children_task.append(task2) assert_raises(KeyError, root.get_from_database, 'task2_val2')
def test_ex_access_handling7(): # Test moving a task to which two access exs are linked. root = RootTask() task1 = ComplexTask(task_name='task1') root.children_task.append(task1) task2 = ComplexTask(task_name='task2') task1.children_task.append(task2) task3 = ComplexTask(task_name='task3') task2.children_task.append(task3) task4 = SimpleTask(task_name='task4', task_database_entries={'val2': 'r'}) task3.children_task.append(task4) task3.add_access_exception('task4_val2') task2.add_access_exception('task4_val2') assert_equal(task2.get_from_database('task4_val2'), 'r') task3.remove_access_exception('task4_val2') assert_not_in('task4_val2', task2.access_exs)
def test_add_monitor2(self): """ Test adding twice the same monitor second time should be a no-op. """ plugin = self.workbench.get_plugin(u'hqc_meas.measure') measure = Measure(plugin=plugin, name='Test', status='Under test') measure.root_task = RootTask() # Be sure that there is no observers for the database assert_false(measure.root_task.task_database.has_observers('notifier')) monitor_decl = plugin.monitors[u'monitor1'] measure.add_monitor(monitor_decl.id, monitor_decl.factory(monitor_decl, self.workbench)) measure.add_monitor(monitor_decl.id, monitor_decl.factory(monitor_decl, self.workbench))
def test_run_checks3(self): """ Test running checks for a measure. Failing because of RootTask. """ plugin = self.workbench.get_plugin(u'hqc_meas.measure') measure = Measure(plugin=plugin) measure.root_task = RootTask() # Needed because of Atom returning a _DictProxy measure.checks = dict(plugin.checks) Checker.test_pass = True res, errors = measure.run_checks(self.workbench) assert_false(res) assert_in(u'internal', errors) assert_not_in(u'check1', errors)
def test_save_load_measure1(self): """ Test saving a measure to a file and reloading it. """ plugin = self.workbench.get_plugin(u'hqc_meas.measure') measure = Measure(plugin=plugin, name='Test', status='Under test') measure.root_task = RootTask(default_path=self.test_dir) # Needed because of Atom returning a _DictProxy measure.checks = dict(plugin.checks) # Needed because of Atom returning a _DictProxy measure.headers = dict(plugin.headers) # Adding a monitor. monitor_decl = plugin.monitors[u'monitor1'] measure.add_monitor(monitor_decl.id, monitor_decl.factory(monitor_decl, self.workbench)) measure.monitors[u'monitor1'].save_test = True path = os.path.join(self.test_dir, 'saved_measure.ini') # Save measure. measure.save_measure(path) assert_true(os.path.isfile(path)) # Load measure. loaded = Measure.load_measure(plugin, path) assert_equal(loaded.name, 'Test') assert_equal(loaded.root_task.default_path, self.test_dir) assert_equal(loaded.checks, dict(plugin.checks)) assert_equal(loaded.headers, dict(plugin.headers)) assert_in(u'monitor1', loaded.monitors) monitor = loaded.monitors[u'monitor1'] assert_true(monitor.save_test) # Check that all values have been correctly updated. monitor = measure.monitors[u'monitor1'] assert_equal(monitor.measure_name, measure.name) assert_equal(monitor.measure_status, measure.status) assert_equal(monitor.updated, {'root/default_path': 1}) assert_equal(measure.collect_entries_to_observe(), ['root/default_path']) # Check that the notifier is correctly observed. assert_true(measure.root_task.task_database.has_observers('notifier'))
def test_giving_root1(): # Test assembling a hierarchy and giving it a root task only later. root = RootTask() task1 = ComplexTask(task_name='task1') task2 = ComplexTask(task_name='task2') task1.children_task.append(task2) task3 = ComplexTask(task_name='task3') task2.children_task.append(task3) task4 = SimpleTask(task_name='task4', task_database_entries={'val2': 'r'}) task3.children_task.append(task4) task3.access_exs = ['task4_val2'] task2.access_exs = ['task4_val2'] root.children_task.append(task1) assert_equal(task2.get_from_database('task4_val2'), 'r') task3.children_task = []