##// END OF EJS Templates
Merge pull request #11794 from Carreau/proper-unittests...
Matthias Bussonnier -
r25112:2a721e92 merge
parent child Browse files
Show More
@@ -66,28 +66,29 b' def test_io_init():'
66 # just test for string equality.
66 # just test for string equality.
67 assert 'IPython.utils.io.IOStream' in classname, classname
67 assert 'IPython.utils.io.IOStream' in classname, classname
68
68
69 def test_IOStream_init():
69 class TestIOStream(unittest.TestCase):
70 """IOStream initializes from a file-like object missing attributes. """
70
71 # Cause a failure from getattr and dir(). (Issue #6386)
71 def test_IOStream_init(self):
72 class BadStringIO(StringIO):
72 """IOStream initializes from a file-like object missing attributes. """
73 def __dir__(self):
73 # Cause a failure from getattr and dir(). (Issue #6386)
74 attrs = super(StringIO, self).__dir__()
74 class BadStringIO(StringIO):
75 attrs.append('name')
75 def __dir__(self):
76 return attrs
76 attrs = super().__dir__()
77
77 attrs.append('name')
78 iostream = IOStream(BadStringIO())
78 return attrs
79 iostream.write('hi, bad iostream\n')
79 with self.assertWarns(DeprecationWarning):
80 assert not hasattr(iostream, 'name')
80 iostream = IOStream(BadStringIO())
81 iostream.close()
81 iostream.write('hi, bad iostream\n')
82
82
83 def test_capture_output():
83 assert not hasattr(iostream, 'name')
84 """capture_output() context works"""
84 iostream.close()
85
85
86 with capture_output() as io:
86 def test_capture_output(self):
87 print('hi, stdout')
87 """capture_output() context works"""
88 print('hi, stderr', file=sys.stderr)
88
89
89 with capture_output() as io:
90 nt.assert_equal(io.stdout, 'hi, stdout\n')
90 print('hi, stdout')
91 nt.assert_equal(io.stderr, 'hi, stderr\n')
91 print('hi, stderr', file=sys.stderr)
92
92
93
93 nt.assert_equal(io.stdout, 'hi, stdout\n')
94 nt.assert_equal(io.stderr, 'hi, stderr\n')
@@ -263,28 +263,31 b' def test_get_long_path_name():'
263 p = path.get_long_path_name('/usr/local')
263 p = path.get_long_path_name('/usr/local')
264 nt.assert_equal(p,'/usr/local')
264 nt.assert_equal(p,'/usr/local')
265
265
266 @dec.skip_win32 # can't create not-user-writable dir on win
266
267 @with_environment
267 class TestRaiseDeprecation(unittest.TestCase):
268 def test_not_writable_ipdir():
268
269 tmpdir = tempfile.mkdtemp()
269 @dec.skip_win32 # can't create not-user-writable dir on win
270 os.name = "posix"
270 @with_environment
271 env.pop('IPYTHON_DIR', None)
271 def test_not_writable_ipdir(self):
272 env.pop('IPYTHONDIR', None)
272 tmpdir = tempfile.mkdtemp()
273 env.pop('XDG_CONFIG_HOME', None)
273 os.name = "posix"
274 env['HOME'] = tmpdir
274 env.pop('IPYTHON_DIR', None)
275 ipdir = os.path.join(tmpdir, '.ipython')
275 env.pop('IPYTHONDIR', None)
276 os.mkdir(ipdir, 0o555)
276 env.pop('XDG_CONFIG_HOME', None)
277 try:
277 env['HOME'] = tmpdir
278 open(os.path.join(ipdir, "_foo_"), 'w').close()
278 ipdir = os.path.join(tmpdir, '.ipython')
279 except IOError:
279 os.mkdir(ipdir, 0o555)
280 pass
280 try:
281 else:
281 open(os.path.join(ipdir, "_foo_"), 'w').close()
282 # I can still write to an unwritable dir,
282 except IOError:
283 # assume I'm root and skip the test
283 pass
284 raise SkipTest("I can't create directories that I can't write to")
284 else:
285 with AssertPrints('is not a writable location', channel='stderr'):
285 # I can still write to an unwritable dir,
286 ipdir = paths.get_ipython_dir()
286 # assume I'm root and skip the test
287 env.pop('IPYTHON_DIR', None)
287 raise SkipTest("I can't create directories that I can't write to")
288 with self.assertWarnsRegex(UserWarning, 'is not a writable location'):
289 ipdir = paths.get_ipython_dir()
290 env.pop('IPYTHON_DIR', None)
288
291
289 @with_environment
292 @with_environment
290 def test_get_py_filename():
293 def test_get_py_filename():
@@ -313,7 +316,7 b' def test_unicode_in_filename():'
313 """
316 """
314 try:
317 try:
315 # these calls should not throw unicode encode exceptions
318 # these calls should not throw unicode encode exceptions
316 path.get_py_filename('fooéè.py', force_win32=False)
319 path.get_py_filename('fooéè.py')
317 except IOError as ex:
320 except IOError as ex:
318 str(ex)
321 str(ex)
319
322
@@ -406,7 +409,7 b' def test_ensure_dir_exists():'
406 with nt.assert_raises(IOError):
409 with nt.assert_raises(IOError):
407 path.ensure_dir_exists(f)
410 path.ensure_dir_exists(f)
408
411
409 class TestLinkOrCopy(object):
412 class TestLinkOrCopy(unittest.TestCase):
410 def setUp(self):
413 def setUp(self):
411 self.tempdir = TemporaryDirectory()
414 self.tempdir = TemporaryDirectory()
412 self.src = self.dst("src")
415 self.src = self.dst("src")
General Comments 0
You need to be logged in to leave comments. Login now