diff --git a/pysipp/launch.py b/pysipp/launch.py index a032011..d6098cd 100644 --- a/pysipp/launch.py +++ b/pysipp/launch.py @@ -142,7 +142,7 @@ def _signalall(self, signum): signalled = OrderedDict() for cmd, proc in self.iterprocs(): proc.send_signal(signum) - log.warn( + log.warning( "sent signal '{}' to cmd '{}' with pid '{}'".format( signum, cmd, proc.pid ) diff --git a/pysipp/report.py b/pysipp/report.py index ba34f11..ef76c22 100644 --- a/pysipp/report.py +++ b/pysipp/report.py @@ -44,7 +44,7 @@ def err_summary(agents2procs): return msg -def emit_logfiles(agents2procs, level="warn", max_lines=100): +def emit_logfiles(agents2procs, level="warning", max_lines=100): """Log all available SIPp log-file contents""" emit = getattr(log, level) for ua, proc in agents2procs: diff --git a/pysipp/utils.py b/pysipp/utils.py index 2c1ec09..0fa2f28 100644 --- a/pysipp/utils.py +++ b/pysipp/utils.py @@ -1,8 +1,9 @@ -import imp # XXX py2.7 +import importlib import inspect import logging import os import tempfile +import types LOG_FORMAT = ( "%(asctime)s %(threadName)s [%(levelname)s] %(name)s " @@ -12,6 +13,19 @@ DATE_FORMAT = "%b %d %H:%M:%S" +def load_source(name: str, path: str) -> types.ModuleType: + """ + Replacement for deprecated imp.load_source() + Thanks to: + https://github.com/epfl-scitas/spack for pointing out the + important missing "spec.loader.exec_module(module)" line. + """ + spec = importlib.util.spec_from_file_location(name, path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + def get_logger(): """Get the project logger instance""" return logging.getLogger("pysipp") @@ -32,7 +46,7 @@ def load_mod(path, name=None): """Load a source file as a module""" name = name or os.path.splitext(os.path.basename(path))[0] # load module sources - return imp.load_source(name, path) + return load_source(name, path) def iter_data_descrs(cls): diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..7bee332 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,15 @@ +import os.path + +import pytest + +from pysipp import utils + + +def test_load_mod(scendir): + confpy = os.path.join(scendir, "default_with_confpy", "pysipp_conf.py") + assert utils.load_mod(confpy) + + +def test_load_mod_ko(): + with pytest.raises(FileNotFoundError): + utils.load_mod("not_here.py")