From 4c18f0c42aa842748a512c786e5be87db6bdabd6 Mon Sep 17 00:00:00 2001 From: Matthew Harrigan Date: Sat, 12 Jun 2021 17:49:13 -0700 Subject: [PATCH] tested and finished #51 --- shepherd/sheet.py | 12 +++--- shepherd/tests/TESTING_DOCS.md | 38 +++++++++---------- .../example_outdated.shepherd | 12 +++--- .../examples/example_test/example.shepherd | 14 +++---- .../example_test/example_client.shepherd | 8 ++-- .../staff_ui_test/csv_test/csv_test.shepherd | 24 ++++++------ .../discard_tests/discard_client.shepherd | 6 +-- .../discard_tests/discard_server.shepherd | 8 ++-- .../timeout_tests/timeout_client.shepherd | 4 +- .../timeout_tests/timeout_server.shepherd | 4 +- .../wait_stress_test_client.shepherd | 10 ++--- .../wait_stress_test_server.shepherd | 8 ++-- .../with_infer_client.shepherd | 6 +-- .../with_infer_server.shepherd | 4 +- shepherd/utils.py | 2 + 15 files changed, 80 insertions(+), 80 deletions(-) diff --git a/shepherd/sheet.py b/shepherd/sheet.py index 4c74fda7..c7dd317c 100644 --- a/shepherd/sheet.py +++ b/shepherd/sheet.py @@ -10,15 +10,13 @@ from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials from ydl import ydl_send -from utils import YDL_TARGETS, SHEPHERD_HEADER +from utils import YDL_TARGETS, SHEPHERD_HEADER, CONSTANTS # If modifying these scopes, delete your previously saved credentials # at USER_TOKEN_FILE SCOPES = ['https://www.googleapis.com/auth/spreadsheets'] CLIENT_SECRET_FILE = 'sheets/client_secret.json' -CSV_FILE_NAME = "sheets/Shepherd Evergreen Database - Match Database.csv" USER_TOKEN_FILE = "sheets/user_token.json" # user token; do not upload to github (.gitignore it) -SPREADSHEET_ID = "1JCtt_Iqyx15EOAZN6agqeeUKCFsrL6oOy3brKyAWjBM" class Sheet: @@ -32,12 +30,12 @@ def bg_thread_work(): game_data = [[]] try: spreadsheet = Sheet.__get_authorized_sheet() - game_data = spreadsheet.values().get(spreadsheetId=SPREADSHEET_ID, + game_data = spreadsheet.values().get(spreadsheetId=CONSTANTS.SPREADSHEET_ID, range="Match Database!A2:M").execute()['values'] except: # pylint: disable=bare-except print('[error!] Google API has changed yet again, please fix Sheet.py') print("Fetching data from offline csv file") - with open(CSV_FILE_NAME) as csv_file: + with open(CONSTANTS.CSV_FILE_NAME) as csv_file: game_data = list(csv.reader(csv_file, delimiter=','))[1:] return_len = 12 @@ -98,7 +96,7 @@ def __write_online_scores(match_number, blue_score, gold_score): A method that writes the scores to the sheet """ spreadsheet = Sheet.__get_authorized_sheet() - game_data = spreadsheet.values().get(spreadsheetId=SPREADSHEET_ID, + game_data = spreadsheet.values().get(spreadsheetId=CONSTANTS.SPREADSHEET_ID, range="Match Database!A2:A").execute()['values'] row_num = -1 # if this fails, it'll overwrite the header which is fine @@ -111,5 +109,5 @@ def __write_online_scores(match_number, blue_score, gold_score): body = { 'values': [[str(blue_score), str(gold_score)]] } - spreadsheet.values().update(spreadsheetId=SPREADSHEET_ID, + spreadsheet.values().update(spreadsheetId=CONSTANTS.SPREADSHEET_ID, range=range_name, body=body, valueInputOption="RAW").execute() diff --git a/shepherd/tests/TESTING_DOCS.md b/shepherd/tests/TESTING_DOCS.md index a16dff52..8157bb65 100644 --- a/shepherd/tests/TESTING_DOCS.md +++ b/shepherd/tests/TESTING_DOCS.md @@ -12,17 +12,17 @@ ## Intro -The testing utility was designed as an asynchronous dummy that would be able to mock up the communication between a piece of shepherd and the rest. It is designed to make simple responses to LCM messages sent by the piece of shepherd that is being tested, and it can be used to test any number of shepherd pieces together. Unfortunately, the shepherd testing utility requires LCM to communicate with other parts of shepherd, so a computer without LCM will not be able to run it. +The testing utility was designed as an asynchronous dummy that would be able to mock up the communication between a piece of shepherd and the rest. It is designed to make simple responses to YDL messages sent by the piece of shepherd that is being tested, and it can be used to test any number of shepherd pieces together. Unfortunately, the shepherd testing utility requires YDL to communicate with other parts of shepherd, so a computer without YDL will not be able to run it. -The testing utility communicates via LCM targets, and there are a few important things to be aware of while using the utility. All LCM targets and headers must be included in Utils.py, otherwise the utility will not recognize them. In addition, Utils.py is not imported into the internal environment for python execution that the tester provides. LCM headers and targets will be looked up in Utils.py when they appear in a non-python context, but otherwise they would need to be imported via a RUN statement. Due to underlying limitations, we can only read from one target at a time, so each READ statement will override any previous READ statements, and change our LCM target. Furthermore, we cannot wait on a header from a target before we read from that target, so READ should probably be the first line of your script. +The testing utility communicates via YDL targets, and there are a few important things to be aware of while using the utility. All YDL targets and headers must be included in Utils.py, otherwise the utility will not recognize them. In addition, Utils.py is not imported into the internal environment for python execution that the tester provides. YDL headers and targets will be looked up in Utils.py when they appear in a non-python context, but otherwise they would need to be imported via a RUN statement. Due to underlying limitations, we can only read from one target at a time, so each READ statement will override any previous READ statements, and change our YDL target. Furthermore, we cannot wait on a header from a target before we read from that target, so READ should probably be the first line of your script. While the error recognition and reporting in this utility is helpful, it is not exhaustive. Some disallowed behavior in the following command may not result in a runtime exception, and instead have unexpected and undefined consequences. Adhering to the syntax provided below is the best way to make sure your script works. -It is possible to run multiple .shepherd scripts at once, and have them communicate, however having multiple scripts read from the same LCM target is currently untested and may result in undefined behavior. Also keep in mind that there is no synchronization or timing command in this utility yet, however the RUN command may be used in combination with python timing and synchronization to create the same effect. +It is possible to run multiple .shepherd scripts at once, and have them communicate, however having multiple scripts read from the same YDL target is currently untested and may result in undefined behavior. Also keep in mind that there is no synchronization or timing command in this utility yet, however the RUN command may be used in combination with python timing and synchronization to create the same effect. ## Commands -The testing utility reads in .shepherd testing scripts and emulates the LCM communication per those script's specifications. These scripts use special syntax, which is covered below. +The testing utility reads in .shepherd testing scripts and emulates the YDL communication per those script's specifications. These scripts use special syntax, which is covered below. ### Comments @@ -32,11 +32,11 @@ Usage: `## ` ### READ -The READ statement will mount a listener to the LCM channel that is indicated. +The READ statement will mount a listener to the YDL channel that is indicated. -Typically, this is put at the top of a test file but it is possible to have multiple READ statements in a test. Subsequent READ statements will cause the LCM queue to clear. +Typically, this is put at the top of a test file but it is possible to have multiple READ statements in a test. Subsequent READ statements will cause the YDL queue to clear. -Usage: `READ ` +Usage: `READ ` ### RUN @@ -60,13 +60,13 @@ Usage: `PRINTP ` ### SLEEP -The SLEEP statement is used in order to pause the execution of the .shepherd interpreter for a specified amount of time. Any LCM messages received while the interpreter is paused will still be recorded and may be processed by the next WAIT statement that the interpreter encounters. The sleep time may be a decimal, and is in terms of seconds. SLEEP may take a python expression as an argument, so long as it evaluates to a float. +The SLEEP statement is used in order to pause the execution of the .shepherd interpreter for a specified amount of time. Any YDL messages received while the interpreter is paused will still be recorded and may be processed by the next WAIT statement that the interpreter encounters. The sleep time may be a decimal, and is in terms of seconds. SLEEP may take a python expression as an argument, so long as it evaluates to a float. Usage: `SLEEP