1414from dbprocessing import Version
1515from dbprocessing import DButils
1616from dbprocessing import Diskfile
17+ from dbprocessing import Utils
1718
1819class InspectorFunctions (unittest .TestCase ):
1920 """Tests of the inspector functions"""
@@ -59,17 +60,9 @@ def setUp(self):
5960 self .makeTestDB ()
6061 self .loadData (os .path .join (dbp_testing .testsdir , 'data' , 'db_dumps' ,
6162 'testDB_dump.json' ))
62- if sys .version_info < (3 , 4 ):
63- import imp
64- self .inspect = imp .load_source ('inspect' , os .path .join (dbp_testing .testsdir , 'inspector' , 'rot13_L1.py' ))
65- else :
66- import importlib .util
67- import importlib .machinery
68- loader = importlib .machinery .SourceFileLoader ('inspect' , os .path .join (dbp_testing .testsdir , 'inspector' , 'rot13_L1.py' ))
69- spec = importlib .util .spec_from_file_location ('inspect' , os .path .join (dbp_testing .testsdir , 'inspector' , 'rot13_L1.py' ), loader = loader )
70- self .inspect = importlib .util .module_from_spec (spec )
71- loader .exec_module (self .inspect )
72-
63+ filename = os .path .join (dbp_testing .testsdir , 'inspector' , 'rot13_L1.py' )
64+ self .inspect = None
65+ self .inspect = Utils .load_source ('inspect' , filename , self .inspect )
7366 def tearDown (self ):
7467 super (InspectorClass , self ).tearDown ()
7568 self .removeTestDB ()
@@ -88,16 +81,9 @@ def test_inspector(self):
8881 self .assertEqual (repr (Diskfile .Diskfile (goodfile , self .dbu )), repr (self .inspect .Inspector (goodfile , self .dbu , 1 ,)()))
8982 #self.assertEqual(None, self.inspect.Inspector(goodfile, self.dbu, 1,).extract_YYYYMMDD())
9083 # This inspector sets the data_level - not allowed
91- if sys .version_info < (3 , 4 ):
92- import imp # Depracated in Python 3.4
93- inspect = imp .load_source ('inspect' , os .path .join (dbp_testing .testsdir , 'inspector' , 'rot13_L1_dlevel.py' ))
94- else :
95- import importlib .util
96- import importlib .machinery
97- loader = importlib .machinery .SourceFileLoader ('inspect' , os .path .join (dbp_testing .testsdir , 'inspector' , 'rot13_L1_dlevel.py' ))
98- spec = importlib .util .spec_from_file_location ('inspect' , os .path .join (dbp_testing .testsdir , 'inspector' , 'rot13_L1_dlevel.py' ), loader = loader )
99- inspect = importlib .util .module_from_spec (spec )
100- loader .exec_module (inspect )
84+ filename = os .path .join (dbp_testing .testsdir , 'inspector' , 'rot13_L1_dlevel.py' )
85+ inspect = None
86+ inspect = Utils .load_source ('inspect' , filename , inspect )
10187 with warnings .catch_warnings (record = True ) as w :
10288 self .assertEqual (repr (Diskfile .Diskfile (goodfile , self .dbu )), repr (inspect .Inspector (goodfile , self .dbu , 1 ,)()))
10389 self .assertEqual (len (w ), 1 )
@@ -109,17 +95,9 @@ def test_inspector(self):
10995 # The file doesn't match the inspector pattern...
11096 badfile = os .path .join (
11197 dbp_testing .testsdir , 'inspector' , 'testDB_01_first.raw' )
112- if sys .version_info < (3 , 4 ):
113- import imp # Depracated in Python 3.4
114- inspect = imp .load_source ('inspect' , os .path .join (dbp_testing .testsdir , 'inspector' , 'rot13_L1.py' ))
115- else :
116- import importlib .util
117- import importlib .machinery
118- loader = importlib .machinery .SourceFileLoader ('inspect' , os .path .join (dbp_testing .testsdir , 'inspector' , 'rot13_L1.py' ))
119- spec = importlib .util .spec_from_file_location ('inspect' , os .path .join (dbp_testing .testsdir , 'inspector' , 'rot13_L1.py' ), loader = loader )
120- inspect = importlib .util .module_from_spec (spec )
121- loader .exec_module (inspect )
122-
98+ filename = os .path .join (dbp_testing .testsdir , 'inspector' , 'rot13_L1.py' )
99+ inspect = None
100+ inspect = Utils .load_source ('inspect' , filename , inspect )
123101 self .assertEqual (None , inspect .Inspector (badfile , self .dbu , 1 ,)())
124102
125103 def test_inspector_regex (self ):
0 commit comments