Skip to content

Commit 08fa8aa

Browse files
Hani YacoubHani Yacoub
authored andcommitted
Merge main
2 parents dbacedf + 4fabf88 commit 08fa8aa

14 files changed

+193
-52
lines changed

.github/workflows/l10n.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: L10N Test Execution
33

44
run-name: ${{ github.actor }} is running l10n tests
55
on:
6+
pull_request:
67
workflow_call:
78
inputs:
89
channel:
@@ -37,7 +38,7 @@ env:
3738

3839
jobs:
3940
L10N-MacOS:
40-
if: ${{ inputs.job_to_run == 'L10N-MacOS' || inputs.mac_installer_link }}
41+
if: ${{ inputs.job_to_run == 'L10N-MacOS' || github.event_name == 'pull_request' || inputs.mac_installer_link }}
4142
runs-on: macos-latest
4243
steps:
4344
- name: Create app token
@@ -85,7 +86,7 @@ jobs:
8586
run: |
8687
"$FX_EXECUTABLE" --version;
8788
echo "0" > TEST_EXIT_CODE;
88-
pipenv run python check_l10n_test_cases.py;
89+
pipenv run python choose_l10n_ci_set.py;
8990
while IFS= read -r line; do
9091
echo "Running tests for: $line";
9192
pipenv run python -m l10n_CM.run_l10n --fx-executable="$FX_EXECUTABLE" $line || SCRIPT_EXIT_CODE=$?;
@@ -121,7 +122,7 @@ jobs:
121122
name: artifacts-mac
122123
path: artifacts-mac
123124
L10N-Linux:
124-
if: ${{ inputs.job_to_run == 'L10N-Linux' || inputs.linux_tarball_link }}
125+
if: ${{ inputs.job_to_run == 'L10N-Linux' || github.event_name == 'pull_request' || inputs.linux_tarball_link }}
125126
runs-on: ubuntu-latest
126127
steps:
127128
- name: Create app token
@@ -166,7 +167,7 @@ jobs:
166167
run: |
167168
"$FX_EXECUTABLE" --version;
168169
echo "0" > TEST_EXIT_CODE;
169-
pipenv run python check_l10n_test_cases.py;
170+
pipenv run python choose_l10n_ci_set.py;
170171
Xvfb :99 -screen 0 '1600x1200x24' > artifacts/xvfb.log &
171172
while IFS= read -r line; do
172173
echo "Running tests for: $line";
@@ -203,7 +204,7 @@ jobs:
203204
name: artifacts-linux
204205
path: artifacts-linux
205206
L10N-Windows:
206-
if: ${{ inputs.job_to_run == 'L10N-Windows' || inputs.win_installer_link }}
207+
if: ${{ inputs.job_to_run == 'L10N-Windows' || github.event_name == 'pull_request' || inputs.win_installer_link }}
207208
runs-on: windows-latest
208209
steps:
209210
- name: Create app token
@@ -277,7 +278,7 @@ jobs:
277278
pipenv run python -c "import sys; print(sys.platform)"
278279
$env:FX_EXECUTABLE = 'C:\Program Files\Custom Firefox\firefox.exe'
279280
Start-Process -FilePath $env:FX_EXECUTABLE -ArgumentList "--version" -Wait -NoNewWindow
280-
pipenv run python check_l10n_test_cases.py
281+
pipenv run python choose_l10n_ci_set.py
281282
"0" | Set-Content -Path "TEST_EXIT_CODE"
282283
$SCRIPT_EXIT_CODE = 0
283284
Get-Content "selected_l10n_mappings" | ForEach-Object {
@@ -304,7 +305,7 @@ jobs:
304305
mv ./ci_l10n_pyproject_headed.toml ./pyproject.toml;
305306
$env:FX_EXECUTABLE = 'C:\Program Files\Custom Firefox\firefox.exe'
306307
Write-Host "FX_EXECUTABLE: $FX_EXECUTABLE"
307-
pipenv run python check_l10n_test_cases.py
308+
pipenv run python choose_l10n_ci_set.py
308309
"0" | Set-Content -Path "TEST_EXIT_CODE"
309310
$SCRIPT_EXIT_CODE = 0
310311
Get-Content "selected_l10n_mappings" | ForEach-Object {

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ drivers/
192192
temp.py
193193
tests/test_scratch.py
194194

195+
# L10N files
196+
selected_l10n_mappings
197+
195198
# Credentials
196199
credentials.json
197200
testrail_credentials.env

SELECTOR_INFO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,8 +2135,8 @@ Path to .json: modules/data/generic_page.components.json
21352135
```
21362136
```
21372137
Selector Name: simulated-tracker-dnt-status
2138-
Selector Data: "dnt-on"
2139-
Description: The Do Not Track status
2138+
Selector Data: "dnt-ff"
2139+
Description: The Do Not Track (DNT) status
21402140
Location: Tracker test website
21412141
Path to .json: modules/data/generic_page.components.json
21422142
```

check_l10n_test_cases.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

choose_l10n_ci_set.py

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
import json
2+
import os
3+
import re
4+
import sys
5+
from collections import defaultdict
6+
from subprocess import check_output
7+
8+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
9+
SLASH = "/" if "/" in SCRIPT_DIR else "\\"
10+
CI_MARK = "@pytest.mark.ci"
11+
HEADED_MARK = "@pytest.mark.headed"
12+
OUTPUT_FILE = "selected_l10n_mappings"
13+
14+
15+
def valid_l10n_mappings():
16+
"""
17+
Get a dictionary of valid l10n mappings by going through the region files.
18+
19+
Returns:
20+
The dictionary of valid l10n mappings.
21+
"""
22+
mapping = defaultdict(set)
23+
region_paths = [d for d in os.listdir("./l10n_CM/region/")]
24+
for region_path in region_paths:
25+
if region_path != "Unified.json":
26+
region = region_path.split(".")[0]
27+
with open(f"./l10n_CM/region/{region_path}", "r+") as f:
28+
region_file = json.load(f)
29+
if region_file.get("sites"):
30+
for site in region_file.get("sites"):
31+
mapping[site].add(region)
32+
return mapping
33+
34+
35+
def add_selected_mappings(mappings):
36+
"""
37+
Write the selected mappings to the output file.
38+
39+
Args:
40+
mappings (dict): A dictionary of mappings, where the keys are sites and the values are sets of regions.
41+
"""
42+
for site, regions in mappings.items():
43+
with open(OUTPUT_FILE, "a+") as f:
44+
f.write(f"{site} {' '.join(regions)}\n")
45+
46+
47+
def process_changed_file(f, selected_mappings):
48+
"""
49+
process the changed file to add the site/region mappings.
50+
51+
Args:
52+
f: the changed file.
53+
selected_mappings: the selected mappings dictionary (updated in place).
54+
"""
55+
split = f.split(SLASH)
56+
if f.startswith("l10n_CM/sites/") or f.startswith("l10n_CM/constants/"):
57+
# if constants or sites are changed, add a single site/region mapping entry.
58+
site = split[2]
59+
region = split[3]
60+
region_path = os.path.join("l10n_CM", "region", f"{region}.json")
61+
# make sure the region mapping file exists before adding the mapping
62+
if os.path.exists(region_path):
63+
selected_mappings[site].add(region)
64+
elif f.startswith("l10n_CM/region/"):
65+
# if a region file is changed, add the region to each site mapping.
66+
region = split[-1].split(".")[0]
67+
with open(f, "r+") as f:
68+
region_file = json.load(f)
69+
for site in region_file.get("sites", []):
70+
selected_mappings[site].add(region)
71+
72+
73+
if __name__ == "__main__":
74+
if os.path.exists(".env"):
75+
with open(".env") as fh:
76+
contents = fh.read()
77+
if "TESTRAIL_REPORT='true'" in contents:
78+
os.environ["TESTRAIL_REPORT"] = "true"
79+
if "RUN_ALL='true'" in contents:
80+
os.environ["MANUAL"] = "true"
81+
with open(OUTPUT_FILE, "w") as file:
82+
pass # File is created or cleared
83+
l10n_mappings = valid_l10n_mappings()
84+
if os.environ.get("TESTRAIL_REPORT") or os.environ.get("MANUAL"):
85+
# Run all tests if this is a scheduled beta or a manual run
86+
add_selected_mappings(l10n_mappings)
87+
sys.exit(0)
88+
89+
re_set_all = [
90+
r"l10n_CM/Unified/test_.*\.py",
91+
r"l10n_CM/Unified/conftest\.py",
92+
r"l10n_CM/conftest\.py",
93+
r"modules/page_object_prefs\.py",
94+
r"modules/data/about_prefs\.components\.json",
95+
r"modules/page_object_autofill\.py",
96+
r"modules/data/address_fill\.components\.json",
97+
r"modules/data/credit_card_fill\.components\.json",
98+
r"modules/browser_object_autofill_popup\.py",
99+
r"modules/data/autofill_popup\.components\.json",
100+
]
101+
re_set_select = [
102+
r"l10n_CM/constants/.*/.*/.*\.json",
103+
r"l10n_CM/sites/.*/.*/.*\.html",
104+
r"l10n_CM/region/.*\.json",
105+
]
106+
107+
re_set_all = set(
108+
[
109+
re.compile(val.replace("/", r"\\")) if SLASH == "\\" else re.compile(val)
110+
for val in re_set_all
111+
]
112+
)
113+
re_set_select = set(
114+
[
115+
re.compile(val.replace("/", r"\\")) if SLASH == "\\" else re.compile(val)
116+
for val in re_set_select
117+
]
118+
)
119+
120+
run_list = []
121+
check_output(["git", "fetch", "--quiet", "--depth=1", "origin", "main"])
122+
committed_files = (
123+
check_output(["git", "--no-pager", "diff", "--name-only", "origin/main"])
124+
.decode()
125+
.replace("/", SLASH)
126+
.splitlines()
127+
)
128+
main_conftest = "conftest.py"
129+
base_page = os.path.join("modules", "page_base.py")
130+
131+
if main_conftest in committed_files or base_page in committed_files:
132+
# Run all the tests for all mappings if main conftest or basepage changed
133+
add_selected_mappings(l10n_mappings)
134+
sys.exit(0)
135+
136+
# Run all the tests for all mappings if any core l10n model, component, conftest, or tests are changed.
137+
selected_mappings = defaultdict(set)
138+
# by default, have the demo page run for US
139+
selected_mappings["demo"] = {"US"}
140+
for f in committed_files:
141+
for re_val in re_set_all:
142+
if re_val.match(f):
143+
add_selected_mappings(l10n_mappings)
144+
sys.exit(0)
145+
# check if constants, sites or region directory files were changed or added.
146+
# if so, add the site/region mappings.
147+
for re_val in re_set_select:
148+
if re_val.match(f):
149+
process_changed_file(f, selected_mappings)
150+
151+
add_selected_mappings(selected_mappings)
152+
sys.exit(0)

l10n_CM/constants/bestbuy/US/bestbuy_ad.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
},
1414
"form_field": "*[data-moz-autofill-inspect-id='{name}']",
15-
"skip": "True",
1615
"fields": [
1716
"24fa9bb9-032c-4aa5-a829-8f3c8950cba3",
1817
"ca35b256-a76c-476b-bc50-5e651c0a20fe",
@@ -22,5 +21,14 @@
2221
"1f396341-9cfb-400a-9946-80ac1a721c09",
2322
"afe0ae5c-f224-46f2-9331-aa9b3053dcc8",
2423
"b9c75b09-1531-479e-8823-45d212333bd2"
25-
]
24+
],
25+
"skipped": [
26+
"test_demo_ad_1c_dropdown_phone_email_fields.py",
27+
"test_demo_ad_2c_preview_phone_email_fields.py",
28+
"test_demo_ad_3a_autofill_address_fields.py",
29+
"test_demo_ad_3b_autofill_name_org_fields.py",
30+
"test_demo_ad_3c_autofill_phone_email_fields.py",
31+
"test_demo_ad_4c_highlight_phone_email_fields.py",
32+
"test_demo_ad_5c_clear_phone_email_fields.py"
33+
]
2634
}

l10n_CM/constants/calvinklein/CA/calvinklein_ad.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"telephone": "57aab032-b31d-4bf9-8b7a-3fc5f265f6fc"
1212
},
1313
"form_field": "*[data-moz-autofill-inspect-id='{given_name}']",
14-
"skip": "True",
1514
"fields": [
1615
"7d7a6c7c-7084-477e-afda-b27c826032a8",
1716
"179a5ec2-4a98-45e9-9806-abb5496700d0",
@@ -21,5 +20,14 @@
2120
"a2d9e97a-4dab-44cf-960f-f5bbc1db447a",
2221
"e4ebe951-0ed1-4ea9-b2c2-518b7b2ec034",
2322
"57aab032-b31d-4bf9-8b7a-3fc5f265f6fc"
24-
]
23+
],
24+
"skipped": [
25+
"test_demo_ad_1c_dropdown_phone_email_fields.py",
26+
"test_demo_ad_2c_preview_phone_email_fields.py",
27+
"test_demo_ad_3a_autofill_address_fields.py",
28+
"test_demo_ad_3b_autofill_name_org_fields.py",
29+
"test_demo_ad_3c_autofill_phone_email_fields.py",
30+
"test_demo_ad_4c_highlight_phone_email_fields.py",
31+
"test_demo_ad_5c_clear_phone_email_fields.py"
32+
]
2533
}

l10n_CM/constants/cdiscount/FR/cdiscount_cc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"card_number": "03b45e0e-3ee5-4588-bb52-11c51280b1a1",
55
"expiration_date": "1f545e96-cf5e-4bdd-8f70-8d307f9de357",
66
"cvv": "963fd1a5-05f5-4464-adba-71c1529dc983",
7-
"cardholder_name": "e9f9c0b6-2960-47f0-91ca-74b18b3f1056"
7+
"name": "e9f9c0b6-2960-47f0-91ca-74b18b3f1056"
88
},
99
"form_field": "*[data-moz-autofill-inspect-id='{name}']",
1010
"fields": [

l10n_CM/run_l10n.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import requests
1111

12-
from check_l10n_test_cases import valid_l10n_mappings
12+
from choose_l10n_ci_set import valid_l10n_mappings
1313

1414
current_dir = os.path.dirname(__file__)
1515
valid_flags = {"--run-headless", "-n", "--reruns", "--fx-executable", "--ci"}

modules/data/generic_page.components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949

5050
"simulated-tracker-dnt-status": {
51-
"selectorData": "dnt-on",
51+
"selectorData": "dnt-off",
5252
"strategy": "id",
5353
"groups": []
5454
},

0 commit comments

Comments
 (0)