Commit 28e07ee6 authored by Jérome Perrin's avatar Jérome Perrin

testing/testcase: cleanups

Fix long lines, incorrect type annotations and adjust a bit to make mypy
happy.
parent dd8f4b5a
...@@ -37,7 +37,7 @@ from six.moves.urllib.parse import urlparse ...@@ -37,7 +37,7 @@ from six.moves.urllib.parse import urlparse
try: try:
import subprocess32 as subprocess import subprocess32 as subprocess
except ImportError: except ImportError:
import subprocess import subprocess # type: ignore
subprocess # pyflakes subprocess # pyflakes
from .utils import getPortFromPath from .utils import getPortFromPath
...@@ -49,7 +49,7 @@ from ..grid.utils import md5digest ...@@ -49,7 +49,7 @@ from ..grid.utils import md5digest
from ..util import mkdir_p from ..util import mkdir_p
try: try:
from typing import Iterable, Tuple, Callable, Type from typing import Iterable, Tuple, Callable, Type, Dict, List, Optional
except ImportError: except ImportError:
pass pass
...@@ -63,9 +63,9 @@ def makeModuleSetUpAndTestCaseClass( ...@@ -63,9 +63,9 @@ def makeModuleSetUpAndTestCaseClass(
verbose=bool(int(os.environ.get('SLAPOS_TEST_VERBOSE', 0))), verbose=bool(int(os.environ.get('SLAPOS_TEST_VERBOSE', 0))),
shared_part_list=os.environ.get('SLAPOS_TEST_SHARED_PART_LIST', shared_part_list=os.environ.get('SLAPOS_TEST_SHARED_PART_LIST',
'').split(os.pathsep), '').split(os.pathsep),
snapshot_directory=os.environ.get('SLAPOS_TEST_LOG_DIRECTORY') snapshot_directory=os.environ.get('SLAPOS_TEST_LOG_DIRECTORY'),
): ):
# type: (str, str, str, str, bool, bool, List[str]) -> Tuple[Callable[[], None], Type[SlapOSInstanceTestCase]] # type: (str, str, str, str, bool, bool, Iterable[str], Optional[str]) -> Tuple[Callable[[], None], Type[SlapOSInstanceTestCase]]
"""Create a setup module function and a testcase for testing `software_url`. """Create a setup module function and a testcase for testing `software_url`.
This function returns a tuple of two arguments: This function returns a tuple of two arguments:
...@@ -124,7 +124,6 @@ def makeModuleSetUpAndTestCaseClass( ...@@ -124,7 +124,6 @@ def makeModuleSetUpAndTestCaseClass(
if not snapshot_directory: if not snapshot_directory:
snapshot_directory = os.path.join(base_directory, "snapshots") snapshot_directory = os.path.join(base_directory, "snapshots")
cls = type( cls = type(
'SlapOSInstanceTestCase for {}'.format(software_url), 'SlapOSInstanceTestCase for {}'.format(software_url),
(SlapOSInstanceTestCase,), { (SlapOSInstanceTestCase,), {
...@@ -139,7 +138,9 @@ def makeModuleSetUpAndTestCaseClass( ...@@ -139,7 +138,9 @@ def makeModuleSetUpAndTestCaseClass(
'_test_file_snapshot_directory': snapshot_directory '_test_file_snapshot_directory': snapshot_directory
}) })
class SlapOSInstanceTestCase_(cls, SlapOSInstanceTestCase): class SlapOSInstanceTestCase_(
cls, # type: ignore # https://github.com/python/mypy/issues/2813
SlapOSInstanceTestCase):
# useless intermediate class so that editors provide completion anyway. # useless intermediate class so that editors provide completion anyway.
pass pass
...@@ -522,11 +523,12 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -522,11 +523,12 @@ class SlapOSInstanceTestCase(unittest.TestCase):
"{}._cleanup leaked_partitions".format(snapshot_name)) "{}._cleanup leaked_partitions".format(snapshot_name))
for cp in leaked_partitions: for cp in leaked_partitions:
try: try:
# XXX is this really the reference ?
partition_reference = cp.getInstanceParameterDict()['instance_title']
cls.slap.request( cls.slap.request(
software_release=cp.getSoftwareRelease().getURI(), software_release=cp.getSoftwareRelease().getURI(),
# software_type=cp.getType(), # TODO # software_type=cp.getType(), # TODO
# XXX is this really the reference ? partition_reference=partition_reference,
partition_reference=cp.getInstanceParameterDict()['instance_title'],
state="destroyed") state="destroyed")
except: except:
cls.logger.exception( cls.logger.exception(
...@@ -547,10 +549,14 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -547,10 +549,14 @@ class SlapOSInstanceTestCase(unittest.TestCase):
cls.logger.exception("Error during stop") cls.logger.exception("Error during stop")
cls._storeSystemSnapshot("{}._cleanup stop".format(snapshot_name)) cls._storeSystemSnapshot("{}._cleanup stop".format(snapshot_name))
leaked_supervisor_configs = glob.glob( leaked_supervisor_configs = glob.glob(
os.path.join(cls.slap.instance_directory, 'etc', 'supervisord.conf.d', '*.conf')) os.path.join(
cls.slap.instance_directory, 'etc', 'supervisord.conf.d', '*.conf'))
if leaked_supervisor_configs: if leaked_supervisor_configs:
[os.unlink(config) for config in leaked_supervisor_configs] for config in leaked_supervisor_configs:
raise AssertionError("Test leaked supervisor configurations: %s" % leaked_supervisor_configs) os.unlink(config)
raise AssertionError(
"Test leaked supervisor configurations: %s" %
leaked_supervisor_configs)
@classmethod @classmethod
def requestDefaultInstance(cls, state='started'): def requestDefaultInstance(cls, state='started'):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment