##// END OF EJS Templates
Merge pull request #5396 from ivanov/fix-5363...
Merge pull request #5396 from ivanov/fix-5363 prevent saving of partially loaded notebooks

File last commit:

r11826:182f1027
r15995:41452895 merge
Show More
test_process.py
146 lines | 5.0 KiB | text/x-python | PythonLexer
Brian Granger
Adding test_platutils.py.
r1976 # encoding: utf-8
"""
Tests for platutils.py
"""
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2008-2011 The IPython Development Team
Brian Granger
Adding test_platutils.py.
r1976 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import sys
Julian Taylor
allow test_process to succeed without python installed
r10607 import os
Fernando Perez
Fully refactored subprocess handling on all platforms....
r2908 from unittest import TestCase
Brian Granger
Adding test_platutils.py.
r1976
import nose.tools as nt
Fernando Perez
Fully refactored subprocess handling on all platforms....
r2908 from IPython.utils.process import (find_cmd, FindCmdError, arg_split,
Paul Ivanov
test for get_output_error_code
r11826 system, getoutput, getoutputerror,
get_output_error_code)
Brian Granger
Adding test_platutils.py.
r1976 from IPython.testing import decorators as dec
Fernando Perez
Fully refactored subprocess handling on all platforms....
r2908 from IPython.testing import tools as tt
Brian Granger
Adding test_platutils.py.
r1976
Julian Taylor
allow test_process to succeed without python installed
r10607 python = os.path.basename(sys.executable)
Brian Granger
Adding test_platutils.py.
r1976 #-----------------------------------------------------------------------------
# Tests
#-----------------------------------------------------------------------------
@dec.skip_win32
Fernando Perez
More win32 fixes and refinements to test suite.
r2453 def test_find_cmd_ls():
Brian Granger
Adding test_platutils.py.
r1976 """Make sure we can find the full path to ls."""
path = find_cmd('ls')
Thomas Kluyver
Fix some more tests for Python 3.
r4898 nt.assert_true(path.endswith('ls'))
Brian Granger
Adding test_platutils.py.
r1976
Fernando Perez
More win32 fixes and refinements to test suite.
r2453
def has_pywin32():
try:
import win32api
except ImportError:
return False
return True
@dec.onlyif(has_pywin32, "This test requires win32api to run")
def test_find_cmd_pythonw():
Brian Granger
Adding test_platutils.py.
r1976 """Try to find pythonw on Windows."""
path = find_cmd('pythonw')
nt.assert_true(path.endswith('pythonw.exe'))
Fernando Perez
More win32 fixes and refinements to test suite.
r2453
@dec.onlyif(lambda : sys.platform != 'win32' or has_pywin32(),
"This test runs on posix or in win32 with win32api installed")
Brian Granger
Adding test_platutils.py.
r1976 def test_find_cmd_fail():
"""Make sure that FindCmdError is raised if we can't find the cmd."""
nt.assert_raises(FindCmdError,find_cmd,'asdfasdf')
Administrator
Added platutils.get_long_path_name to expand paths with "~" on win32....
r1986
Fernando Perez
More win32 fixes and refinements to test suite.
r2453
Jörgen Stenarson
Special version of arg_split for win32
r5512 @dec.skip_win32
Fernando Perez
Work around a bug in Python's shlex module with unicode input....
r2650 def test_arg_split():
"""Ensure that argument lines are correctly split like in a shell."""
tests = [['hi', ['hi']],
[u'hi', [u'hi']],
Robert Kern
BUG: when given unicode inputs, arg_split should return unicode outputs. Always use utf-8 to encode the string instead of relying on sys.stdin.encoding, which may not be able to accept the full range of Unicode characters. When given unicode strings, arg_split is probably not receiving input from a terminal.
r3291 ['hello there', ['hello', 'there']],
Jörgen Stenarson
Moved arg_split to _process_win32.py and _process_posix.py.
r5517 # \u01ce == \N{LATIN SMALL LETTER A WITH CARON}
# Do not use \N because the tests crash with syntax error in
# some cases, for example windows python2.6.
[u'h\u01cello', [u'h\u01cello']],
Jörgen Stenarson
Special version of arg_split for win32
r5512 ['something "with quotes"', ['something', '"with quotes"']],
]
for argstr, argv in tests:
nt.assert_equal(arg_split(argstr), argv)
Jörgen Stenarson
Fixing some errors in the tests
r5513 @dec.skip_if_not_win32
Jörgen Stenarson
Special version of arg_split for win32
r5512 def test_arg_split_win32():
"""Ensure that argument lines are correctly split like in a shell."""
tests = [['hi', ['hi']],
[u'hi', [u'hi']],
['hello there', ['hello', 'there']],
Jörgen Stenarson
Moved arg_split to _process_win32.py and _process_posix.py.
r5517 [u'h\u01cello', [u'h\u01cello']],
Jörgen Stenarson
Fixing some errors in the tests
r5513 ['something "with quotes"', ['something', 'with quotes']],
Fernando Perez
Work around a bug in Python's shlex module with unicode input....
r2650 ]
for argstr, argv in tests:
nt.assert_equal(arg_split(argstr), argv)
Fernando Perez
Fully refactored subprocess handling on all platforms....
r2908
class SubProcessTestCase(TestCase, tt.TempFileMixin):
def setUp(self):
"""Make a valid python temp file."""
lines = ["from __future__ import print_function",
"import sys",
"print('on stdout', end='', file=sys.stdout)",
"print('on stderr', end='', file=sys.stderr)",
"sys.stdout.flush()",
"sys.stderr.flush()"]
self.mktmp('\n'.join(lines))
def test_system(self):
Julian Taylor
allow test_process to succeed without python installed
r10607 status = system('%s "%s"' % (python, self.fname))
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(status, 0)
MinRK
fix arguments for commands in _process_posix...
r5296
def test_system_quotes(self):
Julian Taylor
allow test_process to succeed without python installed
r10607 status = system('%s -c "import sys"' % python)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(status, 0)
Fernando Perez
Fully refactored subprocess handling on all platforms....
r2908
def test_getoutput(self):
Julian Taylor
allow test_process to succeed without python installed
r10607 out = getoutput('%s "%s"' % (python, self.fname))
Julian Taylor
fix documentation and test of getoutput...
r10606 # we can't rely on the order the line buffered streams are flushed
try:
self.assertEqual(out, 'on stderron stdout')
except AssertionError:
self.assertEqual(out, 'on stdouton stderr')
Fernando Perez
Fully refactored subprocess handling on all platforms....
r2908
MinRK
fix arguments for commands in _process_posix...
r5296 def test_getoutput_quoted(self):
Julian Taylor
allow test_process to succeed without python installed
r10607 out = getoutput('%s -c "print (1)"' % python)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(out.strip(), '1')
Jörgen Stenarson
Splitting tests for getoutput_quoted into all and non-win32
r5514
#Invalid quoting on windows
@dec.skip_win32
def test_getoutput_quoted2(self):
Julian Taylor
allow test_process to succeed without python installed
r10607 out = getoutput("%s -c 'print (1)'" % python)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(out.strip(), '1')
Julian Taylor
allow test_process to succeed without python installed
r10607 out = getoutput("%s -c 'print (\"1\")'" % python)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(out.strip(), '1')
MinRK
fix arguments for commands in _process_posix...
r5296
Julian Taylor
fix documentation and test of getoutput...
r10606 def test_getoutput_error(self):
Julian Taylor
allow test_process to succeed without python installed
r10607 out, err = getoutputerror('%s "%s"' % (python, self.fname))
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(out, 'on stdout')
self.assertEqual(err, 'on stderr')
Paul Ivanov
test for get_output_error_code
r11826
def test_get_output_error_code(self):
quiet_exit = '%s -c "import sys; sys.exit(1)"' % python
out, err, code = get_output_error_code(quiet_exit)
self.assertEqual(out, '')
self.assertEqual(err, '')
self.assertEqual(code, 1)
out, err, code = get_output_error_code('%s "%s"' % (python, self.fname))
self.assertEqual(out, 'on stdout')
self.assertEqual(err, 'on stderr')
self.assertEqual(code, 0)