From c74a829e8bc55715915011bc011b50e2e467489f Mon Sep 17 00:00:00 2001 From: Kountouris Panagiotis Date: Tue, 30 Oct 2018 09:50:00 +0100 Subject: [PATCH 1/4] Fix logger deprecation warnings `warn()` is deprecated and needs to be substituted with `warning()`. This commit fixes this issue. --- exopy/app/icons/plugin.py | 2 +- exopy/app/log/plugin.py | 6 +++--- exopy/instruments/plugin.py | 6 +++--- exopy/measurement/monitors/text_monitor/plugin.py | 4 ++-- exopy/measurement/workspace/workspace.py | 6 +++--- exopy/tasks/plugin.py | 2 +- tests/app/log/test_tools.py | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/exopy/app/icons/plugin.py b/exopy/app/icons/plugin.py index b0088aac..c6ec105e 100644 --- a/exopy/app/icons/plugin.py +++ b/exopy/app/icons/plugin.py @@ -112,7 +112,7 @@ def get_icon(self, icon_id): msg = msg % (self.fallback_theme, icon_id) logger = logging.getLogger(__name__) - logger.warn(msg) + logger.warning(msg) return icon diff --git a/exopy/app/log/plugin.py b/exopy/app/log/plugin.py index 25b7fff7..c41c98fa 100644 --- a/exopy/app/log/plugin.py +++ b/exopy/app/log/plugin.py @@ -141,7 +141,7 @@ def add_filter(self, id, filter, handler_id): """ if not hasattr(filter, 'filter'): logger = logging.getLogger(__name__) - logger.warn('Filter does not implemet a filter method') + logger.warning('Filter does not implemet a filter method') return handlers = self._handlers @@ -154,7 +154,7 @@ def add_filter(self, id, filter, handler_id): else: logger = logging.getLogger(__name__) - logger.warn('Handler {} does not exist') + logger.warning('Handler {} does not exist') def remove_filter(self, id): """Remove the specified filter. @@ -192,7 +192,7 @@ def set_formatter(self, handler_id, formatter): else: logger = logging.getLogger(__name__) - logger.warn('Handler {} does not exist') + logger.warning('Handler {} does not exist') # ---- Private API -------------------------------------------------------- diff --git a/exopy/instruments/plugin.py b/exopy/instruments/plugin.py index b2bb916c..5e9554fe 100644 --- a/exopy/instruments/plugin.py +++ b/exopy/instruments/plugin.py @@ -272,7 +272,7 @@ def create_settings(self, settings_id, infos, read_only=False): """ if settings_id is None: msg = 'No id was found for the settings whose infos are %s' - logger.warn(msg, infos) + logger.warning(msg, infos) return None s_decl = self._settings.contributions[settings_id] sett = s_decl.new(self.workbench, infos, read_only) @@ -483,9 +483,9 @@ def _refresh_profiles(self): if res: profiles[name] = i else: - logger.warn(msg) + logger.warning(msg) else: - logger.warn('{} is not a valid directory'.format(path)) + logger.warning('{} is not a valid directory'.format(path)) self._profiles = profiles diff --git a/exopy/measurement/monitors/text_monitor/plugin.py b/exopy/measurement/monitors/text_monitor/plugin.py index 59e88fa2..28bfbd26 100644 --- a/exopy/measurement/monitors/text_monitor/plugin.py +++ b/exopy/measurement/monitors/text_monitor/plugin.py @@ -115,7 +115,7 @@ def build_rule(self, name_or_config): config['id'] = name_or_config else: msg = 'Requested rule not found : {}'.format(name_or_config) - logger.warn(msg) + logger.warning(msg) return else: @@ -130,7 +130,7 @@ def build_rule(self, name_or_config): else: msg = 'Requested rule class not found : {}'.format(class_id) - logger.warn(msg) + logger.warning(msg) def get_rule_type(self, rule_type_id): """Access the class corresponding to a given id. diff --git a/exopy/measurement/workspace/workspace.py b/exopy/measurement/workspace/workspace.py index 4170ee00..edcb69e5 100644 --- a/exopy/measurement/workspace/workspace.py +++ b/exopy/measurement/workspace/workspace.py @@ -497,21 +497,21 @@ def _attach_default_tools(self, measurement): measurement.add_tool('pre-hook', pre_id) else: msg = "Default pre-execution hook {} not found" - logger.warn(msg.format(pre_id)) + logger.warning(msg.format(pre_id)) for monitor_id in self.plugin.default_monitors: if monitor_id in self.plugin.monitors: measurement.add_tool('monitor', monitor_id) else: msg = "Default monitor {} not found." - logger.warn(msg.format(monitor_id)) + logger.warning(msg.format(monitor_id)) for post_id in self.plugin.default_post_hooks: if post_id in self.plugin.post_hooks: measurement.add_tool('post-hook', post_id) else: msg = "Default post-execution hook {} not found" - logger.warn(msg.format(post_id)) + logger.warning(msg.format(post_id)) def _insert_new_edition_panels(self, measurements, update=True, panels=None): diff --git a/exopy/tasks/plugin.py b/exopy/tasks/plugin.py index 33282b2f..6f854615 100644 --- a/exopy/tasks/plugin.py +++ b/exopy/tasks/plugin.py @@ -403,7 +403,7 @@ def _refresh_templates(self): templates[name] = template_path else: logger = logging.getLogger(__name__) - logger.warn('{} is not a valid directory'.format(path)) + logger.warning('{} is not a valid directory'.format(path)) self.templates = templates diff --git a/tests/app/log/test_tools.py b/tests/app/log/test_tools.py index e1eaae7d..e0085fae 100644 --- a/tests/app/log/test_tools.py +++ b/tests/app/log/test_tools.py @@ -58,7 +58,7 @@ def assert_text(): exopy_qtbot.wait_until(assert_text) model.clean_text() - logger.warn('test') + logger.warning('test') def assert_text(): assert model.text == 'WARNING: test\n' From e4949b5d2191601a2706b7ba385ab3c74c733fea Mon Sep 17 00:00:00 2001 From: MatthieuDartiailh Date: Mon, 5 Nov 2018 19:49:13 -0500 Subject: [PATCH 2/4] utils: fix getargspec deprecation warning Replacing getargspec by getfullargspec fix the issue and does not require any other change. --- exopy/utils/atom_util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exopy/utils/atom_util.py b/exopy/utils/atom_util.py index 03f2250a..82066cf4 100644 --- a/exopy/utils/atom_util.py +++ b/exopy/utils/atom_util.py @@ -16,7 +16,7 @@ from textwrap import fill from atom.api import Str, Unicode, Enum, Atom, Constant -from inspect import getargspec +from inspect import getfullargspec from inspect import cleandoc # String identifing the preference tag @@ -107,7 +107,7 @@ def member_from_pref(obj, member, val): # If the user provided a custom "from_pref" function, then we check # that it has the correct signature and use it to obtain the value elif (isinstance(meta_value, (tuple, list)) and - len(getargspec(meta_value[FROM_PREF_ID])[0]) == 3): + len(getfullargspec(meta_value[FROM_PREF_ID])[0]) == 3): value = meta_value[FROM_PREF_ID](obj, member, val) elif meta_value is False: @@ -162,7 +162,7 @@ def member_to_pref(obj, member, val): # If the user provided a custom "to_pref" function, then we check # that it has the correct signature and use it to obtain the value elif (isinstance(meta_value, (tuple, list)) and - len(getargspec(meta_value[TO_PREF_ID])[0]) == 3): + len(getfullargspec(meta_value[TO_PREF_ID])[0]) == 3): pref_value = meta_value[TO_PREF_ID](obj, member, val) elif meta_value is False: From beae4d4939ca1134255eb3a122b304b261123603 Mon Sep 17 00:00:00 2001 From: MatthieuDartiailh Date: Mon, 5 Nov 2018 19:50:01 -0500 Subject: [PATCH 3/4] tests: specify pytest_plugin only in top level conftest --- docs/source/dev_guide/testing.rst | 6 +++--- tests/conftest.py | 8 +++++++- tests/instruments/conftest.py | 4 +--- tests/measurement/conftest.py | 2 -- tests/measurement/monitors/text_monitor/conftest.py | 3 --- .../monitors/text_monitor/rules/test_edition.py | 3 --- tests/measurement/monitors/text_monitor/rules/test_std.py | 4 ---- tests/measurement/monitors/text_monitor/test_custom.py | 3 --- tests/measurement/monitors/text_monitor/test_manifest.py | 4 ---- tests/measurement/monitors/text_monitor/test_monitor.py | 3 --- tests/measurement/monitors/text_monitor/test_plugin.py | 3 --- tests/measurement/workspace/test_workspace.py | 5 +---- tests/tasks/conftest.py | 2 -- tests/tasks/tasks/test_base_views.py | 3 --- tests/tasks/tasks/test_instr_view.py | 2 -- tests/test___main__.py | 3 --- 16 files changed, 12 insertions(+), 46 deletions(-) diff --git a/docs/source/dev_guide/testing.rst b/docs/source/dev_guide/testing.rst index e0bc342f..7a3389f2 100644 --- a/docs/source/dev_guide/testing.rst +++ b/docs/source/dev_guide/testing.rst @@ -147,9 +147,9 @@ package. .. note:: If a fixture is defined in a fixtures.py module, one should add a - 'pytest_plugin' variable at the top of the test module with a list of all - the module containing fixtures to load (modules should be specified using - their full path). + 'pytest_plugin' variable to the top level conftest.py file with a list of + all the module containing fixtures to load (modules should be specified + using their full path). ex : pytest_plugins = [str('exopy.testing.instruments.fixtures')] diff --git a/tests/conftest.py b/tests/conftest.py index 949238c9..838acfda 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,4 +13,10 @@ from enaml.qt import QT_API os.environ.setdefault('PYTEST_QT_API', QT_API) -pytest_plugins = str('exopy.testing.fixtures'), +pytest_plugins = ('exopy.testing.fixtures', + 'exopy.testing.instruments.fixtures', + 'exopy.testing.measurement.fixtures', + 'exopy.testing.measurement.workspace.fixtures', + 'exopy.testing.measurement.monitors.text_monitor.fixtures', + 'exopy.testing.tasks.fixtures') + diff --git a/tests/instruments/conftest.py b/tests/instruments/conftest.py index 17622472..7e1c51d7 100644 --- a/tests/instruments/conftest.py +++ b/tests/instruments/conftest.py @@ -11,8 +11,8 @@ """ import os -import pytest import enaml +import pytest from configobj import ConfigObj with enaml.imports(): @@ -20,8 +20,6 @@ from exopy.testing.instruments.util import add_profile -pytest_plugins = str('exopy.testing.instruments.fixtures'), - PROFILE_PATH = os.path.join(os.path.dirname(__file__), 'fp.instr.ini') diff --git a/tests/measurement/conftest.py b/tests/measurement/conftest.py index 464a4ef6..7981aa9d 100644 --- a/tests/measurement/conftest.py +++ b/tests/measurement/conftest.py @@ -9,5 +9,3 @@ """Fixture for testing the measurement plugin. """ - -pytest_plugins = str('exopy.testing.measurement.fixtures'), diff --git a/tests/measurement/monitors/text_monitor/conftest.py b/tests/measurement/monitors/text_monitor/conftest.py index 6e64a0b3..c8c94093 100644 --- a/tests/measurement/monitors/text_monitor/conftest.py +++ b/tests/measurement/monitors/text_monitor/conftest.py @@ -9,6 +9,3 @@ """Load common fixture used to test text monitor capabilities. """ - -pytest_plugins = str('exopy.testing.measurement.' - 'monitors.text_monitor.fixtures'), diff --git a/tests/measurement/monitors/text_monitor/rules/test_edition.py b/tests/measurement/monitors/text_monitor/rules/test_edition.py index 85fd2ff8..5d61480e 100644 --- a/tests/measurement/monitors/text_monitor/rules/test_edition.py +++ b/tests/measurement/monitors/text_monitor/rules/test_edition.py @@ -21,9 +21,6 @@ import CreateRuleDialog, EditRulesView -pytest_plugins = str('exopy.testing.measurement.' - 'monitors.text_monitor.fixtures'), - PLUGIN_ID = 'exopy.measurement.monitors.text_monitor' diff --git a/tests/measurement/monitors/text_monitor/rules/test_std.py b/tests/measurement/monitors/text_monitor/rules/test_std.py index 33154a63..c4bcd6b3 100644 --- a/tests/measurement/monitors/text_monitor/rules/test_std.py +++ b/tests/measurement/monitors/text_monitor/rules/test_std.py @@ -22,10 +22,6 @@ from exopy.testing.windows import ContainerTestingWindow -pytest_plugins = str('exopy.testing.measurement.' - 'monitors.text_monitor.fixtures'), - - @pytest.fixture def plugin(text_monitor_workbench): """Text monitor plugin. diff --git a/tests/measurement/monitors/text_monitor/test_custom.py b/tests/measurement/monitors/text_monitor/test_custom.py index 221739a3..4da178c1 100644 --- a/tests/measurement/monitors/text_monitor/test_custom.py +++ b/tests/measurement/monitors/text_monitor/test_custom.py @@ -19,9 +19,6 @@ from exopy.measurement.monitors.text_monitor.custom_entry_edition\ import EntryDialog -pytest_plugins = str('exopy.testing.measurement.' - 'monitors.text_monitor.fixtures'), - @pytest.fixture def monitor(text_monitor_workbench): diff --git a/tests/measurement/monitors/text_monitor/test_manifest.py b/tests/measurement/monitors/text_monitor/test_manifest.py index a314a5e2..a904c12c 100644 --- a/tests/measurement/monitors/text_monitor/test_manifest.py +++ b/tests/measurement/monitors/text_monitor/test_manifest.py @@ -19,10 +19,6 @@ import TextMonitorEdit, TextMonitorItem -pytest_plugins = str('exopy.testing.measurement.' - 'monitors.text_monitor.fixtures') - - def test_text_monitor_declration_functions(text_monitor_workbench, exopy_qtbot): """Test that we can create a monitor and its views. diff --git a/tests/measurement/monitors/text_monitor/test_monitor.py b/tests/measurement/monitors/text_monitor/test_monitor.py index c9660618..30510c7c 100644 --- a/tests/measurement/monitors/text_monitor/test_monitor.py +++ b/tests/measurement/monitors/text_monitor/test_monitor.py @@ -25,9 +25,6 @@ from exopy.measurement.monitors.text_monitor.monitor_views\ import (TextMonitorItem, TextMonitorEdit) -pytest_plugins = str('exopy.testing.measurement.' - 'monitors.text_monitor.fixtures'), - @pytest.fixture def monitor(text_monitor_workbench): diff --git a/tests/measurement/monitors/text_monitor/test_plugin.py b/tests/measurement/monitors/text_monitor/test_plugin.py index 40c4f302..4780e5e6 100644 --- a/tests/measurement/monitors/text_monitor/test_plugin.py +++ b/tests/measurement/monitors/text_monitor/test_plugin.py @@ -20,9 +20,6 @@ with enaml.imports(): from .contributed_rules import RulesManifest -pytest_plugins = str('exopy.testing.measurement.' - 'monitors.text_monitor.fixtures') - @pytest.fixture def text_monitor_plugin(text_monitor_workbench): diff --git a/tests/measurement/workspace/test_workspace.py b/tests/measurement/workspace/test_workspace.py index b33c7550..73bc5367 100644 --- a/tests/measurement/workspace/test_workspace.py +++ b/tests/measurement/workspace/test_workspace.py @@ -23,9 +23,6 @@ from exopy.testing.measurement.contributions import Flags -pytest_plugins = str('exopy.testing.measurement.workspace.fixtures'), - - @pytest.yield_fixture def workspace(exopy_qtbot, measurement_workbench, measurement): """Create a measurement workspace. @@ -169,7 +166,7 @@ def assert_ui(): @pytest.mark.timeout(30) -def test_creating_saving_loading_measurement(exopy_qtbot, workspace, +def test_creating_saving_loading_measurement(exopy_qtbot, workspace, monkeypatch, tmpdir): """Test creating, saving, loading a measurement. diff --git a/tests/tasks/conftest.py b/tests/tasks/conftest.py index 9b807dcf..8eaabea8 100644 --- a/tests/tasks/conftest.py +++ b/tests/tasks/conftest.py @@ -9,5 +9,3 @@ """Fixture for testing the task manager plugin. """ - -pytest_plugins = str('exopy.testing.tasks.fixtures'), diff --git a/tests/tasks/tasks/test_base_views.py b/tests/tasks/tasks/test_base_views.py index a6dbf5f6..7b50dfaf 100644 --- a/tests/tasks/tasks/test_base_views.py +++ b/tests/tasks/tasks/test_base_views.py @@ -24,9 +24,6 @@ from exopy.testing.util import show_widget, handle_dialog, get_window -pytest_plugins = str('exopy.testing.tasks.fixtures'), - - @pytest.mark.ui def test_root_path_edition(exopy_qtbot, task_workbench, dialog_sleep, monkeypatch): diff --git a/tests/tasks/tasks/test_instr_view.py b/tests/tasks/tasks/test_instr_view.py index 1e9aa13d..a14327ff 100644 --- a/tests/tasks/tasks/test_instr_view.py +++ b/tests/tasks/tasks/test_instr_view.py @@ -27,8 +27,6 @@ from .instrument_contributor import InstrContributor -pytest_plugins = str('exopy.testing.instruments.fixtures'), - PROFILE_PATH = os.path.join(os.path.dirname(__file__), 'fp.instr.ini') diff --git a/tests/test___main__.py b/tests/test___main__.py index f3dbcd80..a945f0aa 100644 --- a/tests/test___main__.py +++ b/tests/test___main__.py @@ -16,9 +16,6 @@ from exopy.testing.util import handle_dialog -pytest_plugins = str('exopy.testing.fixtures'), - - def test_parser_add_argument(): """Test adding an argument to the parser. From 1c292b1f355b30250bc7a73219a00c307497872c Mon Sep 17 00:00:00 2001 From: MatthieuDartiailh Date: Mon, 5 Nov 2018 19:53:35 -0500 Subject: [PATCH 4/4] tests: fix remaining pytest warnings Also consolidate tests, and prevent the use of too many file descriptors to allow the tests to run on OSX. --- CHANGES | 2 +- exopy/testing/util.py | 4 +-- .../connections/test_visa_connections.py | 3 ++ .../engines/test_process_engine.py | 35 +++++++++---------- tests/measurement/test_plugin.py | 14 +++++--- .../workspace/test_measurement_edition.py | 9 ++--- .../workspace/test_measurement_execution.py | 16 +++++---- .../workspace/test_measurement_tracking.py | 14 ++++---- .../tasks/logic/test_conditional_task.py | 9 +++++ .../tasks/logic/test_loop_exceptions_tasks.py | 10 ++++++ tests/tasks/tasks/logic/test_loop_task.py | 17 +++++---- tests/tasks/tasks/logic/test_while_task.py | 8 +++++ tests/tasks/tasks/test_execution.py | 10 ++++++ tests/tasks/tasks/test_validators.py | 8 +++-- .../tasks/tasks/util/test_definition_task.py | 9 +++++ tests/tasks/tasks/util/test_formula_task.py | 9 +++++ tests/tasks/tasks/util/test_log_task.py | 9 +++++ tests/tasks/tasks/util/test_sleep_task.py | 9 +++++ 18 files changed, 141 insertions(+), 54 deletions(-) diff --git a/CHANGES b/CHANGES index 57b9c084..7db4b035 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,5 @@ Exopy Changelog -============== +=============== 0.2.0 - unreleased diff --git a/exopy/testing/util.py b/exopy/testing/util.py index 320da734..67258dce 100644 --- a/exopy/testing/util.py +++ b/exopy/testing/util.py @@ -233,10 +233,10 @@ def __init__(self, bot, cls, handler, op, skip_answer): def __call__(self): self.called = True - from .fixtures import dialog_sleep + from .fixtures import DIALOG_SLEEP dial = get_window(self.bot, cls=self.cls) wait_for_window_displayed(self.bot, dial) - self.bot.wait(dialog_sleep()) + self.bot.wait(DIALOG_SLEEP) obs = EventObserver() dial.observe('finished', obs.callback) diff --git a/tests/instruments/connections/test_visa_connections.py b/tests/instruments/connections/test_visa_connections.py index 2078eee2..35978e41 100644 --- a/tests/instruments/connections/test_visa_connections.py +++ b/tests/instruments/connections/test_visa_connections.py @@ -9,6 +9,8 @@ """Test for the Visa connections. """ +import logging + import enaml from exopy.testing.util import show_widget, wait_for_destruction @@ -139,6 +141,7 @@ def test_creating_a_visa_connection(prof_plugin, exopy_qtbot, caplog): """Test creating a Visa connection through VisaConnection.new """ + caplog.set_level(logging.INFO) c = prof_plugin.create_connection('VisaTCPIP', {'__junk': ''}, True) w = show_widget(exopy_qtbot, c) assert caplog.records diff --git a/tests/measurement/engines/test_process_engine.py b/tests/measurement/engines/test_process_engine.py index bf5a96c3..f7baa06c 100644 --- a/tests/measurement/engines/test_process_engine.py +++ b/tests/measurement/engines/test_process_engine.py @@ -9,18 +9,19 @@ """Test process engine functionalities. """ +import gc import socket from threading import Thread from time import sleep -import pytest import enaml -from atom.api import Value, Bool, Unicode +import pytest +from atom.api import Bool, Unicode, Value from exopy.measurement.engines.api import ExecutionInfos +from exopy.measurement.engines.process_engine.subprocess import TaskProcess from exopy.tasks.api import RootTask, SimpleTask from exopy.tasks.infos import TaskInfos -from exopy.measurement.engines.process_engine.subprocess import TaskProcess with enaml.imports(): from exopy.measurement.engines.process_engine.engine_declaration import\ @@ -29,9 +30,6 @@ from exopy.tasks.manifest import TasksManagerManifest -pytest_plugins = str('exopy.testing.measurement.workspace.fixtures'), - - class WaitingTask(SimpleTask): """Simple Task whose execution can be controlled using events. @@ -45,16 +43,15 @@ def check(self, *args, **kwargs): return self.check_flag, {'test': 1} def perform(self): - s = socket.socket() - while True: - if s.connect_ex(('localhost', self.sync_port)) == 0: - break - sleep(0.01) - s.sendall(self.sock_id.encode('utf-8')) - s.recv(4096) - s.sendall('Waiting'.encode('utf-8')) - s.recv(4096) - s.close() + with socket.socket() as s: + while True: + if s.connect_ex(('localhost', self.sync_port)) == 0: + break + sleep(0.01) + s.sendall(self.sock_id.encode('utf-8')) + s.recv(4096) + s.sendall('Waiting'.encode('utf-8')) + s.recv(4096) class ExecThread(Thread): @@ -71,12 +68,14 @@ def run(self): self.value = self._engine.perform(self._exec_infos) -@pytest.fixture +@pytest.yield_fixture def process_engine(measurement_workbench): measurement_workbench.register(LogManifest()) measurement_workbench.register(TasksManagerManifest()) plugin = measurement_workbench.get_plugin('exopy.measurement') - return plugin.create('engine', 'exopy.process_engine') + yield plugin.create('engine', 'exopy.process_engine') + plugin.processor.engine = None + gc.collect() @pytest.yield_fixture diff --git a/tests/measurement/test_plugin.py b/tests/measurement/test_plugin.py index 9cc1dd1e..7efe453f 100644 --- a/tests/measurement/test_plugin.py +++ b/tests/measurement/test_plugin.py @@ -14,6 +14,8 @@ import pytest import enaml +from exopy.measurement.measurement import Measurement +from exopy.tasks.api import RootTask from exopy.testing.util import set_preferences, ErrorDialogException with enaml.imports(): @@ -134,14 +136,16 @@ def test_handling_not_found_default_tools(measurement_workbench): measurement_workbench.get_plugin('exopy.measurement') -def test_find_next_measurement(measurement_workbench): +def test_find_next_measurement(measurement_workbench, measurement): """Test finding the next valid measurement in the queue. """ - from exopy.testing.measurement.fixtures import measurement - m1 = measurement(measurement_workbench) - m2 = measurement(measurement_workbench) - m3 = measurement(measurement_workbench) + plugin = measurement_workbench.get_plugin('exopy.measurement') + m1 = measurement + m2 = Measurement(plugin=plugin, root_task=RootTask(), + name='Dummy', id='002') + m3 = Measurement(plugin=plugin, root_task=RootTask(), + name='Dummy', id='003') plugin = measurement_workbench.get_plugin('exopy.measurement') plugin.enqueued_measurements.add(m1) plugin.enqueued_measurements.add(m2) diff --git a/tests/measurement/workspace/test_measurement_edition.py b/tests/measurement/workspace/test_measurement_edition.py index 0b6cd2c3..398f3559 100644 --- a/tests/measurement/workspace/test_measurement_edition.py +++ b/tests/measurement/workspace/test_measurement_edition.py @@ -12,7 +12,6 @@ import pytest import enaml -from exopy.testing.measurement.fixtures import measurement as m_build from exopy.testing.util import (handle_dialog, wait_for_window_displayed, wait_for_destruction, handle_question) from exopy.tasks.tasks.logic.loop_exceptions_tasks import BreakTask @@ -28,9 +27,6 @@ from exopy.utils.widgets.qt_tree_menu import CutAction -pytest_plugins = str('exopy.testing.measurement.workspace.fixtures'), - - @pytest.fixture def edition_view(measurement, workspace, exopy_qtbot): """Start plugins and add measurements before creating the execution view. @@ -226,7 +222,8 @@ def assert_tab(): exopy_qtbot.wait(10 + dialog_sleep) -def test_switching_the_linked_measurement(exopy_qtbot, edition_view, dialog_sleep): +def test_switching_the_linked_measurement(exopy_qtbot, measurement, + edition_view, dialog_sleep): """Test changing the measurement edited by the editor. """ @@ -236,7 +233,7 @@ def test_switching_the_linked_measurement(exopy_qtbot, edition_view, dialog_slee ed = edition_view.widget.dock_widget().widgets()[0] - ed.measurement = m_build(ed.workspace.workbench) + ed.measurement = measurement def assert_selected(): tree = ed.widgets()[5] diff --git a/tests/measurement/workspace/test_measurement_execution.py b/tests/measurement/workspace/test_measurement_execution.py index 8f92e52d..1505cafa 100644 --- a/tests/measurement/workspace/test_measurement_execution.py +++ b/tests/measurement/workspace/test_measurement_execution.py @@ -12,7 +12,8 @@ import pytest import enaml -from exopy.testing.measurement.fixtures import measurement as m_build +from exopy.measurement.measurement import Measurement +from exopy.tasks.api import RootTask from exopy.testing.util import (handle_dialog, wait_for_window_displayed, CallSpy) @@ -23,17 +24,16 @@ import MeasView, ExecutionDockItem -pytest_plugins = str('exopy.testing.measurement.workspace.fixtures'), - - @pytest.fixture def execution_view(measurement_workbench, workspace, exopy_qtbot): """Start plugins and add measurements before creating the execution view. """ pl = measurement_workbench.get_plugin('exopy.measurement') - pl.enqueued_measurements.add(m_build(measurement_workbench)) - pl.enqueued_measurements.add(m_build(measurement_workbench)) + pl.enqueued_measurements.add(Measurement(plugin=pl, root_task=RootTask(), + name='Dummy', id='001')) + pl.enqueued_measurements.add(Measurement(plugin=pl, root_task=RootTask(), + name='Dummy', id='002')) pl.enqueued_measurements.measurements[1].name = 'dummy_test' pl.selected_engine = 'dummy' engine = pl.create('engine', pl.selected_engine) @@ -383,7 +383,9 @@ def assert_visible(): assert en_stat.visible exopy_qtbot.wait_until(assert_visible) - assert en_stat.widgets()[1].text == 'Stopped' + def assert_status(): + assert en_stat.widgets()[1].text == 'Stopped' + exopy_qtbot.wait_until(assert_status) meas = item.workspace.plugin.enqueued_measurements.measurements[0] item.workspace.plugin.processor.running_measurement = meas diff --git a/tests/measurement/workspace/test_measurement_tracking.py b/tests/measurement/workspace/test_measurement_tracking.py index e4f11d1d..4fe329a3 100644 --- a/tests/measurement/workspace/test_measurement_tracking.py +++ b/tests/measurement/workspace/test_measurement_tracking.py @@ -17,17 +17,15 @@ from atom.api import Value from enaml.core.object import Object +from exopy.measurement.measurement import Measurement from exopy.measurement.workspace.measurement_tracking import MeasurementTracker -from exopy.testing.measurement.fixtures import measurement +from exopy.tasks.api import RootTask with enaml.imports(): from exopy.measurement.workspace.measurement_edition\ import MeasurementEditorDockItem -pytest_plugins = str('exopy.testing.measurement.fixtures'), - - class FalseObject(Object): """Object waiting for an event to yield its parents. @@ -56,13 +54,15 @@ def create_false_widget(measurement, event): @pytest.mark.timeout(10) -def test_measurement_tracker(measurement_workbench): +def test_measurement_tracker(measurement_workbench, measurement): """Test the measurement tracker. """ + plugin = measurement_workbench.get_plugin('exopy.measurement') tracker = MeasurementTracker() - meas1 = measurement(measurement_workbench) - meas2 = measurement(measurement_workbench) + meas1 = measurement + meas2 = Measurement(plugin=plugin, root_task=RootTask(), + name='Dummy', id='002') ev1 = Event() ev2 = Event() diff --git a/tests/tasks/tasks/logic/test_conditional_task.py b/tests/tasks/tasks/logic/test_conditional_task.py index 19154c68..7ca9a73f 100644 --- a/tests/tasks/tasks/logic/test_conditional_task.py +++ b/tests/tasks/tasks/logic/test_conditional_task.py @@ -9,6 +9,8 @@ """Test of the conditional task. """ +import gc + import pytest import enaml from multiprocessing import Event @@ -33,6 +35,13 @@ def setup(self): self.check = CheckTask(name='check') self.task.add_child_task(0, self.check) + def teardown(self): + del self.root.should_pause + del self.root.should_stop + # Ensure we collect the file descriptor of the events. Otherwise we can + # get funny errors on MacOS. + gc.collect() + def test_check1(self): """Test that everything is ok if condition is evaluable. diff --git a/tests/tasks/tasks/logic/test_loop_exceptions_tasks.py b/tests/tasks/tasks/logic/test_loop_exceptions_tasks.py index f75bdb50..862ac4f0 100644 --- a/tests/tasks/tasks/logic/test_loop_exceptions_tasks.py +++ b/tests/tasks/tasks/logic/test_loop_exceptions_tasks.py @@ -9,6 +9,8 @@ """Test of the loop exceptions tasks. """ +import gc + import pytest import enaml from multiprocessing import Event @@ -39,6 +41,14 @@ class TestExceptionTasks(object): def setup(self): self.root = RootTask(should_stop=Event(), should_pause=Event()) + def teardown(self): + del self.root.should_pause + del self.root.should_stop + # Ensure we collect the file descriptor of the events. Otherwise we can + # get funny errors on MacOS. + gc.collect() + + def test_check1(self, exception_task): """Test that everything is ok condition is evaluable and parent is a Loop. diff --git a/tests/tasks/tasks/logic/test_loop_task.py b/tests/tasks/tasks/logic/test_loop_task.py index 44f08e36..f9ef3514 100644 --- a/tests/tasks/tasks/logic/test_loop_task.py +++ b/tests/tasks/tasks/logic/test_loop_task.py @@ -9,6 +9,7 @@ """Test of the LoopTask. """ +import gc from multiprocessing import Event import pytest @@ -31,9 +32,6 @@ from exopy.tasks.tasks.base_views import RootTaskView -pytest_plugins = str('exopy.testing.tasks.fixtures'), - - @pytest.fixture def linspace_interface(request): """Fixture building a linspace interface. @@ -68,7 +66,7 @@ def test_linspace_handling_of_step_sign(monkeypatch, linspace_interface): """ monkeypatch.setattr(LoopTask, 'perform_loop', false_perform_loop) - root = RootTask(should_stop=Event(), should_pause=Event()) + root = RootTask() lt = LoopTask(name='Test') root.add_child_task(0, lt) @@ -92,7 +90,7 @@ def test_linspace_handling_of_rounding(monkeypatch, linspace_interface): """ monkeypatch.setattr(LoopTask, 'perform_loop', false_perform_loop) - root = RootTask(should_stop=Event(), should_pause=Event()) + root = RootTask() lt = LoopTask(name='Test') root.add_child_task(0, lt) @@ -135,7 +133,7 @@ def test_linspace_handling_of_non_matching_stop(monkeypatch, """ monkeypatch.setattr(LoopTask, 'perform_loop', false_perform_loop) - root = RootTask(should_stop=Event(), should_pause=Event()) + root = RootTask() lt = LoopTask(name='Test') root.add_child_task(0, lt) @@ -159,6 +157,13 @@ def setup(self): self.task = LoopTask(name='Test') self.root.add_child_task(0, self.task) + def teardown(self): + del self.root.should_pause + del self.root.should_stop + # Ensure we collect the file descriptor of the events. Otherwise we can + # get funny errors on MacOS. + gc.collect() + def test_subtask_handling(self): """Test adding, changing, removing the subtask. diff --git a/tests/tasks/tasks/logic/test_while_task.py b/tests/tasks/tasks/logic/test_while_task.py index 4fb78af9..492c6dfd 100644 --- a/tests/tasks/tasks/logic/test_while_task.py +++ b/tests/tasks/tasks/logic/test_while_task.py @@ -9,6 +9,7 @@ """Test of the WhileTask. """ +import gc from multiprocessing import Event import pytest @@ -38,6 +39,13 @@ def setup(self): self.check = CheckTask(name='check') self.task.add_child_task(0, self.check) + def teardown(self): + del self.root.should_pause + del self.root.should_stop + # Ensure we collect the file descriptor of the events. Otherwise we can + # get funny errors on MacOS. + gc.collect() + def test_check1(self): """Simply test that everything is ok if condition is evaluable. diff --git a/tests/tasks/tasks/test_execution.py b/tests/tasks/tasks/test_execution.py index ec3137ee..dc074c04 100644 --- a/tests/tasks/tasks/test_execution.py +++ b/tests/tasks/tasks/test_execution.py @@ -9,6 +9,7 @@ """test execution of tasks. """ +import gc import os import threading from multiprocessing import Event @@ -40,6 +41,15 @@ def setup(self): root.write_in_database('meas_id', '001') self.root = root + def teardown(self): + del self.root.should_pause + del self.root.should_stop + del self.root.paused + del self.root.resumed + # Ensure we collect the file descriptor of the events. Otherwise we can + # get funny errors on MacOS. + gc.collect() + def test_check_simple_task(self, tmpdir): """Test automatic testing of formatting and evaluating. diff --git a/tests/tasks/tasks/test_validators.py b/tests/tasks/tasks/test_validators.py index e7db5d4e..ebbda2e9 100644 --- a/tests/tasks/tasks/test_validators.py +++ b/tests/tasks/tasks/test_validators.py @@ -9,6 +9,7 @@ """Tests for the feval tagged members fields validators. """ +import gc import numbers from multiprocessing import Event @@ -20,7 +21,7 @@ from exopy.testing.tasks.util import CheckTask -@pytest.fixture +@pytest.yield_fixture def task(): """Create a task to test the validators. @@ -35,7 +36,10 @@ class Tester(CheckTask): task = Tester(name='test', database_entries={'val': 1}) loop = LoopTask(name='Loop', task=task) root.add_child_task(0, loop) - return task + yield task + del root.should_pause + del root.should_stop + gc.collect() def test_base_validation(task): diff --git a/tests/tasks/tasks/util/test_definition_task.py b/tests/tasks/tasks/util/test_definition_task.py index 17c6735b..3ac7939d 100644 --- a/tests/tasks/tasks/util/test_definition_task.py +++ b/tests/tasks/tasks/util/test_definition_task.py @@ -9,6 +9,8 @@ """Test of the Definition task. """ +import gc + import pytest import enaml from multiprocessing import Event @@ -34,6 +36,13 @@ def setup(self): self.task = DefinitionTask(name='Test') self.root.add_child_task(0, self.task) + def teardown(self): + del self.root.should_pause + del self.root.should_stop + # Ensure we collect the file descriptor of the events. Otherwise we can + # get funny errors on MacOS. + gc.collect() + def test_perform1(self): """Test checking that the formatted definition gets written to the database diff --git a/tests/tasks/tasks/util/test_formula_task.py b/tests/tasks/tasks/util/test_formula_task.py index 0769d25e..b9fc040f 100644 --- a/tests/tasks/tasks/util/test_formula_task.py +++ b/tests/tasks/tasks/util/test_formula_task.py @@ -9,6 +9,8 @@ """Test of the Formula task. """ +import gc + import pytest import enaml from multiprocessing import Event @@ -32,6 +34,13 @@ def setup(self): self.task = FormulaTask(name='Test') self.root.add_child_task(0, self.task) + def teardown(self): + del self.root.should_pause + del self.root.should_stop + # Ensure we collect the file descriptor of the events. Otherwise we can + # get funny errors on MacOS. + gc.collect() + def test_perform1(self): """Test checking that the evaluated formula gets written to the database diff --git a/tests/tasks/tasks/util/test_log_task.py b/tests/tasks/tasks/util/test_log_task.py index f3f68511..09e81882 100644 --- a/tests/tasks/tasks/util/test_log_task.py +++ b/tests/tasks/tasks/util/test_log_task.py @@ -9,6 +9,8 @@ """Test of the Log task. """ +import gc + import pytest import enaml from multiprocessing import Event @@ -30,6 +32,13 @@ def setup(self): self.task = LogTask(name='Test') self.root.add_child_task(0, self.task) + def teardown(self): + del self.root.should_pause + del self.root.should_stop + # Ensure we collect the file descriptor of the events. Otherwise we can + # get funny errors on MacOS. + gc.collect() + def test_check1(self): """Test checking that a message that cannot be formatted will result in a fail diff --git a/tests/tasks/tasks/util/test_sleep_task.py b/tests/tasks/tasks/util/test_sleep_task.py index afb9278f..5a89a0f1 100644 --- a/tests/tasks/tasks/util/test_sleep_task.py +++ b/tests/tasks/tasks/util/test_sleep_task.py @@ -9,6 +9,8 @@ """Test of the Sleep task. """ +import gc + import pytest import enaml from multiprocessing import Event @@ -30,6 +32,13 @@ def setup(self): self.task = SleepTask(name='Test') self.root.add_child_task(0, self.task) + def teardown(self): + del self.root.should_pause + del self.root.should_stop + # Ensure we collect the file descriptor of the events. Otherwise we can + # get funny errors on MacOS. + gc.collect() + def test_check1(self): """ Test handling a correct string in the 'time' field