Skip to content

Commit

Permalink
fix: flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
FritzHeiden committed Jan 8, 2025
1 parent 4238981 commit 3112517
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 89 deletions.
26 changes: 6 additions & 20 deletions tools/wave/testing/tests_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@


class TestsManager(object):
def initialize(
self, test_loader, sessions_manager, results_manager, event_dispatcher
):
def initialize(self, test_loader, sessions_manager, results_manager, event_dispatcher):
self._test_loader = test_loader
self._sessions_manager = sessions_manager
self._results_manager = results_manager
Expand Down Expand Up @@ -105,11 +103,7 @@ def read_last_completed_tests(self, token, count):
tests["pass"].append(result["test"])
if not passes and len(tests["fail"]) < count:
tests["fail"].append(result["test"])
if (
len(tests["pass"]) == count
and len(tests["fail"]) == count
and len(tests["timeout"]) == count
):
if len(tests["pass"]) == count and len(tests["fail"]) == count and len(tests["timeout"]) == count:
return tests
return tests

Expand Down Expand Up @@ -142,11 +136,7 @@ def compare(tests_manager, test_a, test_b):
return -1
return 1

sorted_tests.sort(
key=functools.cmp_to_key(
lambda test_a, test_b: compare(self, test_a, test_b)
)
)
sorted_tests.sort(key=functools.cmp_to_key(lambda test_a, test_b: compare(self, test_a, test_b)))
return sorted_tests

def _get_next_test_from_list(self, tests):
Expand Down Expand Up @@ -217,13 +207,11 @@ def skip_to(self, test_list, test):
if test not in sorted_tests:
return test_list
index = sorted_tests.index(test)
remaining_tests = sorted_tests[index + 1 :]
remaining_tests = sorted_tests[index + 1:]
remaining_tests_by_api = {}
current_api = "___"
for test in remaining_tests:
if not test.startswith("/" + current_api) and not test.startswith(
current_api
):
if not test.startswith("/" + current_api) and not test.startswith(current_api):
current_api = next((p for p in test.split("/") if p != ""), None)
if current_api not in remaining_tests_by_api:
remaining_tests_by_api[current_api] = []
Expand Down Expand Up @@ -308,9 +296,7 @@ def complete_test(self, test, session):

self.update_tests(running_tests=running_tests, session=session)

self._event_dispatcher.dispatch_event(
dispatcher_token=session.token, event_type=TEST_COMPLETED_EVENT, data=test
)
self._event_dispatcher.dispatch_event(dispatcher_token=session.token, event_type=TEST_COMPLETED_EVENT, data=test)

def update_tests(self, pending_tests=None, running_tests=None, session=None):
if pending_tests is not None:
Expand Down
6 changes: 3 additions & 3 deletions tools/wave/testing/wpt_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def generate_report(
"--pass", "100",
"--ref", reference_dir if reference_dir is not None else "",
"--testsBaseUrl", tests_base_url
]
]
subprocess.call(command, shell=False)
except subprocess.CalledProcessError as e:
info = sys.exc_info()
raise Exception("Failed to execute wptreport: " + str(info[0].__name__) + ": " + e.output)
except FileNotFoundError as e:
except FileNotFoundError:
raise Exception("Failed to execute wptreport: " + " ".join(command))


Expand Down Expand Up @@ -67,4 +67,4 @@ def is_wptreport_installed():
subprocess.check_output(["wptreport", "--help"])
return True
except Exception:
return False
return False
93 changes: 47 additions & 46 deletions tools/wave/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# mypy: allow-untyped-defs

import pytest
import requests
import json
import copy


def test_import_results():
# Arrange
token = create_session()
Expand All @@ -17,10 +17,10 @@ def test_import_results():
print(api)
print(test)
start_session(token)
next_test = read_next_test(token)
read_next_test(token)
create_positive_result(token, test)
next_test = read_next_test(token)
read_next_test(token)

# Act
url = "/".join([get_url(), "api/results", token, api, "json"])
r = requests.get(url)
Expand All @@ -31,19 +31,20 @@ def test_import_results():
url = "/".join([get_url(), "api/results", token, api, "json"])
r = requests.post(url, data=json.dumps(new_results))
status_code = r.status_code

url = "/".join([get_url(), "api/results", token, api, "json"])
r = requests.get(url)
updated_results = r.json()

# Assert
assert status_code == 200
assert updated_results == new_results
assert updated_results != old_results

# CleanUp
delete_session(token)



def test_last_completed_tests():
# Arrange
token = create_session()
Expand All @@ -56,111 +57,111 @@ def test_last_completed_tests():
print(api)
print(test)
start_session(token)
next_test = read_next_test(token)
read_next_test(token)
create_timed_out_result(token, test)
next_test = read_next_test(token)
read_next_test(token)

# Act
url = "/".join([get_url(), "api/tests/", token, "/last_completed"])
r = requests.get(url)
status_code = r.status_code
url = "/".join([get_url(), "api/results", token, api, "json"])
r = requests.get(url)
updated_results = r.json()

# url = "/".join([get_url(), "api/results", token, api, "json"])
# r = requests.get(url)
# updated_results = r.json()

# Assert
assert status_code == 200

# CleanUp
delete_session(token)



def create_session():
url = "/".join([get_url(), "api/sessions"])
r = requests.post(url)
response_payload = r.json()
token = response_payload["token"]
return token


def read_session(token):
url = "/".join([get_url(), "api/sessions", token])
r = requests.get(url)
session = r.json()
return session


def read_session_status(token):
url = "/".join([get_url(), "api/sessions", token, "status"])
r = requests.get(url)
status = r.json()
return status



def read_available_tests():
url = "/".join([get_url(), "api/tests"])
r = requests.get(url)
tests = r.json()
return tests


def set_session_tests(token, tests):
url = "/".join([get_url(), "api/sessions", token])
config = {
"tests": {
"include": tests
}
}

r = requests.put(url, data=json.dumps(config))

config = {"tests": {"include": tests}}

requests.put(url, data=json.dumps(config))


def read_next_test(token):
url = "/".join([get_url(), "api/tests", token, "next"])
r = requests.get(url)
next_test = r.json()["next_test"]
return next_test


def start_session(token):
url = "/".join([get_url(), "api/sessions", token, "start"])
r = requests.post(url)

requests.post(url)


def create_result(token, test, result):
url = "/".join([get_url(), "api/results", token])
r = requests.post(url, data=json.dumps(result))
print(r.status_code)
print(result)



def create_positive_result(token, test):
result = {
"test": test,
"status": "OK",
"message": None,
"subtests": [
{"name": "Subtest xy", "status": "PASS", "message": None}
]
"subtests": [{"name": "Subtest xy", "status": "PASS", "message": None}],
}

create_result(token, test, result)


def create_timed_out_result(token, test):
result = {
"test": test,
"status": "TIMEOUT",
"message": None,
"subtests": []
}

result = {"test": test, "status": "TIMEOUT", "message": None, "subtests": []}

create_result(token, test, result)



def read_session_tests(token):
url = "/".join([get_url(), "api/tests", token])
r = requests.get(url)
tests = r.json()
return tests


def delete_session(token):
url = "/".join([get_url(), "api/sessions", token])
r = requests.delete(url)
requests.delete(url)


def get_url():
host = "127.0.0.1:8000"
base_url = "_wave"
return "/".join(["http:/", host, base_url])
return "/".join(["http:/", host, base_url])
46 changes: 26 additions & 20 deletions tools/wave/wave-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,38 @@
REFERENCE_BROWSERS = {
"chrome": {
"name": "Chromium 73.0.3640.0",
"url": "https://s3.us-east-2.amazonaws.com/wave-browser-snapshots/wave-reference-browser-results/WMAS+2018/Chromium73-a50c6db0-6a94-11e9-8d1b-e23fc4555885.zip"
"url": "https://s3.us-east-2.amazonaws.com/wave-browser-snapshots\
/wave-reference-browser-results/WMAS+2018\
/Chromium73-a50c6db0-6a94-11e9-8d1b-e23fc4555885.zip",
},
"edge": {
"name": "Edge 44.17763",
"url": "https://s3.us-east-2.amazonaws.com/wave-browser-snapshots/wave-reference-browser-results/WMAS+2018/Edge44-b2924d20-6a93-11e9-98b4-a11fb92a6d1c.zip"
"url": "https://s3.us-east-2.amazonaws.com/wave-browser-snapshots\
/wave-reference-browser-results/WMAS+2018\
/Edge44-b2924d20-6a93-11e9-98b4-a11fb92a6d1c.zip",
},
"firefox": {
"name": "Firefox 64.0",
"url":
"https://s3.us-east-2.amazonaws.com/wave-browser-snapshots/wave-reference-browser-results/WMAS+2018/Firefox64-bb7aafa0-6a92-11e9-8ec2-04f58dad2e4f.zip"
"url": "https://s3.us-east-2.amazonaws.com/wave-browser-snapshots\
/wave-reference-browser-results/WMAS+2018\
/Firefox64-bb7aafa0-6a92-11e9-8ec2-04f58dad2e4f.zip",
},
"webkit": {
"name": "WebKit r239158",
"url":
"https://s3.us-east-2.amazonaws.com/wave-browser-snapshots/wave-reference-browser-results/WMAS+2018/WebKitr239158-caf823e0-6a92-11e9-b732-3188d0065ebc.zip"
}
"url": "https://s3.us-east-2.amazonaws.com/wave-browser-snapshots\
/wave-reference-browser-results/WMAS+2018\
/WebKitr239158-caf823e0-6a92-11e9-b732-3188d0065ebc.zip",
},
}


def main() -> None:
parameters = get_run_parameters()
configuration_file_path = None
if ("configuration_file_path" in parameters):
configuration_file_path = parameters["configuration_file_path"]
# configuration_file_path = None
# if ("configuration_file_path" in parameters):
# configuration_file_path = parameters["configuration_file_path"]

if (parameters["operation"] == DOWNLOAD_REFERENCE_BROWSERS):
if parameters["operation"] == DOWNLOAD_REFERENCE_BROWSERS:
download_reference_browsers()


Expand All @@ -55,7 +61,7 @@ def get_run_parameters():
next(iterator)
next(iterator)
for argument in iterator:
if (argument.lower() == "--config"):
if argument.lower() == "--config":
path = next(iterator)
if not path.startswith("/"):
path = os.path.join(os.getcwd(), path)
Expand All @@ -65,8 +71,8 @@ def get_run_parameters():
raise Exception("Unknown option {}".format(argument))

if "configuration_file_path" not in parameters:
parameters["configuration_file_path"] = os.path.join(
os.getcwd(), "config.json")
configuration_file_path = os.path.join(os.getcwd(), "config.json")
parameters["configuration_file_path"] = configuration_file_path

return parameters

Expand Down Expand Up @@ -94,22 +100,22 @@ def download_reference_browsers():
browser = REFERENCE_BROWSERS[id]
browser["zip"] = browser["url"].split("/")[-1]
printt("Downloading {} results ...".format(browser["name"]))
download_file(browser["url"], os.path.join(
result_directory, browser["zip"]))
dest_path = os.path.join(result_directory, browser["zip"])
download_file(browser["url"], dest_path)
print(" done.")

for id in REFERENCE_BROWSERS:
browser = REFERENCE_BROWSERS[id]
printt("Extracting {} results ...".format(browser["name"]))
zip_file = zipfile.ZipFile(os.path.join(
result_directory, browser["zip"]))
dest_path = os.path.join(result_directory, browser["name"])
zip_file = zipfile.ZipFile(dest_path)
zip_file.extractall(result_directory)
print(" done.")

print("Cleaning ...")
for id in REFERENCE_BROWSERS:
browser = REFERENCE_BROWSERS[id]
os.remove(os.path.join(
result_directory, browser["zip"]))
os.remove(os.path.join(result_directory, browser["zip"]))


main()

0 comments on commit 3112517

Please sign in to comment.