summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSamuel Bancal <Samuel.Bancal@epfl.ch>2015-02-12 15:23:02 +0100
committerSamuel Bancal <Samuel.Bancal@epfl.ch>2015-02-12 15:23:02 +0100
commit37665f9add48760c1d4ad8c1909da4d8645e3146 (patch)
tree73ef5b5638a9d5bb24a8c40d7d27b5e5aa1d1195 /tests
parent450f390eaecf88ad95f429ce8b5d03fc8381f158 (diff)
downloadpexpect-git-37665f9add48760c1d4ad8c1909da4d8645e3146.tar.gz
Allows also method callback for events argument in pexpect.run()
Updated test_run.py for this case
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_run.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test_run.py b/tests/test_run.py
index c018b4d..286bf69 100755
--- a/tests/test_run.py
+++ b/tests/test_run.py
@@ -35,6 +35,20 @@ def timeout_callback (d):
return 1
return 0
+def function_events_callback (d):
+ try:
+ previous_echoed = d["child_result_list"][-1].decode().split("\n")[-2].strip()
+ if previous_echoed.endswith("foo1"):
+ return "echo foo2\n"
+ elif previous_echoed.endswith("foo2"):
+ return "echo foo3\n"
+ elif previous_echoed.endswith("foo3"):
+ return "exit\n"
+ else:
+ raise Exception("Unexpected output {0}".format(previous_echoed))
+ except IndexError:
+ return "echo foo1\n"
+
class RunFuncTestCase(PexpectTestCase.PexpectTestCase):
runfunc = staticmethod(pexpect.run)
cr = b'\r'
@@ -88,6 +102,44 @@ class RunFuncTestCase(PexpectTestCase.PexpectTestCase):
timeout=10)
assert exitstatus == 0
+ def test_run_function (self):
+ events = [
+ ('GO:', function_events_callback)
+ ]
+
+ (data, exitstatus) = pexpect.run(
+ 'bash --rcfile {0}'.format(self.rcfile),
+ withexitstatus=True,
+ events=events,
+ timeout=10)
+ assert exitstatus == 0
+
+ def test_run_method (self):
+ events = [
+ ('GO:', self.method_events_callback)
+ ]
+
+ (data, exitstatus) = pexpect.run(
+ 'bash --rcfile {0}'.format(self.rcfile),
+ withexitstatus=True,
+ events=events,
+ timeout=10)
+ assert exitstatus == 0
+
+ def method_events_callback (self, d):
+ try:
+ previous_echoed = d["child_result_list"][-1].decode().split("\n")[-2].strip()
+ if previous_echoed.endswith("foo1"):
+ return "echo foo2\n"
+ elif previous_echoed.endswith("foo2"):
+ return "echo foo3\n"
+ elif previous_echoed.endswith("foo3"):
+ return "exit\n"
+ else:
+ raise Exception("Unexpected output {0}".format(previous_echoed))
+ except IndexError:
+ return "echo foo1\n"
+
class RunUnicodeFuncTestCase(RunFuncTestCase):
runfunc = staticmethod(pexpect.runu)
cr = b'\r'.decode('ascii')