summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--selftest/testlist.py35
-rw-r--r--selftest/tests/test_testlist.py29
2 files changed, 54 insertions, 10 deletions
diff --git a/selftest/testlist.py b/selftest/testlist.py
index bc88f9d0c0..276b51b812 100644
--- a/selftest/testlist.py
+++ b/selftest/testlist.py
@@ -22,7 +22,6 @@
__all__ = ['find_in_list', 'read_test_regexes', 'read_testlist']
import re
-import sys
def find_in_list(list, fullname):
"""Find test in list.
@@ -87,14 +86,30 @@ def read_testlist(inf, outf):
outf.write(l)
-class TestListFilter(object):
- """Interface for something that can filter a test list."""
+def read_restricted_test_list(f):
+ for l in f.readlines():
+ yield l.strip()
- def should_run_testsuite(self, name):
- """Whether to run a specific testsuite.
- :param name: Name of the testsuite
- :return: List of tests to run. None means run the whole testsuite.
- Return an empty list to not run this testsuite
- """
- raise NotImplementedError(self.should_run_testsuite)
+class RestrictedTestManager(object):
+
+ def __init__(self, test_list):
+ self.test_list = test_list
+ self.unused = set(self.test_list)
+
+ def should_run_testsuite(self, name):
+ match = []
+ for r in self.test_list:
+ if r == name:
+ match = None
+ if r in self.unused:
+ self.unused.remove(r)
+ elif r.startswith(name + "."):
+ if match is not None:
+ match.append(r[len(name+"."):])
+ if r in self.unused:
+ self.unused.remove(r)
+ return match
+
+ def iter_unused(self):
+ return iter(self.unused)
diff --git a/selftest/tests/test_testlist.py b/selftest/tests/test_testlist.py
index 0e7f68bf8e..4405e86003 100644
--- a/selftest/tests/test_testlist.py
+++ b/selftest/tests/test_testlist.py
@@ -20,6 +20,7 @@
"""Tests for selftest.testlist."""
from selftest.testlist import (
+ RestrictedTestManager,
find_in_list,
read_test_regexes,
read_testlist,
@@ -71,3 +72,31 @@ class ReadTestlistTests(unittest.TestCase):
self.assertEquals([('foo', 'bar', 'bla', False, False)],
list(read_testlist(inf, outf)))
self.assertEquals("MORENOISE\nNOISE\n", outf.getvalue())
+
+
+
+class RestrictedTestManagerTests(unittest.TestCase):
+
+ def test_unused(self):
+ mgr = RestrictedTestManager(["foo.bar"])
+ self.assertEquals(["foo.bar"], list(mgr.iter_unused()))
+
+ def test_run_testsuite(self):
+ mgr = RestrictedTestManager(["foo.bar"])
+ self.assertEquals(None, mgr.should_run_testsuite("foo.bar"))
+
+ def test_run_subtest(self):
+ mgr = RestrictedTestManager(["foo.bar.bla"])
+ self.assertEquals(["bla"], mgr.should_run_testsuite("foo.bar"))
+
+ def test_run_subtest_after_testsuite(self):
+ mgr = RestrictedTestManager(["foo.bar", "foo.bar.bla"])
+ self.assertEquals(None, mgr.should_run_testsuite("foo.bar"))
+
+ def test_run_multiple_subtests(self):
+ mgr = RestrictedTestManager(["foo.bar.blie", "foo.bar.bla"])
+ self.assertEquals(["blie", "bla"], mgr.should_run_testsuite("foo.bar"))
+
+ def test_run_nomatch(self):
+ mgr = RestrictedTestManager(["foo.bar"])
+ self.assertEquals([], mgr.should_run_testsuite("foo.blie.bla"))