예제 #1
0
def test_IOStream_init():
    """IOStream initializes from a file-like object missing attributes. """
    # Cause a failure from getattr and dir(). (Issue #6386)
    class BadStringIO(StringIO):
        def __dir__(self):
            attrs = super(StringIO, self).__dir__()
            attrs.append('name')
            return attrs

    iostream = IOStream(BadStringIO())
    iostream.write('hi, bad iostream\n')
    assert not hasattr(iostream, 'name')
예제 #2
0
    def test_IOStream_init(self):
        """IOStream initializes from a file-like object missing attributes. """

        # Cause a failure from getattr and dir(). (Issue #6386)
        class BadStringIO(StringIO):
            def __dir__(self):
                attrs = super().__dir__()
                attrs.append("name")
                return attrs

        with self.assertWarns(DeprecationWarning):
            iostream = IOStream(BadStringIO())
            iostream.write("hi, bad iostream\n")

        assert not hasattr(iostream, "name")
        iostream.close()