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 test_enqueue_measure1(self):
        # Test enqueueing a measure passing the tests using no instruments.

        core = self.workbench.get_plugin(u'enaml.workbench.core')
        cmd = u'enaml.workbench.ui.select_workspace'
        core.invoke_command(cmd, {'workspace': u'hqc_meas.measure.workspace'},
                            self)

        plugin = self.workbench.get_plugin(u'hqc_meas.measure')

        measure = Measure(plugin=plugin, name='Test')
        measure.root_task = RootTask(default_path=self.test_dir)
        plugin.edited_measure = measure

        res = plugin.workspace.enqueue_measure(plugin.edited_measure)

        assert_true(res)
        assert_false(measure.root_task.run_time)
        assert_true(plugin.enqueued_measures)
        en_meas = plugin.enqueued_measures[0]
        assert_is_not(en_meas, measure)
        assert_equal(en_meas.status, 'READY')
        assert_equal(en_meas.infos,
                     'The measure is ready to be performed by an engine.')
        assert_in('build_deps', en_meas.store)
        assert_not_in('profiles', en_meas.store)
    def test_enqueue_measure4(self):
        # Test enqueueing a measure passing the tests using instruments.

        core = self.workbench.get_plugin(u'enaml.workbench.core')
        cmd = u'enaml.workbench.ui.select_workspace'
        core.invoke_command(cmd, {'workspace': u'hqc_meas.measure.workspace'},
                            self)

        plugin = self.workbench.get_plugin(u'hqc_meas.measure')

        false_instr_user = FalseInstrTask(selected_profile='  dummy  ',
                                          selected_driver='PanelTestDummy')
        measure = Measure(plugin=plugin, name='Test')
        measure.root_task = RootTask(default_path=self.test_dir)
        measure.root_task.children_task = [false_instr_user]
        plugin.edited_measure = measure

        res = plugin.workspace.enqueue_measure(plugin.edited_measure)

        assert_true(res)
        assert_false(measure.root_task.run_time)
        assert_true(plugin.enqueued_measures)
        en_meas = plugin.enqueued_measures[0]
        assert_is_not(en_meas, measure)
        assert_equal(en_meas.status, 'READY')
        assert_equal(en_meas.infos,
                     'The measure is ready to be performed by an engine.')
        assert_in('build_deps', en_meas.store)
        assert_equal(['  dummy  '], en_meas.store['profiles'])
        assert_in('drivers', en_meas.root_task.run_time)

        instr_plugin = self.workbench.get_plugin('hqc_meas.instr_manager')
        assert_in('  dummy  ', instr_plugin.available_profiles)
    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')
Exemple #5
0
    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 test_plugin_find_next_measure1(self):
        """ Test plugin.find_next_measure, first measure is ok.

        """
        plugin = self.workbench.get_plugin(u'hqc_meas.measure')
        measure = Measure(plugin=plugin, name='Test')
        measure.root_task = RootTask()
        plugin.enqueued_measures.append(measure)

        meas = plugin.find_next_measure()
        assert_is(measure, meas)
    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_setting_state(self):
        """ Test entering the edition state for a measure.

        """
        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))

        assert_true(measure.root_task.task_database.has_observers('notifier'))

        measure.enter_running_state()

        assert_false(measure.root_task.task_database.has_observers('notifier'))

        measure.enter_edition_state()

        assert_true(measure.root_task.task_database.has_observers('notifier'))
    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_run_checks1(self):
        """ Test running checks for a measure. Passing.

        """
        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 = True
        res, errors = measure.run_checks(self.workbench)

        assert_true(res)
        assert_equal(errors, {})
    def _create_measure(self, plugin):
        """ Create a measure.

        """
        measure = Measure(plugin=plugin, name='Test1')
        measure.root_task = RootTask(default_path=self.test_dir)
        children = [SleepTask(task_name='sleep1', time=1),
                    LogTask(task_name='print', message='test'),
                    SleepTask(task_name='sleep2', time=0.1)]
        measure.root_task.children_task.extend(children)
        measure.status = 'READY'
        monitor_decl = plugin.monitors[u'monitor1']
        measure.add_monitor(monitor_decl.id,
                            monitor_decl.factory(monitor_decl,
                                                 self.workbench))
        return measure
Exemple #12
0
    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 _create_measure(self, plugin, instr=False):
        """ Create a measure.

        """
        measure = Measure(plugin=plugin, name='Test1')
        measure.root_task = RootTask(default_path=self.test_dir)
        if instr:
            false_instr_user = FalseInstrTask(selected_profile='  dummy  ',
                                              selected_driver='PanelTestDummy')
            measure.root_task.children_task = [false_instr_user]
        measure.status = 'READY'
        monitor_decl = plugin.monitors[u'monitor1']
        measure.add_monitor(monitor_decl.id,
                            monitor_decl.factory(monitor_decl,
                                                 self.workbench))
        return measure
    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')
Exemple #15
0
    def test_run_checks1(self):
        """ Test running checks for a measure. Passing.

        """
        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 = True
        res, errors = measure.run_checks(self.workbench)

        assert_true(res)
        assert_equal(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_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)
Exemple #18
0
    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_measure_editor_dialog2(self):
        # Test that everything goes well in the absence of build_deps
        core = self.workbench.get_plugin(u'enaml.workbench.core')
        cmd = u'enaml.workbench.ui.select_workspace'
        core.invoke_command(cmd, {'workspace': u'hqc_meas.measure.workspace'},
                            self)
        plugin = self.workbench.get_plugin(u'hqc_meas.measure')

        measure = Measure(plugin=plugin, name='Test')
        measure.root_task = RootTask()

        ed = MeasureEditorDialog(measure=measure, workspace=plugin.workspace)
        ed.show()
        process_app_events()
        ed.close()
        process_app_events()
        assert_not_in('build_deps', measure.store)
        close_all_windows()
    def test_measure_editor_dialog1(self):
        # Test that the build_deps are correctly destroyed when closing.
        core = self.workbench.get_plugin(u'enaml.workbench.core')
        cmd = u'enaml.workbench.ui.select_workspace'
        core.invoke_command(cmd, {'workspace': u'hqc_meas.measure.workspace'},
                            self)
        plugin = self.workbench.get_plugin(u'hqc_meas.measure')

        measure = Measure(plugin=plugin, name='Test')
        measure.root_task = RootTask()
        measure.store['build_deps'] = 25

        ed = MeasureEditorDialog(measure=measure, workspace=plugin.workspace)
        ed.show()
        process_app_events()
        ed.close()
        process_app_events()
        assert_not_in('build_deps', measure.store)
        close_all_windows()
    def test_enqueue_measure2(self):
        # Test enqueueing a measure failing the tests using no instruments.

        core = self.workbench.get_plugin(u'enaml.workbench.core')
        cmd = u'enaml.workbench.ui.select_workspace'
        core.invoke_command(cmd, {'workspace': u'hqc_meas.measure.workspace'},
                            self)

        plugin = self.workbench.get_plugin(u'hqc_meas.measure')

        measure = Measure(plugin=plugin, name='Test')
        measure.root_task = RootTask()
        plugin.edited_measure = measure

        res = plugin.workspace.enqueue_measure(plugin.edited_measure)

        assert_false(res)
        assert_false(measure.root_task.run_time)
        assert_false(plugin.enqueued_measures)

        close_all_windows()
Exemple #22
0
    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 test_enqueue_measure3(self):
        # Test enqueueing a measure passing the test but emitting warnings.

        # As there is no event loop running the exec_ is not blocking.
        core = self.workbench.get_plugin(u'enaml.workbench.core')
        cmd = u'enaml.workbench.ui.select_workspace'
        core.invoke_command(cmd, {'workspace': u'hqc_meas.measure.workspace'},
                            self)

        plugin = self.workbench.get_plugin(u'hqc_meas.measure')

        measure = Measure(plugin=plugin, name='Test')
        measure.root_task = RootTask()
        plugin.edited_measure = measure

        res = plugin.workspace.enqueue_measure(plugin.edited_measure)

        assert_false(res)
        assert_false(measure.root_task.run_time)
        assert_false(plugin.enqueued_measures)

        close_all_windows()
Exemple #24
0
    def test_save_load_measure2(self):
        """ Test saving a measure to a file and reloading it with absent tools.

        """
        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))

        # Remove test_suite
        self.workbench.unregister(u'tests.suite')

        # 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, {})
        assert_equal(loaded.headers, {})
        assert_equal(loaded.monitors, {})

        self.workbench.register(TestSuiteManifest())
    def test_plugin_find_next_measure2(self):
        """ Test plugin.find_next_measure when measures should be skipped.

        """
        plugin = self.workbench.get_plugin(u'hqc_meas.measure')
        measure1 = Measure(plugin=plugin, name='Test1')
        measure1.root_task = RootTask()
        measure1.status = 'SKIPPED'
        plugin.enqueued_measures.append(measure1)

        measure2 = Measure(plugin=plugin, name='Test2')
        measure2.root_task = RootTask()
        measure2.status = 'EDITING'
        plugin.enqueued_measures.append(measure2)

        measure3 = Measure(plugin=plugin, name='Test3')
        measure3.root_task = RootTask()
        measure3.status = 'READY'
        plugin.enqueued_measures.append(measure3)

        meas = plugin.find_next_measure()
        assert_is(measure3, meas)
    def test_save_load_measure2(self):
        """ Test saving a measure to a file and reloading it with absent tools.

        """
        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))

        # Remove test_suite
        self.workbench.unregister(u'tests.suite')

        # 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, {})
        assert_equal(loaded.headers, {})
        assert_equal(loaded.monitors, {})

        self.workbench.register(TestSuiteManifest())
Exemple #27
0
    def test_setting_state(self):
        """ Test entering the edition state for a measure.

        """
        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))

        assert_true(measure.root_task.task_database.has_observers('notifier'))

        measure.enter_running_state()

        assert_false(measure.root_task.task_database.has_observers('notifier'))

        measure.enter_edition_state()

        assert_true(measure.root_task.task_database.has_observers('notifier'))
Exemple #28
0
    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))
Exemple #29
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')
Exemple #30
0
    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_plugin_find_next_measure3(self):
        """ Test plugin.find_next_measure when no measures can be sent.

        """
        plugin = self.workbench.get_plugin(u'hqc_meas.measure')
        measure1 = Measure(plugin=plugin, name='Test1')
        measure1.root_task = RootTask()
        measure1.status = 'SKIPPED'
        plugin.enqueued_measures.append(measure1)

        measure2 = Measure(plugin=plugin, name='Test2')
        measure2.root_task = RootTask()
        measure2.status = 'EDITING'
        plugin.enqueued_measures.append(measure2)

        meas = plugin.find_next_measure()
        assert_is(None, meas)
    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))
Exemple #33
0
    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'))
Exemple #34
0
    def test_remove_monitor1(self):
        """ Test removing a monitor.

        """
        plugin = self.workbench.get_plugin(u'hqc_meas.measure')
        measure = Measure(plugin=plugin, name='Test', status='Under test')
        measure.root_task = RootTask()

        test_obs = lambda change: False
        measure.root_task.task_database.observe('notifier', test_obs)

        monitor_decl = plugin.monitors[u'monitor1']
        measure.add_monitor(monitor_decl.id,
                            monitor_decl.factory(monitor_decl, self.workbench))
        measure.remove_monitor(u'monitor1')

        assert_not_in(u'monitor1', measure.monitors)

        # Check that the notifier is not observed anymore but that other
        # observers are not deleted.
        assert_true(measure.root_task.task_database.has_observers('notifier'))
        measure.root_task.task_database.unobserve('notifier', test_obs)
        assert_false(measure.root_task.task_database.has_observers('notifier'))
    def test_remove_monitor1(self):
        """ Test removing a monitor.

        """
        plugin = self.workbench.get_plugin(u'hqc_meas.measure')
        measure = Measure(plugin=plugin, name='Test', status='Under test')
        measure.root_task = RootTask()

        test_obs = lambda change: False
        measure.root_task.task_database.observe('notifier', test_obs)

        monitor_decl = plugin.monitors[u'monitor1']
        measure.add_monitor(monitor_decl.id,
                            monitor_decl.factory(monitor_decl,
                                                 self.workbench))
        measure.remove_monitor(u'monitor1')

        assert_not_in(u'monitor1', measure.monitors)

        # Check that the notifier is not observed anymore but that other
        # observers are not deleted.
        assert_true(measure.root_task.task_database.has_observers('notifier'))
        measure.root_task.task_database.unobserve('notifier', test_obs)
        assert_false(measure.root_task.task_database.has_observers('notifier'))
    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_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'], '[]')
Exemple #38
0
    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'], '[]')
Exemple #39
0
    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'))