fixed an incorrect assumption about instance of IO. + workaround for tests with StringIO as a stream