From c41b509385df7ff326a1de73d4a3f15238d2142b Mon Sep 17 00:00:00 2001 From: Shawn Davis Date: Thu, 24 Sep 2020 16:11:12 -0400 Subject: [PATCH] Added wait command. --- docs/source/_data/cloc.csv | 4 ++-- docs/source/_includes/overlays.rst | 13 +++++++++++++ scripttease/library/overlays/posix.py | 13 +++++++++++++ tests/test_library_overlays_posix.py | 6 ++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/source/_data/cloc.csv b/docs/source/_data/cloc.csv index 53a1814..1960bc6 100644 --- a/docs/source/_data/cloc.csv +++ b/docs/source/_data/cloc.csv @@ -1,3 +1,3 @@ files,language,blank,comment,code -22,Python,1044,918,1735 -22,SUM,1044,918,1735 +22,Python,1050,921,1740 +22,SUM,1050,921,1740 diff --git a/docs/source/_includes/overlays.rst b/docs/source/_includes/overlays.rst index 2e854bc..088c777 100644 --- a/docs/source/_includes/overlays.rst +++ b/docs/source/_includes/overlays.rst @@ -898,6 +898,19 @@ Touch a file or directory. [run touch command] touch: path +wait +---- + +Pause execution for a number of seconds. + +- seconds (int): The number of seconds to wait. + + +.. code-block:: ini + + [run wait command] + wait: seconds + write ----- diff --git a/scripttease/library/overlays/posix.py b/scripttease/library/overlays/posix.py index 37bf61b..f5c287e 100644 --- a/scripttease/library/overlays/posix.py +++ b/scripttease/library/overlays/posix.py @@ -27,6 +27,7 @@ __all__ = ( "sed", "symlink", "touch", + "wait", "Function", "Prompt", ) @@ -542,6 +543,17 @@ def touch(path, **kwargs): return Command("touch %s" % path, **kwargs) + +def wait(seconds, **kwargs): + """Pause execution for a number of seconds. + + - seconds (int): The number of seconds to wait. + + """ + kwargs.setdefault("comment", "pause for %s seconds" % seconds) + + return Command("sleep %s" % seconds, **kwargs) + # Classes @@ -740,5 +752,6 @@ POSIX_MAPPINGS = { 'ssl': certbot, 'symlink': symlink, 'touch': touch, + 'wait': wait, 'write': file_write, } diff --git a/tests/test_library_overlays_posix.py b/tests/test_library_overlays_posix.py index b4b51ce..9b5323b 100644 --- a/tests/test_library_overlays_posix.py +++ b/tests/test_library_overlays_posix.py @@ -219,6 +219,12 @@ def test_touch(): assert "touch /path/to/file.txt" in c.get_statement() +def test_wait(): + c = wait(5) + s = c.get_statement() + assert 'sleep 5' in s + + class TestFunction(object): def test_to_string(self):