44import datetime
55import unittest
66import tempfile
7- import imp
7+ import sys
88import warnings
99import os
1010
@@ -59,9 +59,17 @@ def setUp(self):
5959 self .makeTestDB ()
6060 self .loadData (os .path .join (dbp_testing .testsdir , 'data' , 'db_dumps' ,
6161 'testDB_dump.json' ))
62- self .inspect = imp .load_source ('inspect' , os .path .join (
63- dbp_testing .testsdir , 'inspector' , 'rot13_L1.py' ))
64-
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+
6573 def tearDown (self ):
6674 super (InspectorClass , self ).tearDown ()
6775 self .removeTestDB ()
@@ -80,10 +88,18 @@ def test_inspector(self):
8088 self .assertEqual (repr (Diskfile .Diskfile (goodfile , self .dbu )), repr (self .inspect .Inspector (goodfile , self .dbu , 1 ,)()))
8189 #self.assertEqual(None, self.inspect.Inspector(goodfile, self.dbu, 1,).extract_YYYYMMDD())
8290 # This inspector sets the data_level - not allowed
83- inspect = imp .load_source ('inspect' , os .path .join (
84- dbp_testing .testsdir , 'inspector' , 'rot13_L1_dlevel.py' ))
85- with warnings .catch_warnings (record = True ) as w :
86- self .assertEqual (repr (Diskfile .Diskfile (goodfile , self .dbu )), repr (self .inspect .Inspector (goodfile , self .dbu , 1 ,)()))
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 )
101+ with warnings .catch_warnings (record = True ) as w :
102+ self .assertEqual (repr (Diskfile .Diskfile (goodfile , self .dbu )), repr (inspect .Inspector (goodfile , self .dbu , 1 ,)()))
87103 self .assertEqual (len (w ), 1 )
88104 self .assertTrue (isinstance (w [0 ].message , UserWarning ))
89105 self .assertEqual ('Inspector rot13_L1_dlevel.py: set level to 2.0, '
@@ -93,8 +109,17 @@ def test_inspector(self):
93109 # The file doesn't match the inspector pattern...
94110 badfile = os .path .join (
95111 dbp_testing .testsdir , 'inspector' , 'testDB_01_first.raw' )
96- inspect = imp .load_source ('inspect' , os .path .join (
97- dbp_testing .testsdir , 'inspector' , 'rot13_L1.py' ))
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+
98123 self .assertEqual (None , inspect .Inspector (badfile , self .dbu , 1 ,)())
99124
100125 def test_inspector_regex (self ):
0 commit comments