Skip to content

Commit 04162fc

Browse files
committed
Refactored common implementation
1 parent 3ba127e commit 04162fc

File tree

6 files changed

+24
-39
lines changed

6 files changed

+24
-39
lines changed

launchable/test_runners/file.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@
55
from . import launchable
66

77

8-
@launchable.subset
9-
def subset(client):
10-
# read lines as test file names
11-
for t in client.stdin():
12-
client.test_path(t.rstrip("\n"))
13-
14-
client.run()
15-
8+
subset = launchable.CommonSubsetImpls(__name__).scan_stdin()
169

1710
record_tests = launchable.CommonRecordTestImpls(__name__).file_profile_report_files()
1811

launchable/test_runners/jasmine.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@ def record_tests(client, reports):
1919
client.run()
2020

2121

22-
@launchable.subset
23-
def subset(client):
24-
# read lines as test file names
25-
for t in client.stdin():
26-
client.test_path(t.rstrip("\n"))
27-
28-
client.run()
29-
22+
subset = launchable.CommonSubsetImpls(__name__).scan_stdin()
3023

3124
split_subset = launchable.CommonSplitSubsetImpls(__name__).split_subset()
3225

launchable/test_runners/launchable.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,35 @@ class CommonSubsetImpls:
6363
def __init__(self, module_name):
6464
self.cmdname = cmdname(module_name)
6565

66-
def scan_files(self, pattern):
66+
def scan_stdin(self):
67+
"""
68+
Historical implementation of the files profile that's also used elsewhere.
69+
Reads test one line at a time from stdin. Consider this implementation deprecated.
70+
Newer test runners are advised to use scan_files() without the pattern argument.
71+
"""
72+
def subset(client):
73+
# read lines as test file names
74+
for t in client.stdin():
75+
client.test_path(t.rstrip("\n"))
76+
client.run()
77+
78+
return wrap(subset, subset_cmd, self.cmdname)
79+
80+
def scan_files(self, pattern=None):
6781
"""
6882
Suitable for test runners that use files as unit of tests where file names follow a naming pattern.
6983
7084
:param pattern: file masks that identify test files, such as '*_spec.rb'
85+
for test runners that do not have natural file naming conventions, pass in None,
86+
so that the implementation will refuse to accept directories.
7187
"""
7288
@click.argument('files', required=True, nargs=-1)
7389
def subset(client, files):
7490
# client type: Optimize in def lauchable.commands.subset.subset
7591
def parse(fname: str):
7692
if os.path.isdir(fname):
93+
if pattern is None:
94+
raise click.UsageError(f'{fname} is a directory, but expecting a file or GLOB')
7795
client.scan(fname, '**/' + pattern)
7896
elif fname == '@-':
7997
# read stdin

launchable/test_runners/playwright.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,7 @@ def path_builder(case: TestCase, suite: TestSuite,
5151
client.run()
5252

5353

54-
@launchable.subset
55-
def subset(client):
56-
# read lines as test file names
57-
for t in client.stdin():
58-
client.test_path(t.rstrip("\n"))
59-
60-
client.run()
61-
54+
subset = launchable.CommonSubsetImpls(__name__).scan_stdin()
6255

6356
split_subset = launchable.CommonSplitSubsetImpls(__name__).split_subset()
6457

launchable/test_runners/prove.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ def remove_leading_number_and_dash(input_string: str) -> str:
1414
return result
1515

1616

17-
@launchable.subset
18-
def subset(client):
19-
# read lines as test file names
20-
for t in client.stdin():
21-
client.test_path(t.rstrip("\n"))
22-
23-
client.run()
17+
subset = launchable.CommonSubsetImpls(__name__).scan_stdin()
2418

2519

2620
@click.argument('reports', required=True, nargs=-1)

launchable/test_runners/vitest.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,4 @@ def parse_func(report: str) -> ET.ElementTree:
2828
launchable.CommonRecordTestImpls.load_report_files(client=client, source_roots=reports)
2929

3030

31-
@launchable.subset
32-
def subset(client):
33-
# read lines as test file names
34-
for t in client.stdin():
35-
client.test_path(t.rstrip("\n"))
36-
37-
client.run()
31+
subset = launchable.CommonSubsetImpls(__name__).scan_stdin()

0 commit comments

Comments
 (0)