From 70d525f1a25d79c5e30c7711dbe90ce7afbea292 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Fri, 19 Jan 2018 07:25:48 -0500 Subject: [PATCH] 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 .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: Cleber Rosa --- selftests/unit/test_safeloader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/selftests/unit/test_safeloader.py b/selftests/unit/test_safeloader.py index ea9f7d96..5c07be6b 100644 --- a/selftests/unit/test_safeloader.py +++ b/selftests/unit/test_safeloader.py @@ -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): -- GitLab