Issue #17401: Output the closefd attribute as boolean.
This commit is contained in:
parent
b16edc8087
commit
4954f9fcab
|
@ -113,15 +113,25 @@ class AutoFileTests(unittest.TestCase):
|
|||
|
||||
def testRepr(self):
|
||||
self.assertEqual(
|
||||
repr(self.f), "<_io.FileIO name=%r mode=%r closefd='%d'>"
|
||||
% (self.f.name, self.f.mode, self.f.closefd))
|
||||
repr(self.f), "<_io.FileIO name=%r mode=%r closefd=True>"
|
||||
% (self.f.name, self.f.mode))
|
||||
del self.f.name
|
||||
self.assertEqual(
|
||||
repr(self.f), "<_io.FileIO fd=%r mode=%r closefd='%d'>"
|
||||
% (self.f.fileno(), self.f.mode, self.f.closefd))
|
||||
repr(self.f), "<_io.FileIO fd=%r mode=%r closefd=True>"
|
||||
% (self.f.fileno(), self.f.mode))
|
||||
self.f.close()
|
||||
self.assertEqual(repr(self.f), "<_io.FileIO [closed]>")
|
||||
|
||||
def testReprNoCloseFD(self):
|
||||
fd = os.open(TESTFN, os.O_RDONLY)
|
||||
try:
|
||||
with _FileIO(fd, 'r', closefd=False) as f:
|
||||
self.assertEqual(repr(f),
|
||||
"<_io.FileIO name=%r mode=%r closefd=False>"
|
||||
% (f.name, f.mode))
|
||||
finally:
|
||||
os.close(fd)
|
||||
|
||||
def testErrors(self):
|
||||
f = self.f
|
||||
self.assertTrue(not f.isatty())
|
||||
|
|
|
@ -1055,13 +1055,13 @@ fileio_repr(fileio *self)
|
|||
else
|
||||
return NULL;
|
||||
res = PyUnicode_FromFormat(
|
||||
"<_io.FileIO fd=%d mode='%s' closefd='%d'>",
|
||||
self->fd, mode_string(self), self->closefd);
|
||||
"<_io.FileIO fd=%d mode='%s' closefd=%s>",
|
||||
self->fd, mode_string(self), self->closefd ? "True" : "False");
|
||||
}
|
||||
else {
|
||||
res = PyUnicode_FromFormat(
|
||||
"<_io.FileIO name=%R mode='%s' closefd='%d'>",
|
||||
nameobj, mode_string(self), self->closefd);
|
||||
"<_io.FileIO name=%R mode='%s' closefd=%s>",
|
||||
nameobj, mode_string(self), self->closefd ? "True" : "False");
|
||||
Py_DECREF(nameobj);
|
||||
}
|
||||
return res;
|
||||
|
|
Loading…
Reference in New Issue