Skip to content

Commit

Permalink
Merge pull request #160 from pakoun/pr/fix_logger_deprecation_warnings
Browse files Browse the repository at this point in the history
Fix pytest deprecation warnings
  • Loading branch information
MatthieuDartiailh committed Nov 6, 2018
2 parents 08df7f9 + 1c292b1 commit 67fd1d1
Show file tree
Hide file tree
Showing 42 changed files with 170 additions and 117 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Exopy Changelog
==============
===============


0.2.0 - unreleased
Expand Down
6 changes: 3 additions & 3 deletions docs/source/dev_guide/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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')]

Expand Down
2 changes: 1 addition & 1 deletion exopy/app/icons/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions exopy/app/log/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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 --------------------------------------------------------

Expand Down
6 changes: 3 additions & 3 deletions exopy/instruments/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions exopy/measurement/monitors/text_monitor/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions exopy/measurement/workspace/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion exopy/tasks/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions exopy/testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions exopy/utils/atom_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/app/log/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 7 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

4 changes: 1 addition & 3 deletions tests/instruments/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@
"""
import os

import pytest
import enaml
import pytest
from configobj import ConfigObj

with enaml.imports():
from .contributors import InstrContributor1

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

Expand Down
3 changes: 3 additions & 0 deletions tests/instruments/connections/test_visa_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"""Test for the Visa connections.
"""
import logging

import enaml

from exopy.testing.util import show_widget, wait_for_destruction
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/measurement/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@
"""Fixture for testing the measurement plugin.
"""

pytest_plugins = str('exopy.testing.measurement.fixtures'),
35 changes: 17 additions & 18 deletions tests/measurement/engines/test_process_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand All @@ -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.
Expand All @@ -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):
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions tests/measurement/monitors/text_monitor/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@
"""Load common fixture used to test text monitor capabilities.
"""

pytest_plugins = str('exopy.testing.measurement.'
'monitors.text_monitor.fixtures'),
3 changes: 0 additions & 3 deletions tests/measurement/monitors/text_monitor/rules/test_edition.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
import CreateRuleDialog, EditRulesView


pytest_plugins = str('exopy.testing.measurement.'
'monitors.text_monitor.fixtures'),

PLUGIN_ID = 'exopy.measurement.monitors.text_monitor'


Expand Down
4 changes: 0 additions & 4 deletions tests/measurement/monitors/text_monitor/rules/test_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions tests/measurement/monitors/text_monitor/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 0 additions & 4 deletions tests/measurement/monitors/text_monitor/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions tests/measurement/monitors/text_monitor/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 0 additions & 3 deletions tests/measurement/monitors/text_monitor/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 67fd1d1

Please sign in to comment.