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

Merging pull request 2661

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

* https://github.com/avocado-framework/avocado:
  avocado.Test: remove once deprecated datadir
  avocado.Test: removal of srcdir
......@@ -190,15 +190,20 @@ class TestData(object):
DATA_SOURCES = ["variant", "test", "file"]
def __init__(self):
# Maximal allowed file name length is 255
file_datadir = None
if (self.filename is not None and
len(os.path.basename(self.filename)) < 251):
file_datadir = self.filename + '.data'
self._data_sources_mapping = {
"variant": [lambda: self.datadir,
"variant": [lambda: file_datadir,
lambda: "%s.%s" % (self.__class__.__name__,
self._testMethodName),
lambda: self.name.variant],
"test": [lambda: self.datadir,
"test": [lambda: file_datadir,
lambda: "%s.%s" % (self.__class__.__name__,
self._testMethodName)],
"file": [lambda: self.datadir]
"file": [lambda: file_datadir]
}
def _check_valid_data_source(self, source):
......@@ -273,7 +278,13 @@ class TestData(object):
for attempt_source in sources:
datadir = self._get_datadir(attempt_source)
if datadir is not None:
path = os.path.join(datadir, filename)
# avoid returning a slash after the data directory name
# when a file was not requested (thus return the data
# directory itself)
if not filename:
path = datadir
else:
path = os.path.join(datadir, filename)
if not must_exist:
self.log.debug(log_fmt, filename, path,
("assumed to be located at %s source "
......@@ -402,8 +413,7 @@ class Test(unittest.TestCase, TestData):
base_tmpdir = tempfile.mkdtemp(prefix="tmp_dir", dir=self.logdir)
self.__workdir = os.path.join(base_tmpdir,
self.name.str_filesystem)
self.__srcdir_warning_logged = False
self.__srcdir = utils_path.init_dir(self.__workdir, 'src')
utils_path.init_dir(self.__workdir)
self.log.debug("Test metadata:")
if self.filename:
......@@ -480,29 +490,6 @@ class Test(unittest.TestCase, TestData):
else:
return None
@property
def datadir(self):
"""
Returns the path to the directory that may contain test data files
For test a test file hosted at /usr/share/doc/avocado/tests/sleeptest.py
the datadir is /usr/share/doc/avocado/tests/sleeptest.py.data.
Note that this directory has no specific relation to the test
name, only to the file that contains the test. It can be used to
host data files that are generic enough to be used for all tests
contained in a given test file.
This property is deprecated and will be removed in the future.
The :meth:`get_data` function should be used instead.
"""
# Maximal allowed file name length is 255
if (self.filename is not None and
len(os.path.basename(self.filename)) < 251):
return self.filename + '.data'
else:
return None
@property
def filename(self):
"""
......@@ -547,20 +534,6 @@ class Test(unittest.TestCase, TestData):
"""
return self.__workdir
@property
def srcdir(self):
"""
This property is deprecated and will be removed in the future.
The :meth:`workdir` property should be used instead.
"""
if not self.__srcdir_warning_logged:
LOG_JOB.warn("DEPRECATION NOTICE: the test's \"srcdir\" property "
"is deprecated and is planned to be removed no later "
"than May 11 2018. Please use the \"workdir\" "
"property instead.")
self.__srcdir_warning_logged = True
return self.__srcdir
@property
def cache_dirs(self):
"""
......@@ -969,15 +942,12 @@ class Test(unittest.TestCase, TestData):
os.environ['AVOCADO_VERSION'] = VERSION
if self.basedir is not None:
os.environ['AVOCADO_TEST_BASEDIR'] = self.basedir
if self.datadir is not None:
os.environ['AVOCADO_TEST_DATADIR'] = self.datadir
os.environ['AVOCADO_TEST_WORKDIR'] = self.workdir
os.environ['AVOCADO_TEST_LOGDIR'] = self.logdir
os.environ['AVOCADO_TEST_LOGFILE'] = self.logfile
os.environ['AVOCADO_TEST_OUTPUTDIR'] = self.outputdir
if self.__sysinfo_enabled:
os.environ['AVOCADO_TEST_SYSINFODIR'] = self.__sysinfodir
os.environ['AVOCADO_TEST_SRCDIR'] = self.__srcdir
def run_avocado(self):
"""
......@@ -1110,9 +1080,14 @@ class SimpleTest(Test):
self._filename = executable
super(SimpleTest, self).__init__(name=name, params=params,
base_logdir=base_logdir, job=job)
self._data_sources_mapping = {"variant": [lambda: self.datadir,
# Maximal allowed file name length is 255
file_datadir = None
if (self.filename is not None and
len(os.path.basename(self.filename)) < 251):
file_datadir = self.filename + '.data'
self._data_sources_mapping = {"variant": [lambda: file_datadir,
lambda: self.name.variant],
"file": [lambda: self.datadir]}
"file": [lambda: file_datadir]}
self._command = None
if self.filename is not None:
self._command = pipes.quote(self.filename)
......
......@@ -227,10 +227,12 @@ you intend to create it.
for that specific test and execution conditions (such as with or
without variants). Look for "Test data directories" in the test logs.
.. note:: An older API, :attr:`avocado.core.test.Test.datadir`, allows access
to the data directory based on the test file location only. This API
is limited, deprecated and will be removed. All new users should rely
on ``get_data()`` instead.
.. note:: The previously existing API ``avocado.core.test.Test.datadir``,
used to allow access to the data directory based on the test file
location only. This API has been removed. If, for whatever reason
you still need to access the data directory based on the test file
location only, you can use
``get_data(filename='', source='file', must_exist=False)`` instead.
.. _accessing-test-parameters:
......@@ -1672,8 +1674,6 @@ tests:
+-----------------------------+---------------------------------------+-----------------------------------------------------------------------------------------------------+
| AVOCADO_TEST_BASEDIR | Base directory of Avocado tests | $HOME/Downloads/avocado-source/avocado |
+-----------------------------+---------------------------------------+-----------------------------------------------------------------------------------------------------+
| AVOCADO_TEST_DATADIR | Data directory for the test | $AVOCADO_TEST_BASEDIR/my_test.sh.data |
+-----------------------------+---------------------------------------+-----------------------------------------------------------------------------------------------------+
| AVOCADO_TEST_WORKDIR | Work directory for the test | /var/tmp/avocado_Bjr_rd/my_test.sh |
+-----------------------------+---------------------------------------+-----------------------------------------------------------------------------------------------------+
| AVOCADO_TESTS_COMMON_TMPDIR | Temporary directory created by the | /var/tmp/avocado_XhEdo/ |
......@@ -1691,12 +1691,17 @@ tests:
+-----------------------------+---------------------------------------+-----------------------------------------------------------------------------------------------------+
| `***` | All variables from --mux-yaml | TIMEOUT=60; IO_WORKERS=10; VM_BYTES=512M; ... |
+-----------------------------+---------------------------------------+-----------------------------------------------------------------------------------------------------+
| AVOCADO_TEST_SRCDIR | Source directory for the test | /var/tmp/avocado_Bjr_rd/my-test.sh/src |
+-----------------------------+---------------------------------------+-----------------------------------------------------------------------------------------------------+
.. warning:: ``AVOCADO_TEST_SRCDIR`` is deprecated and will be removed
soon. Please use ``AVOCADO_TEST_WORKDIR`` instead.
.. warning:: ``AVOCADO_TEST_SRCDIR`` was present in earlier versions,
but has been deprecated on version 60.0, and removed on
version 62.0. Please use ``AVOCADO_TEST_WORKDIR``
instead.
.. warning:: ``AVOCADO_TEST_DATADIR`` was present in earlier versions,
but has been deprecated on version 60.0, and removed on
version 62.0. The test data files (and directories) are
now dynamically evaluated and are not available as
environment variables
SIMPLE Tests BASH extensions
============================
......
......@@ -5,8 +5,6 @@ echo "Avocado Version: $AVOCADO_VERSION"
echo "Avocado Test basedir: $AVOCADO_TEST_BASEDIR"
echo "Avocado Test datadir: $AVOCADO_TEST_DATADIR"
echo "Avocado Test workdir: $AVOCADO_TEST_WORKDIR"
# Warning: srcdir is deprecated and will be removed soon
echo "Avocado Test srcdir: $AVOCADO_TEST_SRCDIR"
echo "Avocado Test logdir: $AVOCADO_TEST_LOGDIR"
echo "Avocado Test logfile: $AVOCADO_TEST_LOGFILE"
echo "Avocado Test outputdir: $AVOCADO_TEST_OUTPUTDIR"
......@@ -14,7 +12,6 @@ echo "Custom variable: $CUSTOM_VARIABLE"
test -d "$AVOCADO_TEST_BASEDIR" -a \
-d "$AVOCADO_TEST_WORKDIR" -a \
-d "$AVOCADO_TEST_SRCDIR" -a \
-d "$AVOCADO_TEST_LOGDIR" -a \
-f "$AVOCADO_TEST_LOGFILE" -a \
-d "$AVOCADO_TEST_OUTPUTDIR"
......@@ -28,7 +28,7 @@ class LinuxBuildTest(Test):
self.linux_build = kernel.KernelBuild(kernel_version,
linux_config,
self.srcdir,
self.workdir,
self.cache_dirs)
self.linux_build.download(kernel_src_url)
self.linux_build.uncompress()
......
......@@ -19,7 +19,6 @@ echo "Avocado Version: $AVOCADO_VERSION"
echo "Avocado Test basedir: $AVOCADO_TEST_BASEDIR"
echo "Avocado Test datadir: $AVOCADO_TEST_DATADIR"
echo "Avocado Test workdir: $AVOCADO_TEST_WORKDIR"
echo "Avocado Test srcdir: $AVOCADO_TEST_SRCDIR"
echo "Avocado Test logdir: $AVOCADO_TEST_LOGDIR"
echo "Avocado Test logfile: $AVOCADO_TEST_LOGFILE"
echo "Avocado Test outputdir: $AVOCADO_TEST_OUTPUTDIR"
......@@ -28,7 +27,6 @@ echo "Avocado Test sysinfodir: $AVOCADO_TEST_SYSINFODIR"
test "$AVOCADO_VERSION" = "{version}" -a \
-d "$AVOCADO_TEST_BASEDIR" -a \
-d "$AVOCADO_TEST_WORKDIR" -a \
-d "$AVOCADO_TEST_SRCDIR" -a \
-d "$AVOCADO_TEST_LOGDIR" -a \
-f "$AVOCADO_TEST_LOGFILE" -a \
-d "$AVOCADO_TEST_OUTPUTDIR" -a \
......
......@@ -98,12 +98,12 @@ class TestClassTestUnit(unittest.TestCase):
def test_data_dir(self):
"""
Tests that a valid datadir exists following the test filename
Checks `get_data()` won't report fs-unfriendly data dir name
"""
max_length_name = os.path.join(self.tmpdir, "a" * 250)
tst = self._get_fake_filename_test(max_length_name)
self.assertEqual(os.path.join(self.tmpdir, max_length_name + ".data"),
tst.datadir)
tst.get_data('', 'file', False))
def test_no_data_dir(self):
"""
......@@ -111,7 +111,7 @@ class TestClassTestUnit(unittest.TestCase):
"""
above_limit_name = os.path.join(self.tmpdir, "a" * 251)
tst = self._get_fake_filename_test(above_limit_name)
self.assertFalse(tst.datadir)
self.assertFalse(tst.get_data('', 'file', False))
tst._record_reference # Should do nothing
tst._record_reference('stdout', 'stdout.expected')
tst._record_reference('stderr', 'stderr.expected')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册