Skip to content

Commit

Permalink
[Misc] Black auto fix. (dmlc#4697)
Browse files Browse the repository at this point in the history
Co-authored-by: Steve <[email protected]>
  • Loading branch information
frozenbugs and Steve authored Oct 11, 2022
1 parent bd3fe59 commit ea48ce7
Show file tree
Hide file tree
Showing 16 changed files with 1,080 additions and 641 deletions.
57 changes: 31 additions & 26 deletions tests/scripts/ci_report/report.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from urllib.parse import urlparse, urljoin
import os
import requests
import pytest
import json
import enum
from pathlib import Path
import json
import os
import tempfile
from pathlib import Path
from urllib.parse import urljoin, urlparse

import pytest
import requests


class JobStatus(enum.Enum):
Expand All @@ -27,8 +28,8 @@ class JobStatus(enum.Enum):

assert "BUILD_URL" in os.environ, "Are you in the Jenkins environment?"
job_link = os.environ["BUILD_URL"]
response = requests.get('{}wfapi'.format(job_link), verify=False).json()
domain = '{uri.scheme}://{uri.netloc}/'.format(uri=urlparse(job_link))
response = requests.get("{}wfapi".format(job_link), verify=False).json()
domain = "{uri.scheme}://{uri.netloc}/".format(uri=urlparse(job_link))
stages = response["stages"]

final_dict = {}
Expand All @@ -41,37 +42,38 @@ def get_jenkins_json(path):


for stage in stages:
link = stage['_links']['self']['href']
stage_name = stage['name']
link = stage["_links"]["self"]["href"]
stage_name = stage["name"]
res = requests.get(urljoin(domain, link), verify=False).json()
nodes = res['stageFlowNodes']
nodes = res["stageFlowNodes"]
for node in nodes:
nodes_dict[node['id']] = node
nodes_dict[node['id']]['stageName'] = stage_name
nodes_dict[node["id"]] = node
nodes_dict[node["id"]]["stageName"] = stage_name


def get_node_full_name(node, node_dict):
name = ""
while "parentNodes" in node:
name = name + "/" + node["name"]
id = node['parentNodes'][0]
id = node["parentNodes"][0]
if id in nodes_dict:
node = node_dict[id]
else:
break
return name


for key, node in nodes_dict.items():
logs = get_jenkins_json(
node['_links']['log']['href']).get('text', '')
node_name = node['name']
if "Post Actions" in node['stageName']:
logs = get_jenkins_json(node["_links"]["log"]["href"]).get("text", "")
node_name = node["name"]
if "Post Actions" in node["stageName"]:
continue
node_status = node['status']
id = node['id']
node_status = node["status"]
id = node["id"]
full_name = get_node_full_name(node, nodes_dict)
final_dict["{}_{}/{}".format(id, node['stageName'], full_name)] = {
final_dict["{}_{}/{}".format(id, node["stageName"], full_name)] = {
"status": JENKINS_STATUS_MAPPING[node_status],
"logs": logs
"logs": logs,
}

JOB_NAME = os.getenv("JOB_NAME")
Expand All @@ -85,15 +87,18 @@ def get_node_full_name(node, node_dict):
def test_generate_report(test_name):
os.makedirs("./logs_dir/", exist_ok=True)
tmp = tempfile.NamedTemporaryFile(
mode='w', delete=False, suffix=".log", dir="./logs_dir/")
mode="w", delete=False, suffix=".log", dir="./logs_dir/"
)
tmp.write(final_dict[test_name]["logs"])
filename = Path(tmp.name).name
# print(final_dict[test_name]["logs"])
print("Log path: {}".format(prefix+filename))
print("Log path: {}".format(prefix + filename))

if final_dict[test_name]["status"] == JobStatus.FAIL:
pytest.fail(
"Test failed. Please see the log at {}".format(prefix+filename))
"Test failed. Please see the log at {}".format(prefix + filename)
)
elif final_dict[test_name]["status"] == JobStatus.SKIP:
pytest.skip(
"Test skipped. Please see the log at {}".format(prefix+filename))
"Test skipped. Please see the log at {}".format(prefix + filename)
)
10 changes: 6 additions & 4 deletions tests/scripts/ci_report/status.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import os

import requests

JOB_NAME = os.getenv("JOB_NAME")
BUILD_NUMBER = os.getenv("BUILD_NUMBER")
BUILD_ID = os.getenv("BUILD_ID")
COMMIT = os.getenv("GIT_COMMIT")

job_link = os.environ["BUILD_URL"]
response = requests.get('{}wfapi'.format(job_link), verify=False).json()
response = requests.get("{}wfapi".format(job_link), verify=False).json()
status = "✅ CI test succeeded"
for v in response['stages']:
if v['status'] in ['FAILED', 'ABORTED']:
status = "❌ CI test failed in Stage [{}].".format(v['name'])
for v in response["stages"]:
if v["status"] in ["FAILED", "ABORTED"]:
status = "❌ CI test failed in Stage [{}].".format(v["name"])
break

comment = f""" Commit ID: {COMMIT}\n
Expand Down
3 changes: 2 additions & 1 deletion tests/tensorflow/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def test():
pass


if __name__ == "__main__":
test()
test()
Loading

0 comments on commit ea48ce7

Please sign in to comment.