提交 86b48d29 编写于 作者: C Cleber Rosa

avocado.Test: remove once deprecated datadir

The `avocado.Test.datadir` attribute has been deprecated, and it's now
time to have it removed for good.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 d2760c7a
......@@ -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 "
......@@ -479,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):
"""
......@@ -954,8 +942,6 @@ 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
......@@ -1094,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/ |
......@@ -1697,6 +1697,11 @@ tests:
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
============================
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册