提交 70d525f1 编写于 作者: C Cleber Rosa

selftests/unit/test_safeloader.py: do not rely on assertRegex* methods

The prevailing coding style of Avocado (unittest.TestCase) tests is to
use the specialized assert methods, such as assertNotRegexpMatches.

Unfortunately, the regular expression related assertion methods have
been through a messy renaming.  In theory, assertNotRegexpMatches and
assertRegexpMatches should be available in Python 3.0 and 3.1, but not
in Python >= 3.2, where it got renamed to assertRegex and
assertNotRegex.

In practice, in my system with Python 3.6.3, I see:

>>> unittest.TestCase.assertNotRegexpMatches
<function TestCase._deprecate.<locals>.deprecated_func at 0x7f3b85b709d8>

But in Travis, with Python 3.4, it's not available:

ERROR: test_directives_regex (selftests.unit.test_safeloader.DocstringDirectives)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/avocado-framework/avocado/selftests/unit/test_safeloader.py", line 135, in test_directives_regex
    self.assertNotRegexpMatches(directive, safeloader.DOCSTRING_DIRECTIVE_RE)
AttributeError: 'DocstringDirectives' object has no attribute 'assertNotRegexpMatches'

Let's simplify things and just use a regex match and check for its
result.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 deddfefc
......@@ -130,9 +130,9 @@ class DocstringDirectives(unittest.TestCase):
Tests the regular expressions that deal with docstring directives
"""
for directive in self.VALID_DIRECTIVES:
self.assertRegexpMatches(directive, safeloader.DOCSTRING_DIRECTIVE_RE)
self.assertTrue(safeloader.DOCSTRING_DIRECTIVE_RE.match(directive))
for directive in self.INVALID_DIRECTIVES:
self.assertNotRegexpMatches(directive, safeloader.DOCSTRING_DIRECTIVE_RE)
self.assertFalse(safeloader.DOCSTRING_DIRECTIVE_RE.match(directive))
class UnlimitedDiff(unittest.TestCase):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册