未验证 提交 7acddf2b 编写于 作者: L Lukáš Doktor

Merging pull request 2508

Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>

* https://github.com/avocado-framework/avocado:
  Test: initialize workdir early in non-lazy mode
  Test: rely on TestId.str_filesystem for the workdir
  Test: provide more metadata information
  Test: use more appropriate exceptions on invalid input
  Test: log test init before other messages
......@@ -153,7 +153,8 @@ class TestID(object):
For Test ID "001-mytest;foo", examples of shortened file
system versions include "001-mytest;f" or "001-myte;foo".
:raises: AssertionError
:raises: RuntimeError if the test ID cannot be converted to a
filesystem representation.
"""
test_id = str(self)
test_id_fs = astring.string_to_safe_path(test_id)
......@@ -166,9 +167,9 @@ class TestID(object):
elif len(self.str_uid) <= len(test_id_fs): # full uid
return astring.string_to_safe_path(self.str_uid + self.str_variant)
else: # not even uid could be stored in fs
raise AssertionError('Test uid is too long to be stored on the '
'filesystem: "%s"\nFull Test ID: "%s"'
% (self.str_uid, str(self)))
raise RuntimeError('Test ID is too long to be stored on the '
'filesystem: "%s"\nFull Test ID: "%s"'
% (self.str_uid, str(self)))
class TestData(object):
......@@ -369,6 +370,8 @@ class Test(unittest.TestCase, TestData):
self.__log_warn_used = False
self.log.warn = self.log.warning = record_and_warn
self.log.info('INIT %s', self.name)
paths = ['/test/*']
if params is None:
params = []
......@@ -379,8 +382,6 @@ class Test(unittest.TestCase, TestData):
default_timeout = getattr(self, "timeout", None)
self.timeout = self.params.get("timeout", default=default_timeout)
self.log.info('START %s', self.name)
self.__status = None
self.__fail_reason = None
self.__fail_class = None
......@@ -393,14 +394,23 @@ class Test(unittest.TestCase, TestData):
self.__runner_queue = runner_queue
self.__workdir = None
self.__workdir = os.path.join(data_dir.get_tmp_dir(),
self.name.str_filesystem)
self.__srcdir_internal_access = False
self.__srcdir_warning_logged = False
self.__srcdir = None
self.log.debug("Test metadata:")
if self.filename:
self.log.debug("Test metadata:")
self.log.debug(" filename: %s", self.filename)
try:
teststmpdir = self.teststmpdir
except EnvironmentError:
pass
else:
self.log.debug(" teststmpdir: %s", self.teststmpdir)
self.log.debug(" workdir: %s", self.workdir)
unittest.TestCase.__init__(self, methodName=methodName)
TestData.__init__(self)
......@@ -522,11 +532,6 @@ class Test(unittest.TestCase, TestData):
@property
def workdir(self):
if self.__workdir is None:
base_logdir = os.path.basename(self.logdir)
safe_base_logdir = base_logdir.replace(':', '_').replace(';', '_')
self.__workdir = os.path.join(data_dir.get_tmp_dir(),
safe_base_logdir)
return self.__workdir
@property
......@@ -570,9 +575,10 @@ class Test(unittest.TestCase, TestData):
"""
Override the runner_queue
"""
self.assertTrue(self.__runner_queue is None, "Overriding of runner_"
"queue multiple times is not allowed -> old=%s new=%s"
% (self.__runner_queue, runner_queue))
if self.__runner_queue is not None:
raise RuntimeError("Overriding of runner_queue multiple "
"times is not allowed -> old=%s new=%s"
% (self.__runner_queue, runner_queue))
self.__runner_queue = runner_queue
@property
......@@ -608,6 +614,7 @@ class Test(unittest.TestCase, TestData):
return "Test(%r)" % self.name
def _tag_start(self):
self.log.info('START %s', self.name)
self.__running = True
self.time_start = time.time()
......@@ -1211,7 +1218,8 @@ class ExternalRunnerTest(SimpleTest):
external_runner=None, external_runner_argument=None):
if external_runner_argument is None:
external_runner_argument = name.name
self.assertIsNotNone(external_runner, "External runner test requires "
if external_runner is None:
raise ValueError("External runner test requires a valid "
"external_runner parameter, got None instead.")
self.external_runner = external_runner
super(ExternalRunnerTest, self).__init__(name, params, base_logdir,
......
......@@ -90,7 +90,7 @@ class TestClassTestUnit(unittest.TestCase):
tst = check("a" * 255, "whatever", {"variant_id": "whatever-else"},
"a" * 255)
# Impossible to store (uid does not fit
self.assertRaises(AssertionError, check, "a" * 256, "whatever",
self.assertRaises(RuntimeError, check, "a" * 256, "whatever",
{"variant_id": "else"}, None)
self.assertEqual(os.path.basename(tst.workdir),
......@@ -347,7 +347,7 @@ class TestID(unittest.TestCase):
raised.
"""
test_id = test.TestID(1, 'test', no_digits=256)
self.assertRaises(AssertionError, lambda: test_id.str_filesystem)
self.assertRaises(RuntimeError, lambda: test_id.str_filesystem)
def test_uid_large_name(self):
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册