From 496e89d9075fef944c28e276483a600b50b2a5f5 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Sun, 24 Jan 2016 20:31:06 -0200 Subject: [PATCH] Test: turn datadir into a property The reason being that `datadir` can then be properly documented as first class citizens so that Test class users (test writers) can rely on it. Other reason is that that it can be overloaded by inherited classes such as `SimpleTest`, without the need to (re-)set other attributes that depend on it. Signed-off-by: Cleber Rosa --- avocado/core/test.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/avocado/core/test.py b/avocado/core/test.py index 9a996caa..839425ad 100644 --- a/avocado/core/test.py +++ b/avocado/core/test.py @@ -90,8 +90,6 @@ class Test(unittest.TestCase): self.filename = inspect.getfile(self.__class__).rstrip('co') self.basedir = os.path.dirname(self.filename) - self.datadir = self.filename + '.data' - self.expected_stdout_file = os.path.join(self.datadir, 'stdout.expected') self.expected_stderr_file = os.path.join(self.datadir, @@ -160,6 +158,14 @@ class Test(unittest.TestCase): self.time_elapsed = None unittest.TestCase.__init__(self, methodName=methodName) + @property + def datadir(self): + """ + Returns the path to the directory that contains test data files + """ + filename = inspect.getfile(self.__class__).rstrip('co') + return filename + '.data' + @data_structures.LazyProperty def workdir(self): basename = os.path.basename(self.name) @@ -560,14 +566,13 @@ class SimpleTest(Test): super(SimpleTest, self).__init__(name=name, base_logdir=base_logdir, params=params, tag=tag, job=job) self.path = name - basedir = os.path.dirname(self.path) - basename = os.path.basename(self.path) - datadirname = basename + '.data' - self.datadir = os.path.join(basedir, datadirname) - self.expected_stdout_file = os.path.join(self.datadir, - 'stdout.expected') - self.expected_stderr_file = os.path.join(self.datadir, - 'stderr.expected') + + @property + def datadir(self): + """ + Returns the path to the directory that contains test data files + """ + return self.name + '.data' def _log_detailed_cmd_info(self, result): """ -- GitLab