Replace imp to importlib to fix warning

This commit is contained in:
Riza Sulistyo 2023-06-30 18:36:51 +07:00
parent 59249c9ec4
commit ed83e140aa
10 changed files with 31 additions and 18 deletions

13
tests/pjsua/inc_util.py Normal file
View File

@ -0,0 +1,13 @@
import sys
def load_module_from_file(module_name, module_path):
if sys.version_info[0] == 3 and sys.version_info[1] >= 5:
import importlib.util
spec = importlib.util.spec_from_file_location(module_name, module_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
elif sys.version_info[0] == 3 and sys.version_info[1] < 5:
import importlib.machinery
loader = importlib.machinery.SourceFileLoader(module_name, module_path)
module = loader.load_module()
return module

View File

@ -1,11 +1,11 @@
import time
import imp
import sys
import inc_const as const
import inc_util as util
from inc_cfg import *
# Load configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])
cfg_file = util.load_module_from_file("cfg_file", ARGS[1])
# Trigger address switch for media flow between ua1 and ua2.
# When the receiver uses STUN while both sides are actually in the same

View File

@ -8,15 +8,15 @@
# wav input must be more than 3 seconds long
import time
import imp
import sys
import re
import subprocess
import inc_const as const
import inc_util as util
from inc_cfg import *
# Load configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])
cfg_file = util.load_module_from_file("cfg_file", ARGS[1])
# WAV similarity calculator
COMPARE_WAV_EXE = ""

View File

@ -10,7 +10,6 @@
# - clock-rate of those files can only be 8khz or 16khz
import time
import imp
import os
import sys
import re
@ -18,11 +17,12 @@ import subprocess
import wave
import shutil
import inc_const as const
import inc_util as util
from inc_cfg import *
# Load configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])
cfg_file = util.load_module_from_file("cfg_file", ARGS[1])
# PESQ configs
PESQ = "tools/pesq" # PESQ executable path

View File

@ -1,11 +1,11 @@
import time
import imp
import sys
import inc_const as const
import inc_util as util
from inc_cfg import *
# Load configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])
cfg_file = util.load_module_from_file("cfg_file", ARGS[1])
# Test body function

View File

@ -1,12 +1,12 @@
import imp
import sys
import inc_sip as sip
import inc_const as const
import inc_util as util
import re
from inc_cfg import *
# Read configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])
cfg_file = util.load_module_from_file("cfg_file", ARGS[1])
# Default server port (should we randomize?)
srv_port = 50070

View File

@ -1,10 +1,10 @@
import imp
import sys
import inc_util as util
from inc_cfg import *
# Read configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])
cfg_file = util.load_module_from_file("cfg_file", ARGS[1])
# Here where it all comes together
test = cfg_file.test_param

View File

@ -1,12 +1,12 @@
import imp
import sys
import inc_sip as sip
import inc_const as const
import inc_util as util
import re
from inc_cfg import *
# Read configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])
cfg_file = util.load_module_from_file("cfg_file", ARGS[1])
# Test body function
def test_func(t):

View File

@ -19,13 +19,13 @@
## - $PJSUA_URI[N] : SIP URI of PJSUA instance #N
import ctypes
import time
import imp
import sys
import os
import re
import subprocess
from inc_cfg import *
import inc_const
import inc_util as util
# flags that test is running in Unix
G_INUNIX = False
@ -84,7 +84,7 @@ def resolve_driver_macros(st):
# Init test driver
if os.access(SIPP_SCEN_XML[:-4]+".py", os.R_OK):
# Load test driver file (the corresponding .py file), if any
cfg_file = imp.load_source("cfg_file", SIPP_SCEN_XML[:-4]+".py")
cfg_file = util.load_module_from_file("cfg_file", SIPP_SCEN_XML[:-4]+".py")
for ua_idx, ua_param in enumerate(cfg_file.PJSUA):
ua_param = resolve_driver_macros(ua_param)
PJSUA_INST_PARAM.append(InstanceParam("pjsua"+str(ua_idx), ua_param))

View File

@ -1,5 +1,4 @@
import sys
import imp
import re
import os
import subprocess
@ -12,6 +11,7 @@ import getopt
import inc_cfg as inc
import inc_const as const
import inc_util as util
# Vars
G_EXE = "" # pjsua executable path
@ -313,7 +313,7 @@ def handle_error(errmsg, t, close_processes = True):
# MAIN
# Import the test script
script = imp.load_source("script", inc.ARGS[0])
script = util.load_module_from_file("script", inc.ARGS[0])
# Init random seed
random.seed()