提交 f5ae8ed8 编写于 作者: L Lukáš Doktor

test: Remove unnecessary LazyProperty from Test class

Most of the LazyProperty variables in Test are actually always read on
"get_state" and other occasions so it does not make sense to set it
Lazily.

Also protect the remaining lazily initialized property from overriding
by using @property instead of our custom LazyProperty, which is not
really a property.

This commit requires some adjustments to nasty example tests which used
to override self.srcdir, which is not allowed (and restricted since this
commit).
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 c0156e43
......@@ -243,6 +243,7 @@ class Test(unittest.TestCase):
self.__fail_reason = None
self.__fail_class = None
self.__traceback = None
self.__cache_dirs = None # Is initialized lazily
self.__running = False
self.paused = False
......@@ -250,6 +251,12 @@ class Test(unittest.TestCase):
self.__runner_queue = runner_queue
basename = (os.path.basename(self.logdir).replace(':', '_')
.replace(';', '_'))
self.__workdir = utils_path.init_dir(data_dir.get_tmp_dir(),
basename)
self.__srcdir = utils_path.init_dir(self.workdir, 'src')
unittest.TestCase.__init__(self, methodName=methodName)
@property
......@@ -355,27 +362,27 @@ class Test(unittest.TestCase):
raise EnvironmentError(msg)
return path
@data_structures.LazyProperty
@property
def workdir(self):
basename = (os.path.basename(self.logdir).replace(':', '_')
.replace(';', '_'))
return utils_path.init_dir(data_dir.get_tmp_dir(), basename)
return self.__workdir
@data_structures.LazyProperty
@property
def srcdir(self):
return utils_path.init_dir(self.workdir, 'src')
return self.__srcdir
@data_structures.LazyProperty
@property
def cache_dirs(self):
"""
Returns a list of cache directories as set in config file.
"""
cache_dirs = settings.get_value('datadir.paths', 'cache_dirs',
key_type=list, default=[])
datadir_cache = os.path.join(data_dir.get_data_dir(), 'cache')
if datadir_cache not in cache_dirs:
cache_dirs.append(datadir_cache)
return cache_dirs
if self.__cache_dirs is None:
cache_dirs = settings.get_value('datadir.paths', 'cache_dirs',
key_type=list, default=[])
datadir_cache = os.path.join(data_dir.get_data_dir(), 'cache')
if datadir_cache not in cache_dirs:
cache_dirs.append(datadir_cache)
self.__cache_dirs = cache_dirs
return self.__cache_dirs
@property
def runner_queue(self):
......
......@@ -28,19 +28,19 @@ class SyncTest(Test):
sync_tarball = self.params.get('sync_tarball', '*', 'synctest.tar.bz2')
tarball_path = os.path.join(self.datadir, sync_tarball)
archive.extract(tarball_path, self.srcdir)
self.srcdir = os.path.join(self.srcdir, 'synctest')
srcdir = os.path.join(self.srcdir, 'synctest')
os.chdir(srcdir)
if self.params.get('debug_symbols', default=True):
build.make(self.srcdir,
build.make(srcdir,
env={'CFLAGS': '-g -O0'},
extra_args='synctest')
else:
build.make(self.srcdir)
build.make(srcdir)
def test(self):
"""
Execute synctest with the appropriate params.
"""
os.chdir(self.srcdir)
path = os.path.join(os.getcwd(), 'synctest')
cmd = ('%s %s %s' %
(path, self.params.get('sync_length', default=100),
......
......@@ -31,10 +31,10 @@ class TrinityTest(Test):
tarball = self.params.get('tarball', default='trinity-1.5.tar.bz2')
tarball_path = os.path.join(self.datadir, tarball)
archive.extract(tarball_path, self.srcdir)
self.srcdir = os.path.join(self.srcdir, 'trinity-1.5')
os.chdir(self.srcdir)
srcdir = os.path.join(self.srcdir, 'trinity-1.5')
os.chdir(srcdir)
process.run('./configure.sh')
build.make(self.srcdir)
build.make(srcdir)
self.victims_path = data_factory.make_dir_and_populate(self.workdir)
def test(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册