File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1- import imp # XXX py2.7
1+ import importlib
22import inspect
33import logging
44import os
55import tempfile
6+ import types
67
78LOG_FORMAT = (
89 "%(asctime)s %(threadName)s [%(levelname)s] %(name)s "
1213DATE_FORMAT = "%b %d %H:%M:%S"
1314
1415
16+ def load_source (name : str , path : str ) -> types .ModuleType :
17+ """
18+ Replacement for deprecated imp.load_source()
19+ Thanks to:
20+ https://github.com/epfl-scitas/spack for pointing out the
21+ important missing "spec.loader.exec_module(module)" line.
22+ """
23+ spec = importlib .util .spec_from_file_location (name , path )
24+ module = importlib .util .module_from_spec (spec )
25+ spec .loader .exec_module (module )
26+ return module
27+
28+
1529def get_logger ():
1630 """Get the project logger instance"""
1731 return logging .getLogger ("pysipp" )
@@ -32,7 +46,7 @@ def load_mod(path, name=None):
3246 """Load a source file as a module"""
3347 name = name or os .path .splitext (os .path .basename (path ))[0 ]
3448 # load module sources
35- return imp . load_source (name , path )
49+ return load_source (name , path )
3650
3751
3852def iter_data_descrs (cls ):
Original file line number Diff line number Diff line change 1+ import os .path
2+
3+ import pytest
4+
5+ from pysipp import utils
6+
7+
8+ def test_load_mod (scendir ):
9+ confpy = os .path .join (scendir , "default_with_confpy" , "pysipp_conf.py" )
10+ assert utils .load_mod (confpy )
11+
12+
13+ def test_load_mod_ko ():
14+ with pytest .raises (FileNotFoundError ):
15+ utils .load_mod ("not_here.py" )
You can’t perform that action at this time.
0 commit comments