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
28 changes: 25 additions & 3 deletions launchable/test_runners/maven.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import glob
import os
from typing import Dict, List, Optional
import re
from typing import Dict, List, Optional, Tuple

import click

Expand Down Expand Up @@ -60,9 +61,24 @@ def is_file(f: str) -> bool:
is_flag=True,
help="Scan testCompile/default-testCompile/createdFiles.lst for *.lst files generated by `mvn compile` and use them as test inputs.", # noqa: E501
)
@click.option(
'--exclude',
'exclude_rules',
required=False,
multiple=True,
help="Exclude tests matching the given Python regular expression pattern. Can be specified multiple times.",
)
@click.argument('source_roots', required=False, nargs=-1)
@launchable.subset
def subset(client, source_roots, test_compile_created_file, is_scan_test_compile_lst):
def subset(client, source_roots, test_compile_created_file, is_scan_test_compile_lst, exclude_rules: Tuple[str, ...]):

# Compile exclude rules
compiled_exclude_rules = []
for rule in exclude_rules:
try:
compiled_exclude_rules.append(re.compile(rule))
except re.error as e:
raise click.BadParameter("Invalid regular expression '{}': {}".format(rule, e))

def file2class_test_path(f: str) -> List[Dict[str, str]]:
# remove extension
Expand All @@ -74,7 +90,13 @@ def file2class_test_path(f: str) -> List[Dict[str, str]]:

def file2test(f: str) -> Optional[List]:
if is_file(f):
return file2class_test_path(f)
test_path = file2class_test_path(f)

for pattern in compiled_exclude_rules:
if pattern.search(test_path[0]["name"]):
return None

return test_path
else:
return None

Expand Down
5 changes: 4 additions & 1 deletion tests/data/maven/subset_by_absolute_time_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
{"type": "class", "name": "com.launchableinc.rocket_car_maven.App2Test"}
],
[
{ "type": "class", "name": "com.launchableinc.rocket_car_maven.AppTest"}
{"type": "class", "name": "com.launchableinc.rocket_car_maven.AppTest"}
],
[
{"type": "class", "name": "com.launchableinc.rocket_car_maven.e2e.E2ETest"}
]],
"testRunner": "maven",
"session": {
Expand Down
5 changes: 4 additions & 1 deletion tests/data/maven/subset_by_confidence_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
{"type": "class", "name": "com.launchableinc.rocket_car_maven.App2Test"}
],
[
{ "type": "class", "name": "com.launchableinc.rocket_car_maven.AppTest"}
{"type": "class", "name": "com.launchableinc.rocket_car_maven.AppTest"}
],
[
{"type": "class", "name": "com.launchableinc.rocket_car_maven.e2e.E2ETest"}
]],
"testRunner": "maven",
"session": {
Expand Down
5 changes: 4 additions & 1 deletion tests/data/maven/subset_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
{"type": "class", "name": "com.launchableinc.rocket_car_maven.App2Test"}
],
[
{ "type": "class", "name": "com.launchableinc.rocket_car_maven.AppTest"}
{"type": "class", "name": "com.launchableinc.rocket_car_maven.AppTest"}
],
[
{"type": "class", "name": "com.launchableinc.rocket_car_maven.e2e.E2ETest"}
]],
"testRunner": "maven",
"goal": {"type": "subset-by-percentage", "percentage": 0.1},
Expand Down
17 changes: 17 additions & 0 deletions tests/data/maven/subset_with_exclude_rules_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"testPaths": [
[
{"type": "class", "name": "com.launchableinc.rocket_car_maven.App2Test"}
],
[
{"type": "class", "name": "com.launchableinc.rocket_car_maven.AppTest"}
]],
"testRunner": "maven",
"goal": {"type": "subset-by-percentage", "percentage": 0.1},
"ignoreNewTests": false,
"session": {
"id": "16"
},
"getTestsFromGuess": false,
"getTestsFromPreviousSessions": false
}
19 changes: 19 additions & 0 deletions tests/test_runners/test_maven.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,25 @@ def default_path_builder(case, suite, report_file):
str(self.test_files_dir) + "/maven/reports/TEST-nested.xml")
self.assert_success(result)

@responses.activate
@mock.patch.dict(os.environ, {"LAUNCHABLE_TOKEN": CliTestCase.launchable_token})
def test_subset_with_exclude(self):
# Invalid regexp case
result = self.cli('subset', '--target', '10%', '--session',
self.session, 'maven',
'--exclude', r'[invalid',
str(self.test_files_dir.joinpath('java/test/src/java/').resolve()))
self.assertNotEqual(result.exit_code, 0)
self.assertIn("Invalid regular expression", result.output)

# Success case
result = self.cli('subset', '--target', '10%', '--session',
self.session, 'maven',
'--exclude', r'\.e2e\.',
str(self.test_files_dir.joinpath('java/test/src/java/').resolve()))
self.assert_success(result)
self.assert_subset_payload('subset_with_exclude_rules_result.json')

def test_glob(self):
for x in [
'foo/BarTest.java',
Expand Down
Loading