Run yapf on all python files in the repo
Signed-off-by: Ravago Jones <ravagojones@gmail.com>
Change-Id: I221e04c3f517fab8535b22551553799e0fee7a80
diff --git a/scouting/deploy/deploy.py b/scouting/deploy/deploy.py
index c9886fb..5967956 100644
--- a/scouting/deploy/deploy.py
+++ b/scouting/deploy/deploy.py
@@ -3,6 +3,7 @@
import subprocess
import sys
+
def main(argv):
"""Installs the scouting application on the scouting server."""
parser = argparse.ArgumentParser()
@@ -23,11 +24,16 @@
# Copy the .deb to the scouting server, install it, and delete it again.
subprocess.run(["rsync", "-L", args.deb, f"{args.host}:/tmp/{deb.name}"],
- check=True, stdin=sys.stdin)
+ check=True,
+ stdin=sys.stdin)
subprocess.run(f"ssh -tt {args.host} sudo dpkg -i /tmp/{deb.name}",
- shell=True, check=True, stdin=sys.stdin)
+ shell=True,
+ check=True,
+ stdin=sys.stdin)
subprocess.run(f"ssh {args.host} rm -f /tmp/{deb.name}",
- shell=True, check=True, stdin=sys.stdin)
+ shell=True,
+ check=True,
+ stdin=sys.stdin)
if __name__ == "__main__":
diff --git a/scouting/testing/scouting_test_servers.py b/scouting/testing/scouting_test_servers.py
index b6e5c7a..9df23c1 100644
--- a/scouting/testing/scouting_test_servers.py
+++ b/scouting/testing/scouting_test_servers.py
@@ -18,6 +18,7 @@
import time
from typing import List
+
def wait_for_server(port: int):
"""Waits for the server at the specified port to respond to TCP connections."""
while True:
@@ -30,31 +31,37 @@
connection.close()
time.sleep(0.01)
+
def create_db_config(tmpdir: Path) -> Path:
config = tmpdir / "db_config.json"
- config.write_text(json.dumps({
- "username": "test",
- "password": "password",
- "port": 5432,
- }))
+ config.write_text(
+ json.dumps({
+ "username": "test",
+ "password": "password",
+ "port": 5432,
+ }))
return config
+
def create_tba_config(tmpdir: Path) -> Path:
# Configure the scouting webserver to scrape data from our fake TBA
# server.
config = tmpdir / "scouting_config.json"
- config.write_text(json.dumps({
- "api_key": "dummy_key_that_is_not_actually_used_in_this_test",
- "base_url": "http://localhost:7000",
- }))
+ config.write_text(
+ json.dumps({
+ "api_key": "dummy_key_that_is_not_actually_used_in_this_test",
+ "base_url": "http://localhost:7000",
+ }))
return config
+
def set_up_tba_api_dir(tmpdir: Path, year: int, event_code: str):
tba_api_dir = tmpdir / "api" / "v3" / "event" / f"{year}{event_code}"
tba_api_dir.mkdir(parents=True, exist_ok=True)
(tba_api_dir / "matches").write_text(
- Path(f"scouting/scraping/test_data/{year}_{event_code}.json").read_text()
- )
+ Path(f"scouting/scraping/test_data/{year}_{event_code}.json").
+ read_text())
+
class Runner:
"""Helps manage the services we need for testing the scouting app."""
@@ -105,6 +112,7 @@
except FileNotFoundError:
pass
+
def discard_signal(signum, frame):
"""A NOP handler to ignore certain signals.
@@ -113,9 +121,12 @@
"""
pass
+
def main(argv: List[str]):
parser = argparse.ArgumentParser()
- parser.add_argument("--port", type=int, help="The port for the actual web server.")
+ parser.add_argument("--port",
+ type=int,
+ help="The port for the actual web server.")
args = parser.parse_args(argv[1:])
runner = Runner()
diff --git a/scouting/webserver/requests/debug/cli/cli_test.py b/scouting/webserver/requests/debug/cli/cli_test.py
index 2bcd75b..d4310e9 100644
--- a/scouting/webserver/requests/debug/cli/cli_test.py
+++ b/scouting/webserver/requests/debug/cli/cli_test.py
@@ -22,6 +22,7 @@
json_path.write_text(json.dumps(content))
return json_path
+
def run_debug_cli(args: List[str]):
run_result = subprocess.run(
["scouting/webserver/requests/debug/cli/cli_/cli"] + args,
@@ -51,46 +52,71 @@
"year": year,
"event_code": event_code,
})
- exit_code, stdout, stderr = run_debug_cli(["-refreshMatchList", json_path])
+ exit_code, stdout, stderr = run_debug_cli(
+ ["-refreshMatchList", json_path])
self.assertEqual(exit_code, 0, f"{year}{event_code}: {stderr}")
- self.assertIn("(refresh_match_list_response.RefreshMatchListResponseT)", stdout)
+ self.assertIn(
+ "(refresh_match_list_response.RefreshMatchListResponseT)", stdout)
def test_submit_and_request_data_scouting(self):
self.refresh_match_list(year=2020, event_code="fake")
# First submit some data to be added to the database.
json_path = write_json_request({
- "team": 100,
- "match": 1,
- "set_number": 2,
- "comp_level": "quals",
- "starting_quadrant": 3,
- "auto_ball_1": True,
- "auto_ball_2": False,
- "auto_ball_3": False,
- "auto_ball_4": False,
- "auto_ball_5": True,
- "missed_shots_auto": 10,
- "upper_goal_auto": 11,
- "lower_goal_auto": 12,
- "missed_shots_tele": 13,
- "upper_goal_tele": 14,
- "lower_goal_tele": 15,
- "defense_rating": 3,
- "defense_received_rating": 4,
- "climb_level": "Medium",
- "comment": "A very inspiring and useful comment",
+ "team":
+ 100,
+ "match":
+ 1,
+ "set_number":
+ 2,
+ "comp_level":
+ "quals",
+ "starting_quadrant":
+ 3,
+ "auto_ball_1":
+ True,
+ "auto_ball_2":
+ False,
+ "auto_ball_3":
+ False,
+ "auto_ball_4":
+ False,
+ "auto_ball_5":
+ True,
+ "missed_shots_auto":
+ 10,
+ "upper_goal_auto":
+ 11,
+ "lower_goal_auto":
+ 12,
+ "missed_shots_tele":
+ 13,
+ "upper_goal_tele":
+ 14,
+ "lower_goal_tele":
+ 15,
+ "defense_rating":
+ 3,
+ "defense_received_rating":
+ 4,
+ "climb_level":
+ "Medium",
+ "comment":
+ "A very inspiring and useful comment",
})
- exit_code, _, stderr = run_debug_cli(["-submitDataScouting", json_path])
+ exit_code, _, stderr = run_debug_cli(
+ ["-submitDataScouting", json_path])
self.assertEqual(exit_code, 0, stderr)
# Now request the data back with zero indentation. That let's us
# validate the data easily.
json_path = write_json_request({})
- exit_code, stdout, stderr = run_debug_cli(["-requestDataScouting", json_path, "-indent="])
+ exit_code, stdout, stderr = run_debug_cli(
+ ["-requestDataScouting", json_path, "-indent="])
self.assertEqual(exit_code, 0, stderr)
- self.assertIn(textwrap.dedent("""\
+ self.assertIn(
+ textwrap.dedent("""\
{
Team: (int32) 100,
Match: (int32) 1,
@@ -120,10 +146,13 @@
# RequestAllMatches has no fields.
json_path = write_json_request({})
- exit_code, stdout, stderr = run_debug_cli(["-requestAllMatches", json_path])
+ exit_code, stdout, stderr = run_debug_cli(
+ ["-requestAllMatches", json_path])
self.assertEqual(exit_code, 0, stderr)
- self.assertIn("MatchList: ([]*request_all_matches_response.MatchT) (len=90 cap=90) {", stdout)
+ self.assertIn(
+ "MatchList: ([]*request_all_matches_response.MatchT) (len=90 cap=90) {",
+ stdout)
self.assertEqual(stdout.count("MatchNumber:"), 90)
def test_request_matches_for_team(self):
@@ -132,11 +161,14 @@
json_path = write_json_request({
"team": 4856,
})
- exit_code, stdout, stderr = run_debug_cli(["-requestMatchesForTeam", json_path])
+ exit_code, stdout, stderr = run_debug_cli(
+ ["-requestMatchesForTeam", json_path])
# Team 4856 has 12 matches.
self.assertEqual(exit_code, 0, stderr)
- self.assertIn("MatchList: ([]*request_matches_for_team_response.MatchT) (len=12 cap=12) {", stdout)
+ self.assertIn(
+ "MatchList: ([]*request_matches_for_team_response.MatchT) (len=12 cap=12) {",
+ stdout)
self.assertEqual(stdout.count("MatchNumber:"), 12)
self.assertEqual(len(re.findall(r": \(int32\) 4856[,\n]", stdout)), 12)
@@ -148,13 +180,16 @@
# RequestAllMatches has no fields.
json_path = write_json_request({})
- exit_code, stdout, stderr = run_debug_cli(["-requestAllMatches", json_path])
+ exit_code, stdout, stderr = run_debug_cli(
+ ["-requestAllMatches", json_path])
self.assertEqual(exit_code, 0, stderr)
request_all_matches_outputs.append(stdout)
self.maxDiff = None
- self.assertEqual(request_all_matches_outputs[0], request_all_matches_outputs[1])
+ self.assertEqual(request_all_matches_outputs[0],
+ request_all_matches_outputs[1])
+
if __name__ == "__main__":
unittest.main()
diff --git a/scouting/www/index_html_generator.py b/scouting/www/index_html_generator.py
index 3b057fd..bc0e63d 100644
--- a/scouting/www/index_html_generator.py
+++ b/scouting/www/index_html_generator.py
@@ -5,9 +5,11 @@
import sys
from pathlib import Path
+
def compute_sha256(filepath):
return hashlib.sha256(filepath.read_bytes()).hexdigest()
+
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument("--template", type=str)
@@ -20,9 +22,9 @@
bundle_sha256 = compute_sha256(bundle_path)
output = template.format(
- MAIN_BUNDLE_FILE = f"/sha256/{bundle_sha256}/{bundle_path.name}",
- )
+ MAIN_BUNDLE_FILE=f"/sha256/{bundle_sha256}/{bundle_path.name}", )
Path(args.output).write_text(output)
+
if __name__ == "__main__":
sys.exit(main(sys.argv))