Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions reframe/frontend/check_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

import reframe.core.runtime as rt
import reframe.utility.sanity as util
from reframe.core.exceptions import ReframeError


def re_compile(patt):
try:
return re.compile(patt)
except re.error:
raise ReframeError("invalid regex: '%s'" % patt)


def have_name(patt):
regex = re.compile(patt)
regex = re_compile(patt)

def _fn(c):
return regex.match(c.name)
Expand All @@ -21,7 +29,7 @@ def _fn(c):


def have_tag(patt):
regex = re.compile(patt)
regex = re_compile(patt)

def _fn(c):
return any(regex.match(p) for p in c.tags)
Expand All @@ -30,7 +38,7 @@ def _fn(c):


def have_prgenv(patt):
regex = re.compile(patt)
regex = re_compile(patt)

def _fn(c):
if '*' in c.valid_prog_environs:
Expand Down
16 changes: 16 additions & 0 deletions unittests/test_check_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import reframe.utility.sanity as sn
import unittests.fixtures as fixtures
from reframe.core.pipeline import RegressionTest
from reframe.core.exceptions import ReframeError


class TestCheckFilters(unittest.TestCase):
Expand Down Expand Up @@ -90,3 +91,18 @@ def test_have_gpu_only(self):

def test_have_cpu_only(self):
self.assertEqual(1, self.count_checks(filters.have_cpu_only()))

def test_invalid_regex(self):
# We need to explicitly call `evaluate` to make sure the exception
# is triggered in all cases
with self.assertRaises(ReframeError):
self.count_checks(filters.have_name('*foo')).evaluate()

with self.assertRaises(ReframeError):
self.count_checks(filters.have_not_name('*foo')).evaluate()

with self.assertRaises(ReframeError):
self.count_checks(filters.have_tag('*foo')).evaluate()

with self.assertRaises(ReframeError):
self.count_checks(filters.have_prgenv('*foo')).evaluate()