Skip to content

Commit

Permalink
tools: fix Python 3 deprecation warning in test.py
Browse files Browse the repository at this point in the history
PR-URL: #30208
Reviewed-By: Christian Clauss <cclauss@me.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
  • Loading branch information
Hellzed authored and targos committed Nov 10, 2019
1 parent c1c613e commit 65eda36
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@


from __future__ import print_function
import imp
import logging
import optparse
import os
Expand All @@ -45,6 +44,27 @@
import errno
import copy


if sys.version_info >= (3, 5):
from importlib import machinery, util
def get_module(name, path):
loader_details = (machinery.SourceFileLoader, machinery.SOURCE_SUFFIXES)
spec = machinery.FileFinder(path, loader_details).find_spec(name)
module = util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
else:
import imp
def get_module(name, path):
file = None
try:
(file, pathname, description) = imp.find_module(name, [path])
return imp.load_module(name, file, pathname, description)
finally:
if file:
file.close()


from io import open
from os.path import join, dirname, abspath, basename, isdir, exists
from datetime import datetime
Expand Down Expand Up @@ -786,18 +806,13 @@ def GetConfiguration(self, context):
if self.is_loaded:
return self.config
self.is_loaded = True
file = None
try:
(file, pathname, description) = imp.find_module('testcfg', [ self.path ])
module = imp.load_module('testcfg', file, pathname, description)
self.config = module.GetConfiguration(context, self.path)
if hasattr(self.config, 'additional_flags'):
self.config.additional_flags += context.node_args
else:
self.config.additional_flags = context.node_args
finally:
if file:
file.close()

module = get_module('testcfg', self.path)
self.config = module.GetConfiguration(context, self.path)
if hasattr(self.config, 'additional_flags'):
self.config.additional_flags += context.node_args
else:
self.config.additional_flags = context.node_args
return self.config

def GetBuildRequirements(self, path, context):
Expand Down

0 comments on commit 65eda36

Please sign in to comment.