-
Notifications
You must be signed in to change notification settings - Fork 225
[2/8] Use assert(Not)Regex instead of assertTrue or assertFalse in tests
#5241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
33ac366
ee60934
fb82e2d
ede2655
1a0dddd
f8e0861
3151130
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -232,16 +232,12 @@ def test_package(self): | |
| self.assertTrue(os.path.isfile(pkgfile), "Found %s" % pkgfile) | ||
|
|
||
| # check whether extra packaging options were passed down | ||
| regex = re.compile("^got an unhandled option: --foo bar$", re.M) | ||
| self.assertTrue(regex.search(fpm_output), "Pattern '%s' found in: %s" % (regex.pattern, fpm_output)) | ||
| self.assertRegex(fpm_output, re.compile("^got an unhandled option: --foo bar$", re.M)) | ||
|
|
||
| pkgtxt = read_file(pkgfile) | ||
| pkgtxt_regex = re.compile("STARTCONTENTS of installdir %s" % easyblock.installdir) | ||
| self.assertTrue(pkgtxt_regex.search(pkgtxt), "Pattern '%s' found in: %s" % (pkgtxt_regex.pattern, pkgtxt)) | ||
| self.assertIn("STARTCONTENTS of installdir %s" % easyblock.installdir, pkgtxt) | ||
|
|
||
| no_logfiles_regex = re.compile(r'STARTCONTENTS.*\.(log|md)$.*ENDCONTENTS', re.DOTALL | re.MULTILINE) | ||
| res = no_logfiles_regex.search(pkgtxt) | ||
| self.assertFalse(res, "Pattern not '%s' found in: %s" % (no_logfiles_regex.pattern, pkgtxt)) | ||
| self.assertNotRegex(pkgtxt, re.compile(r'STARTCONTENTS.*\.(log|md)$.*ENDCONTENTS', re.DOTALL | re.M)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, this is the one I meant that has $ in the middle
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I had kept the |
||
|
|
||
| toy_txt = read_file(os.path.join(TEST_ECS_DIR, 't', 'toy', 'toy-0.0-gompi-2018a-test.eb')) | ||
| replace_str = '''description = """Toy C program, 100% toy. Now with `backticks'\n''' | ||
|
|
@@ -250,19 +246,16 @@ def test_package(self): | |
| toy_file = os.path.join(self.test_prefix, 'toy-test-description.eb') | ||
| write_file(toy_file, toy_txt) | ||
|
|
||
| regex = re.compile(r"""`backticks'""") | ||
| self.assertTrue(regex.search(toy_txt), "Pattern '%s' found in: %s" % (regex.pattern, toy_txt)) | ||
| self.assertRegex(toy_txt, r"""`backticks'""") | ||
| ec_desc = EasyConfig(toy_file, validate=False) | ||
| easyblock_desc = EB_toy(ec_desc) | ||
| easyblock_desc.run_all_steps(False) | ||
| pkgdir = package(easyblock_desc) | ||
| pkgfile = os.path.join(pkgdir, 'toy-0.0-gompi-2018a-test-eb-%s.1.rpm' % EASYBUILD_VERSION) | ||
| self.assertTrue(os.path.isfile(pkgfile)) | ||
| pkgtxt = read_file(pkgfile) | ||
| regex_pkg = re.compile(r"""DESCRIPTION:.*`backticks'.*""") | ||
| self.assertTrue(regex_pkg.search(pkgtxt), "Pattern '%s' not found in: %s" % (regex_pkg.pattern, pkgtxt)) | ||
| regex_pkg = re.compile(r"""DESCRIPTION:.*\nand newlines""", re.MULTILINE) | ||
| self.assertTrue(regex_pkg.search(pkgtxt), "Pattern '%s' not found in: %s" % (regex_pkg.pattern, pkgtxt)) | ||
| self.assertRegex(pkgtxt, r"""DESCRIPTION:.*`backticks'.*""") | ||
| self.assertRegex(pkgtxt, r"""DESCRIPTION:.*\nand newlines""") | ||
|
Comment on lines
240
to
+258
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't these two actually need MULTILINE? the first one does have a "$" in the middle of the regex at least and the second one includes newline in the pattern
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first one? MULTILINE only affects |
||
|
|
||
|
|
||
| def suite(loader=None): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the lack of re.compile here compared to the others above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps the question should be why keep the re.compile above?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re.compilewas required when flags were used. E.g. when^$should match line begin/end. I removed the remaining ones that were no longer required now