Show More
@@ -37,7 +37,12 b' class IOStream:' | |||
|
37 | 37 | def clone(meth): |
|
38 | 38 | return not hasattr(self, meth) and not meth.startswith('_') |
|
39 | 39 | for meth in filter(clone, dir(stream)): |
|
40 | setattr(self, meth, getattr(stream, meth)) | |
|
40 | try: | |
|
41 | val = getattr(stream, meth) | |
|
42 | except AttributeError: | |
|
43 | pass | |
|
44 | else: | |
|
45 | setattr(self, meth, val) | |
|
41 | 46 | |
|
42 | 47 | def __repr__(self): |
|
43 | 48 | cls = self.__class__ |
@@ -17,7 +17,7 b' import unittest' | |||
|
17 | 17 | import nose.tools as nt |
|
18 | 18 | |
|
19 | 19 | from IPython.testing.decorators import skipif, skip_win32 |
|
20 | from IPython.utils.io import Tee, capture_output | |
|
20 | from IPython.utils.io import IOStream, Tee, capture_output | |
|
21 | 21 | from IPython.utils.py3compat import doctest_refactor_print |
|
22 | 22 | from IPython.utils.tempdir import TemporaryDirectory |
|
23 | 23 | |
@@ -68,6 +68,19 b' def test_io_init():' | |||
|
68 | 68 | # just test for string equality. |
|
69 | 69 | assert 'IPython.utils.io.IOStream' in classname, classname |
|
70 | 70 | |
|
71 | def test_IOStream_init(): | |
|
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(StringIO, self).__dir__() | |
|
77 | attrs.append('name') | |
|
78 | return attrs | |
|
79 | ||
|
80 | iostream = IOStream(BadStringIO()) | |
|
81 | iostream.write('hi, bad iostream\n') | |
|
82 | assert not hasattr(iostream, 'name') | |
|
83 | ||
|
71 | 84 | def test_capture_output(): |
|
72 | 85 | """capture_output() context works""" |
|
73 | 86 |
General Comments 0
You need to be logged in to leave comments.
Login now