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