aboutsummaryrefslogtreecommitdiffstats
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
parentsmall doc fix (diff)
downloadpython-efl-99c618fc2b4d1e91047c049411d65d3b568ba126.tar.gz
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)
-rw-r--r--efl/ecore/efl.ecore.pyx42
-rwxr-xr-xtests/ecore/exe_helper.sh14
-rw-r--r--tests/ecore/test_08_exe.py89
3 files changed, 113 insertions, 32 deletions
diff --git a/efl/ecore/efl.ecore.pyx b/efl/ecore/efl.ecore.pyx
index f1b35d9..25b6196 100644
--- a/efl/ecore/efl.ecore.pyx
+++ b/efl/ecore/efl.ecore.pyx
@@ -426,27 +426,29 @@ atexit.register(shutdown)
#---------------------------------------------------------------------------
+# This conflict seems to not exists anymore, see tests/ecore/test_08_exe.py
+#---------------------------------------------------------------------------
# let's try to warn users that ecore conflicts with subprocess module
-import subprocess
-
-_orig_subprocess = None
-
-def subprocess_warning(*a, **ka):
- print(""" DEVELOPER WARNING:
- Using subprocess (Popen and derivatives) with Ecore is a bad idea.
-
- Ecore will set some signal handlers subprocess module depends and this
- may cause this module to operate unexpectedly.
-
- Instead of using subprocess.Popen(), please consider using Ecore's
- Exe() class.
- """)
- traceback.print_stack()
- return _orig_subprocess(*a, **ka)
-
-if subprocess.Popen is not subprocess_warning:
- _orig_subprocess = subprocess.Popen
- subprocess.Popen = subprocess_warning
+# import subprocess
+#
+# _orig_subprocess = None
+#
+# def subprocess_warning(*a, **ka):
+# print(""" DEVELOPER WARNING:
+# Using subprocess (Popen and derivatives) with Ecore is a bad idea.
+#
+# Ecore will set some signal handlers subprocess module depends and this
+# may cause this module to operate unexpectedly.
+#
+# Instead of using subprocess.Popen(), please consider using Ecore's
+# Exe() class.
+# """)
+# traceback.print_stack()
+# return _orig_subprocess(*a, **ka)
+#
+# if subprocess.Popen is not subprocess_warning:
+# _orig_subprocess = subprocess.Popen
+# subprocess.Popen = subprocess_warning
#---------------------------------------------------------------------------
diff --git a/tests/ecore/exe_helper.sh b/tests/ecore/exe_helper.sh
new file mode 100755
index 0000000..824586e
--- /dev/null
+++ b/tests/ecore/exe_helper.sh
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+import time
+import sys
+
+delay = float(sys.argv[1])
+
+for i in range(1000):
+ print(i)
+ sys.stdout.flush()
+ time.sleep(delay)
+
+exit(0)
+
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 @@
import os
import unittest
import logging
+import subprocess
from efl import ecore
script_path = os.path.dirname(os.path.realpath(__file__))
+helper = os.path.join(script_path, "exe_helper.sh")
+
+
+# basic read flags with line support
+flags = ecore.ECORE_EXE_PIPE_READ | \
+ ecore.ECORE_EXE_PIPE_READ_LINE_BUFFERED | \
+ ecore.ECORE_EXE_TERM_WITH_PARENT
+
+
+class TestExeSubprocess(unittest.TestCase):
+ def testInit(self):
+ self.exe_terminated = False
+ self.num_lines_from_exe = 0
+ self.num_lines_from_popen = 0
+ self.check_output_tested = False
+ self.call_tested = False
+
+ # spawn a "slow" ecore.Exe child (will start on ml begin)
+ exe = ecore.Exe("%s 0.001" % helper, flags)
+ exe.on_add_event_add(self.on_exe_add)
+ exe.on_data_event_add(self.on_exe_data)
+ exe.on_del_event_add(self.on_exe_del)
+
+ # start ml with a 5 secs timeout
+ t = ecore.timer_add(5, ecore.main_loop_quit)
+ ecore.main_loop_begin()
+ t.delete()
+
+ # do the ecore exe terminate? (timeout not expired)
+ self.assertEqual(self.exe_terminated, True)
+
+ # do ecore exe received all the expected lines?
+ self.assertEqual(self.num_lines_from_exe, 1000)
+
+ # do the subprocess.call() test runs?
+ self.assertEqual(self.call_tested, True)
+
+ # do the subprocess.check_output() test runs?
+ self.assertEqual(self.check_output_tested, True)
+
+ # wait for the popen process to succesfully terminate
+ out, err = self.proc.communicate()
+ self.assertEqual(err, None)
+
+ # do we received all the expected lines from popen?
+ self.num_lines_from_popen += len(out.split())
+ self.assertEqual(self.num_lines_from_popen, 1000)
+
+ def on_exe_add(self, exe, event):
+ self.assertIsInstance(event, ecore.EventExeAdd)
+
+ # subprocess.call() in the middle of ecore.Exe (sync)
+ ret = subprocess.call("%s 0.0 >/dev/null" % helper, shell=True)
+ self.assertEqual(ret, 0)
+ self.call_tested = True
+
+ # subprocess.check_output() in the middle of ecore.Exe (sync)
+ out = subprocess.check_output([helper, "0.0"])
+ self.assertEqual(len(out.split()), 1000)
+ self.check_output_tested = True
+
+ # spawn a Popen child, will read it's output later (async)
+ self.proc = subprocess.Popen([helper, "0.0"], stdout=subprocess.PIPE)
+
+ def on_exe_data(self, exe, event):
+ self.assertIsInstance(event, ecore.EventExeData)
+ self.num_lines_from_exe += len(event.lines)
+
+ # read a single line from the Popen process stdout
+ self.proc.stdout.readline() # WARNING: this one is blocking
+ self.num_lines_from_popen += 1
+
+ def on_exe_del(self, exe, event):
+ self.assertIsInstance(event, ecore.EventExeDel)
+ self.exe_terminated = True
+ ecore.main_loop_quit()
class TestExe(unittest.TestCase):
@@ -17,11 +94,6 @@ class TestExe(unittest.TestCase):
self.num_del = 0
self.num_data = 0
- # basic read flags with line support
- flags = ecore.ECORE_EXE_PIPE_READ | \
- ecore.ECORE_EXE_PIPE_READ_LINE_BUFFERED | \
- ecore.ECORE_EXE_TERM_WITH_PARENT
-
# EXE 1: simple ls -la output, monitor for add, del and data (stdout)
def on_add(x, event, a, b, c):
self.assertEqual(x, exe1)
@@ -30,20 +102,17 @@ class TestExe(unittest.TestCase):
self.assertEqual(b, 2)
self.assertEqual(c, 3)
self.num_add += 1
- return ecore.ECORE_CALLBACK_RENEW
def on_del(x, event):
self.assertEqual(x, exe1)
self.assertIsInstance(event, ecore.EventExeDel)
self.num_del += 1
- return ecore.ECORE_CALLBACK_RENEW
def on_data(x, event):
self.assertEqual(x, exe1)
self.assertIsInstance(event, ecore.EventExeData)
self.assertTrue(len(event.lines) >= 13) #we have at least 13 files here
self.num_data += 1
- return ecore.ECORE_CALLBACK_RENEW
exe1 = ecore.Exe('ls -l "%s"' % script_path, flags)
exe1.on_add_event_add(on_add, 1, c=3, b=2)
@@ -81,14 +150,12 @@ class TestExe(unittest.TestCase):
self.assertIsInstance(event, ecore.EventExeAdd)
x.send(b"123\nabc\nxyz\n")
self.num_add += 1
- return ecore.ECORE_CALLBACK_RENEW
def on_cat_pipe_del(x, event):
self.assertEqual(x, exe3)
self.assertIsInstance(event, ecore.EventExeDel)
self.num_del += 1
- return ecore.ECORE_CALLBACK_RENEW
def on_cat_pipe_data(x, event):
self.assertEqual(x, exe3)
@@ -96,7 +163,6 @@ class TestExe(unittest.TestCase):
self.assertEqual(event.lines, ["123", "abc", "xyz"])
x.on_data_event_del(on_cat_pipe_data)
self.num_data += 1
- return ecore.ECORE_CALLBACK_CANCEL
def on_cat_pipe_data2(x, event):
self.assertEqual(x, exe3)
@@ -106,7 +172,6 @@ class TestExe(unittest.TestCase):
x.on_data_event_del(on_cat_pipe_data2)
x.kill()
self.num_data += 1
- return ecore.ECORE_CALLBACK_RENEW
exe3 = ecore.Exe("cat", flags | ecore.ECORE_EXE_PIPE_WRITE)
exe3.on_add_event_add(on_cat_pipe_add)