Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecation warnings #84

Merged
merged 2 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pysipp/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion pysipp/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 16 additions & 2 deletions pysipp/utils.py
Original file line number Diff line number Diff line change
@@ -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 "
Expand All @@ -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")
Expand All @@ -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):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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")