From ba26d7ca9b434bf8ebd2e76c0ce71fbf3b6062a8 Mon Sep 17 00:00:00 2001 From: Matthew Harrigan Date: Sun, 30 May 2021 11:14:43 -0700 Subject: [PATCH] DISCARD statement, tesets for this statement, and documentation --- shepherd/Tester.py | 19 ++++++++++++++++--- shepherd/testing_script.py | 1 + shepherd/tests/TESTING_DOCS.md | 8 ++++++++ .../discard_tests/discard_client.shepherd | 6 ++++++ .../discard_tests/discard_server.shepherd | 9 +++++++++ .../discard_tests/instructions.shepherd | 2 ++ 6 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 shepherd/tests/testing_tests/discard_tests/discard_client.shepherd create mode 100644 shepherd/tests/testing_tests/discard_tests/discard_server.shepherd create mode 100644 shepherd/tests/testing_tests/discard_tests/instructions.shepherd diff --git a/shepherd/Tester.py b/shepherd/Tester.py index ec550924..ffd4944c 100644 --- a/shepherd/Tester.py +++ b/shepherd/Tester.py @@ -35,7 +35,7 @@ class (source). def parse_header(header): """ A helper function that translates the headers in format - .
to the string representation stored in Utils.py. + .
to the string representation stored in Utils.py. Enforces the syntax for referencing the header, as well as the existance of the header in Utils.py. """ @@ -369,7 +369,7 @@ def assert_function(expression): def sleep_function(expression): """ The function that parses SLEEP statements. - Enforces syntax, and pauses the .shepherd interpreter for the specified + Enforces syntax and pauses the .shepherd interpreter for the specified number of seconds. """ expression = remove_outer_spaces(expression) @@ -381,6 +381,18 @@ def sleep_function(expression): raise Exception(f'expected a time afer after SLEEP, but got {expression}') time.sleep(amount) +def discard_function(expression): + """ + The function that parses DISCARD statements. + Enforces syntax and clears the LCM / YDL queue so that no outstanding requests + are processed. + """ + global EVENTS + if expression != '': + raise Exception('expected nothing after DISCARD statement') + with EVENTS.mutex: + EVENTS.queue.clear() + def read_function(line): """ The function that parses READ statements. @@ -716,7 +728,8 @@ def main(): 'FAIL': fail_function, 'ASSERT': assert_function, '##': lambda line: None, - 'SLEEP': sleep_function + 'SLEEP': sleep_function, + 'DISCARD': discard_function } if __name__ == '__main__': diff --git a/shepherd/testing_script.py b/shepherd/testing_script.py index 05a51851..c8c487ff 100644 --- a/shepherd/testing_script.py +++ b/shepherd/testing_script.py @@ -94,6 +94,7 @@ def start(): # check for help flag if "-h" in sys.argv[1:] or "-help" in sys.argv[1:]: print("testing_script.py takes any number of the following arguments:") + print("leave args empty to run all tests.") print(" to run test groups:") for test_group in test_groups.keys(): print(f" {test_group}") diff --git a/shepherd/tests/TESTING_DOCS.md b/shepherd/tests/TESTING_DOCS.md index 8a053eb5..a4da3a69 100644 --- a/shepherd/tests/TESTING_DOCS.md +++ b/shepherd/tests/TESTING_DOCS.md @@ -66,6 +66,14 @@ time may be a decimal, and is in terms of seconds. SLEEP may take a python expre Usage: `SLEEP