Skip to content

Commit 66455e6

Browse files
committed
Set http.agent for Robolectric UI tests
1 parent a5ee1e5 commit 66455e6

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

scripts/update_android_ui_test_gradle.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,36 @@
88
import sys
99

1010

11+
TEST_OPTIONS_INJECTION = (
12+
" testOptions {\n"
13+
" unitTests.includeAndroidResources = true\n"
14+
" unitTests.all {\n"
15+
" systemProperty 'http.agent', 'CodenameOneUiTest'\n"
16+
" }\n"
17+
" }\n\n"
18+
)
19+
20+
1121
def ensure_test_options(content: str) -> str:
12-
if "unitTests.includeAndroidResources" in content:
22+
if "systemProperty 'http.agent'" in content:
1323
return content
1424

25+
legacy_block = (
26+
" testOptions {\n"
27+
" unitTests.includeAndroidResources = true\n"
28+
" }\n\n"
29+
)
30+
31+
if legacy_block in content:
32+
return content.replace(legacy_block, TEST_OPTIONS_INJECTION)
33+
1534
pattern = re.compile(r"(android\s*\{\s*\r?\n)")
1635
match = pattern.search(content)
1736
if not match:
1837
raise SystemExit("Unable to locate android block in Gradle file")
1938

20-
injection = (
21-
" testOptions {\n"
22-
" unitTests.includeAndroidResources = true\n"
23-
" }\n\n"
24-
)
2539
start, end = match.span(1)
26-
return content[:end] + injection + content[end:]
40+
return content[:end] + TEST_OPTIONS_INJECTION + content[end:]
2741

2842

2943
def ensure_dependencies(content: str) -> str:

0 commit comments

Comments
 (0)