summaryrefslogtreecommitdiff
path: root/functional_tests
diff options
context:
space:
mode:
authorHeng Liu <liucougar@gmail.com>2011-11-04 10:02:38 -0700
committerHeng Liu <liucougar@gmail.com>2011-11-04 10:02:38 -0700
commitee86f762d68d59b0e846fddd0a783a90843415f6 (patch)
tree21f3541fa2baded1d3c3ec895e08b2a04a32d3df /functional_tests
parent047aaa3ac7b05f12c4c6b81dbab153a6cfbc918f (diff)
downloadnose-ee86f762d68d59b0e846fddd0a783a90843415f6.tar.gz
rearrange keyboard interrupt tests
Diffstat (limited to 'functional_tests')
-rw-r--r--functional_tests/test_multiprocessing/support/fake_nosetest.py7
-rw-r--r--functional_tests/test_multiprocessing/support/keyboardinterrupt.py8
-rw-r--r--functional_tests/test_multiprocessing/support/keyboardinterrupt_twice.py11
-rw-r--r--functional_tests/test_multiprocessing/test_keyboardinterrupt.py22
4 files changed, 32 insertions, 16 deletions
diff --git a/functional_tests/test_multiprocessing/support/fake_nosetest.py b/functional_tests/test_multiprocessing/support/fake_nosetest.py
index 886c569..f5a6289 100644
--- a/functional_tests/test_multiprocessing/support/fake_nosetest.py
+++ b/functional_tests/test_multiprocessing/support/fake_nosetest.py
@@ -1,13 +1,14 @@
+import os
import sys
import nose
-
from nose.plugins.multiprocess import MultiProcess
from nose.config import Config
from nose.plugins.manager import PluginManager
if __name__ == '__main__':
- if len(sys.argv) < 2:
- print "USAGE: %s TEST_FILE" % sys.argv[0]
+ if len(sys.argv) < 3:
+ print "USAGE: %s TEST_FILE LOG_FILE" % sys.argv[0]
sys.exit(1)
+ os.environ['NOSE_MP_LOG']=sys.argv[2]
nose.main(defaultTest=sys.argv[1], argv=[sys.argv[0],'--processes=1','-v'], config=Config(plugins=PluginManager(plugins=[MultiProcess()])))
diff --git a/functional_tests/test_multiprocessing/support/keyboardinterrupt.py b/functional_tests/test_multiprocessing/support/keyboardinterrupt.py
index 988d1eb..2c36d95 100644
--- a/functional_tests/test_multiprocessing/support/keyboardinterrupt.py
+++ b/functional_tests/test_multiprocessing/support/keyboardinterrupt.py
@@ -1,8 +1,12 @@
+import os
+
from tempfile import mktemp
from time import sleep
-logfile = mktemp()
-print "tempfile is:",logfile
+if 'NOSE_MP_LOG' not in os.environ:
+ raise Exception('Environment variable NOSE_MP_LOG is not set')
+
+logfile = os.environ['NOSE_MP_LOG']
def log(w):
f = open(logfile, 'a')
diff --git a/functional_tests/test_multiprocessing/support/keyboardinterrupt_twice.py b/functional_tests/test_multiprocessing/support/keyboardinterrupt_twice.py
index b7d845a..3932bbd 100644
--- a/functional_tests/test_multiprocessing/support/keyboardinterrupt_twice.py
+++ b/functional_tests/test_multiprocessing/support/keyboardinterrupt_twice.py
@@ -1,8 +1,12 @@
+import os
+
from tempfile import mktemp
from time import sleep
-logfile = mktemp()
-print "tempfile is:",logfile
+if 'NOSE_MP_LOG' not in os.environ:
+ raise Exception('Environment variable NOSE_MP_LOG is not set')
+
+logfile = os.environ['NOSE_MP_LOG']
def log(w):
f = open(logfile, 'a')
@@ -10,6 +14,9 @@ def log(w):
f.close()
#make sure all tests in this file are dispatched to the same subprocess
def setup():
+ '''global logfile
+ logfile = mktemp()
+ print "tempfile is:",logfile'''
log('setup')
def test_timeout():
diff --git a/functional_tests/test_multiprocessing/test_keyboardinterrupt.py b/functional_tests/test_multiprocessing/test_keyboardinterrupt.py
index 7d26d10..03c0890 100644
--- a/functional_tests/test_multiprocessing/test_keyboardinterrupt.py
+++ b/functional_tests/test_multiprocessing/test_keyboardinterrupt.py
@@ -25,27 +25,31 @@ runner = os.path.join(support, 'fake_nosetest.py')
def keyboardinterrupt(case):
#os.setsid would create a process group so signals sent to the
#parent process will propogates to all children processes
- process = Popen([sys.executable,runner,os.path.join(support,case)], preexec_fn=os.setsid, stdout=PIPE, stderr=PIPE, bufsize=-1)
+ from tempfile import mktemp
+ logfile = mktemp()
+ process = Popen([sys.executable,runner,os.path.join(support,case),logfile], preexec_fn=os.setsid, stdout=PIPE, stderr=PIPE, bufsize=-1)
sleep(0.5)
os.killpg(process.pid, signal.SIGINT)
- return process
+ return process, logfile
-def get_log_content(stdout):
- prefix = 'tempfile is: '
+def get_log_content(logfile):
+ '''prefix = 'tempfile is: '
if not stdout.startswith(prefix):
raise Exception('stdout does not contain tmp file name: '+stdout)
- logfile = stdout[len(prefix):].strip() #remove trailing new line char
+ logfile = stdout[len(prefix):].strip() #remove trailing new line char'''
f = open(logfile)
content = f.read()
f.close()
+ os.remove(logfile)
return content
def test_keyboardinterrupt():
- process = keyboardinterrupt('keyboardinterrupt.py')
+ process, logfile = keyboardinterrupt('keyboardinterrupt.py')
stdout, stderr = [s.decode('utf-8') for s in process.communicate(None)]
- log = get_log_content(stdout)
+ print stderr
+ log = get_log_content(logfile)
assert 'setup' in log
assert 'test_timeout' in log
assert 'test_timeout_finished' not in log
@@ -58,11 +62,11 @@ def test_keyboardinterrupt():
def test_keyboardinterrupt_twice():
- process = keyboardinterrupt('keyboardinterrupt_twice.py')
+ process, logfile = keyboardinterrupt('keyboardinterrupt_twice.py')
sleep(0.5)
os.killpg(process.pid, signal.SIGINT)
stdout, stderr = [s.decode('utf-8') for s in process.communicate(None)]
- log = get_log_content(stdout)
+ log = get_log_content(logfile)
assert 'setup' in log
assert 'test_timeout' in log
assert 'test_timeout_finished' not in log