Skip to content

Commit

Permalink
added SLEEP tests and support for python expressions in the SLEEP sta…
Browse files Browse the repository at this point in the history
…tement
  • Loading branch information
FIREdog5 committed May 29, 2021
1 parent 5f1472e commit fc84b5c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions shepherd/Tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,10 @@ def sleep_function(expression):
if expression == '':
raise Exception('expected a time afer after SLEEP')
try:
amount = float(expression)
amount = float(evaluate_python(expression))
except ValueError as e:
raise Exception(f'expected a time afer after SLEEP, but got {expression}')
time.Sleep(amount)
time.sleep(amount)

def read_function(line):
"""
Expand Down
4 changes: 2 additions & 2 deletions shepherd/tests/TESTING_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ Usage: `PRINTP <python expression>`

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.
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 <time>`
Usage: `SLEEP <time / python expression>`

### IF

Expand Down
25 changes: 25 additions & 0 deletions shepherd/tests/testing_tests/sleep_test.shepherd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## small wait test
RUN import time
RUN start = time.time()
SLEEP .1
RUN end = time.time()
RUN delta = end - start
RUN epsilon = abs(delta - .1)
PRINTP epsilon
FAIL epsilon > .001
## large wait test
RUN start = time.time()
SLEEP 10
RUN end = time.time()
RUN delta = end - start
RUN epsilon = abs(delta - 10)
PRINTP epsilon
FAIL epsilon > .02
## very large wait test
RUN start = time.time()
SLEEP 100
RUN end = time.time()
RUN delta = end - start
RUN epsilon = abs(delta - 100)
PRINTP epsilon
ASSERT epsilon < .15

1 comment on commit fc84b5c

@FIREdog5
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#48

Please sign in to comment.