Skip to content

[3/8] Use assert(Not)Regex instead of assertTrue or assertFalse in tests - #5242

Merged
akesandgren merged 2 commits into
easybuilders:developfrom
Flamefire:assertregex-3
Sep 16, 2026
Merged

akesandgren merged 2 commits into
easybuilders:developfrom
Flamefire:assertregex-3

Conversation

@Flamefire

Copy link
Copy Markdown
Contributor

This makes the tests shorter and hence easier to read, avoids re.compile calls and manual failure message composing. In some cases assert_multi_regex could be used to avoid the explicit loops.

Comment thread test/framework/github.py Outdated

sha = gh.fetch_latest_commit_sha('easybuild-framework', 'easybuilders', github_user=GITHUB_TEST_ACCOUNT)
self.assertTrue(re.match('^[0-9a-f]{40}$', sha))
self.assertRegex(sha, '^[0-9a-f]{40}$')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably be better to make this a "constant", SHA_PATTERN or something

Comment thread test/framework/parallelbuild.py Outdated
for regex in regexs:
regex = re.compile(regex)
self.assertTrue(regex.search(cmd), "Pattern '%s' found in: %s" % (regex.pattern, cmd))
self.assert_multi_regex(regexs, cmd)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multi_line = False here? probably doesn't matter but...

Comment thread test/framework/parallelbuild.py Outdated
… in tests

This makes the tests shorter and hence easier to read, avoids
`re.compile` calls and manual failure message composing.
In some cases `assert_multi_regex` could be used to avoid the explicit loops.

@akesandgren akesandgren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@akesandgren akesandgren added this to the next release (5.4.1) milestone Sep 16, 2026
@akesandgren

Copy link
Copy Markdown
Contributor

Going in, thanks @Flamefire!

@akesandgren
akesandgren merged commit d9de765 into easybuilders:develop Sep 16, 2026
41 checks passed
@Flamefire
Flamefire deleted the assertregex-3 branch September 16, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants