summaryrefslogtreecommitdiff
path: root/tests/ecore/test_08_exe.py
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2016-10-02 09:56:27 +0200
committerDave Andreoli <dave@gurumeditation.it>2016-10-02 09:56:27 +0200
commit99c618fc2b4d1e91047c049411d65d3b568ba126 (patch)
treefc5fef97556c463543e286fd508903d32fd8d878 /tests/ecore/test_08_exe.py
parent1a2b8e64f8987e7b5b17d3a96dcf23039b6076b5 (diff)
Remove ecore warning about subprocess incompatibility
This conflict seems to not exists anymore, the added test should prove it Also removed unused return values from the existing exe test (cherry picked from commit 191af7ac380ab87d29e4886fe07cd02b8dd5afa9)
Diffstat (limited to 'tests/ecore/test_08_exe.py')
-rw-r--r--tests/ecore/test_08_exe.py89
1 files changed, 77 insertions, 12 deletions
diff --git a/tests/ecore/test_08_exe.py b/tests/ecore/test_08_exe.py
index adde85f..567dfa9 100644
--- a/tests/ecore/test_08_exe.py
+++ b/tests/ecore/test_08_exe.py
@@ -4,11 +4,88 @@
4import os 4import os
5import unittest 5import unittest
6import logging 6import logging
7import subprocess
7 8
8from efl import ecore 9from efl import ecore
9 10
10 11
11script_path = os.path.dirname(os.path.realpath(__file__)) 12script_path = os.path.dirname(os.path.realpath(__file__))
13helper = os.path.join(script_path, "exe_helper.sh")
14
15
16# basic read flags with line support
17flags = ecore.ECORE_EXE_PIPE_READ | \
18 ecore.ECORE_EXE_PIPE_READ_LINE_BUFFERED | \
19 ecore.ECORE_EXE_TERM_WITH_PARENT
20
21
22class TestExeSubprocess(unittest.TestCase):
23 def testInit(self):
24 self.exe_terminated = False
25 self.num_lines_from_exe = 0
26 self.num_lines_from_popen = 0
27 self.check_output_tested = False
28 self.call_tested = False
29
30 # spawn a "slow" ecore.Exe child (will start on ml begin)
31 exe = ecore.Exe("%s 0.001" % helper, flags)
32 exe.on_add_event_add(self.on_exe_add)
33 exe.on_data_event_add(self.on_exe_data)
34 exe.on_del_event_add(self.on_exe_del)
35
36 # start ml with a 5 secs timeout
37 t = ecore.timer_add(5, ecore.main_loop_quit)
38 ecore.main_loop_begin()
39 t.delete()
40
41 # do the ecore exe terminate? (timeout not expired)
42 self.assertEqual(self.exe_terminated, True)
43
44 # do ecore exe received all the expected lines?
45 self.assertEqual(self.num_lines_from_exe, 1000)
46
47 # do the subprocess.call() test runs?
48 self.assertEqual(self.call_tested, True)
49
50 # do the subprocess.check_output() test runs?
51 self.assertEqual(self.check_output_tested, True)
52
53 # wait for the popen process to succesfully terminate
54 out, err = self.proc.communicate()
55 self.assertEqual(err, None)
56
57 # do we received all the expected lines from popen?
58 self.num_lines_from_popen += len(out.split())
59 self.assertEqual(self.num_lines_from_popen, 1000)
60
61 def on_exe_add(self, exe, event):
62 self.assertIsInstance(event, ecore.EventExeAdd)
63
64 # subprocess.call() in the middle of ecore.Exe (sync)
65 ret = subprocess.call("%s 0.0 >/dev/null" % helper, shell=True)
66 self.assertEqual(ret, 0)
67 self.call_tested = True
68
69 # subprocess.check_output() in the middle of ecore.Exe (sync)
70 out = subprocess.check_output([helper, "0.0"])
71 self.assertEqual(len(out.split()), 1000)
72 self.check_output_tested = True
73
74 # spawn a Popen child, will read it's output later (async)
75 self.proc = subprocess.Popen([helper, "0.0"], stdout=subprocess.PIPE)
76
77 def on_exe_data(self, exe, event):
78 self.assertIsInstance(event, ecore.EventExeData)
79 self.num_lines_from_exe += len(event.lines)
80
81 # read a single line from the Popen process stdout
82 self.proc.stdout.readline() # WARNING: this one is blocking
83 self.num_lines_from_popen += 1
84
85 def on_exe_del(self, exe, event):
86 self.assertIsInstance(event, ecore.EventExeDel)
87 self.exe_terminated = True
88 ecore.main_loop_quit()
12 89
13 90
14class TestExe(unittest.TestCase): 91class TestExe(unittest.TestCase):
@@ -17,11 +94,6 @@ class TestExe(unittest.TestCase):
17 self.num_del = 0 94 self.num_del = 0
18 self.num_data = 0 95 self.num_data = 0
19 96
20 # basic read flags with line support
21 flags = ecore.ECORE_EXE_PIPE_READ | \
22 ecore.ECORE_EXE_PIPE_READ_LINE_BUFFERED | \
23 ecore.ECORE_EXE_TERM_WITH_PARENT
24
25 # EXE 1: simple ls -la output, monitor for add, del and data (stdout) 97 # EXE 1: simple ls -la output, monitor for add, del and data (stdout)
26 def on_add(x, event, a, b, c): 98 def on_add(x, event, a, b, c):
27 self.assertEqual(x, exe1) 99 self.assertEqual(x, exe1)
@@ -30,20 +102,17 @@ class TestExe(unittest.TestCase):
30 self.assertEqual(b, 2) 102 self.assertEqual(b, 2)
31 self.assertEqual(c, 3) 103 self.assertEqual(c, 3)
32 self.num_add += 1 104 self.num_add += 1
33 return ecore.ECORE_CALLBACK_RENEW
34 105
35 def on_del(x, event): 106 def on_del(x, event):
36 self.assertEqual(x, exe1) 107 self.assertEqual(x, exe1)
37 self.assertIsInstance(event, ecore.EventExeDel) 108 self.assertIsInstance(event, ecore.EventExeDel)
38 self.num_del += 1 109 self.num_del += 1
39 return ecore.ECORE_CALLBACK_RENEW
40 110
41 def on_data(x, event): 111 def on_data(x, event):
42 self.assertEqual(x, exe1) 112 self.assertEqual(x, exe1)
43 self.assertIsInstance(event, ecore.EventExeData) 113 self.assertIsInstance(event, ecore.EventExeData)
44 self.assertTrue(len(event.lines) >= 13) #we have at least 13 files here 114 self.assertTrue(len(event.lines) >= 13) #we have at least 13 files here
45 self.num_data += 1 115 self.num_data += 1
46 return ecore.ECORE_CALLBACK_RENEW
47 116
48 exe1 = ecore.Exe('ls -l "%s"' % script_path, flags) 117 exe1 = ecore.Exe('ls -l "%s"' % script_path, flags)
49 exe1.on_add_event_add(on_add, 1, c=3, b=2) 118 exe1.on_add_event_add(on_add, 1, c=3, b=2)
@@ -81,14 +150,12 @@ class TestExe(unittest.TestCase):
81 self.assertIsInstance(event, ecore.EventExeAdd) 150 self.assertIsInstance(event, ecore.EventExeAdd)
82 x.send(b"123\nabc\nxyz\n") 151 x.send(b"123\nabc\nxyz\n")
83 self.num_add += 1 152 self.num_add += 1
84 return ecore.ECORE_CALLBACK_RENEW
85 153
86 def on_cat_pipe_del(x, event): 154 def on_cat_pipe_del(x, event):
87 self.assertEqual(x, exe3) 155 self.assertEqual(x, exe3)
88 self.assertIsInstance(event, ecore.EventExeDel) 156 self.assertIsInstance(event, ecore.EventExeDel)
89 157
90 self.num_del += 1 158 self.num_del += 1
91 return ecore.ECORE_CALLBACK_RENEW
92 159
93 def on_cat_pipe_data(x, event): 160 def on_cat_pipe_data(x, event):
94 self.assertEqual(x, exe3) 161 self.assertEqual(x, exe3)
@@ -96,7 +163,6 @@ class TestExe(unittest.TestCase):
96 self.assertEqual(event.lines, ["123", "abc", "xyz"]) 163 self.assertEqual(event.lines, ["123", "abc", "xyz"])
97 x.on_data_event_del(on_cat_pipe_data) 164 x.on_data_event_del(on_cat_pipe_data)
98 self.num_data += 1 165 self.num_data += 1
99 return ecore.ECORE_CALLBACK_CANCEL
100 166
101 def on_cat_pipe_data2(x, event): 167 def on_cat_pipe_data2(x, event):
102 self.assertEqual(x, exe3) 168 self.assertEqual(x, exe3)
@@ -106,7 +172,6 @@ class TestExe(unittest.TestCase):
106 x.on_data_event_del(on_cat_pipe_data2) 172 x.on_data_event_del(on_cat_pipe_data2)
107 x.kill() 173 x.kill()
108 self.num_data += 1 174 self.num_data += 1
109 return ecore.ECORE_CALLBACK_RENEW
110 175
111 exe3 = ecore.Exe("cat", flags | ecore.ECORE_EXE_PIPE_WRITE) 176 exe3 = ecore.Exe("cat", flags | ecore.ECORE_EXE_PIPE_WRITE)
112 exe3.on_add_event_add(on_cat_pipe_add) 177 exe3.on_add_event_add(on_cat_pipe_add)