in pylib/mercurial-support/run-tests.py [0:0]
def findtests(self, args):
"""Finds possible test files from arguments.
If you wish to inject custom tests into the test harness, this would
be a good function to monkeypatch or override in a derived class.
"""
if not args:
if self.options.changed:
proc = Popen4(
b'hg st --rev "%s" -man0 .'
% _bytespath(self.options.changed),
None,
0,
)
stdout, stderr = proc.communicate()
args = stdout.strip(b'\0').split(b'\0')
else:
args = os.listdir(b'.')
expanded_args = []
for arg in args:
if os.path.isdir(arg):
if not arg.endswith(b'/'):
arg += b'/'
expanded_args.extend([arg + a for a in os.listdir(arg)])
else:
expanded_args.append(arg)
args = expanded_args
testcasepattern = re.compile(br'([\w-]+\.t|py)(?:#([a-zA-Z0-9_\-.#]+))')
tests = []
for t in args:
case = []
if not (
os.path.basename(t).startswith(b'test-')
and (t.endswith(b'.py') or t.endswith(b'.t'))
):
m = testcasepattern.match(os.path.basename(t))
if m is not None:
t_basename, casestr = m.groups()
t = os.path.join(os.path.dirname(t), t_basename)
if casestr:
case = casestr.split(b'#')
else:
continue
if t.endswith(b'.t'):
# .t file may contain multiple test cases
casedimensions = parsettestcases(t)
if casedimensions:
cases = []
def addcases(case, casedimensions):
if not casedimensions:
cases.append(case)
else:
for c in casedimensions[0]:
addcases(case + [c], casedimensions[1:])
addcases([], casedimensions)
if case and case in cases:
cases = [case]
elif case:
# Ignore invalid cases
cases = []
else:
pass
tests += [{'path': t, 'case': c} for c in sorted(cases)]
else:
tests.append({'path': t})
else:
tests.append({'path': t})
return tests