Skip to content

Commit 58cf70c

Browse files
emmatypingRogdham
andcommitted
Add test_name from upstream
Co-authored-by: Rogdham <[email protected]>
1 parent 19d6292 commit 58cf70c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Lib/test/test_zstd/test_core.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,40 @@ def read(self, size=-1):
15421542
with self.assertRaisesRegex(AttributeError, r'fileno'):
15431543
f.fileno()
15441544

1545+
def test_name(self):
1546+
# 1
1547+
f = ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB))
1548+
try:
1549+
with self.assertRaises(AttributeError):
1550+
f.name
1551+
finally:
1552+
f.close()
1553+
with self.assertRaises(ValueError):
1554+
f.name
1555+
1556+
# 2
1557+
with tempfile.NamedTemporaryFile(delete=False) as tmp_f:
1558+
filename = pathlib.Path(tmp_f.name)
1559+
1560+
f = ZstdFile(filename)
1561+
try:
1562+
self.assertEqual(f.name, f._fp.name)
1563+
self.assertIsInstance(f.name, str)
1564+
finally:
1565+
f.close()
1566+
with self.assertRaises(ValueError):
1567+
f.name
1568+
1569+
os.remove(filename)
1570+
1571+
# 3, no .filename property
1572+
class C:
1573+
def read(self, size=-1):
1574+
return b'123'
1575+
with ZstdFile(C(), 'rb') as f:
1576+
with self.assertRaisesRegex(AttributeError, r'name'):
1577+
f.name
1578+
15451579
def test_seekable(self):
15461580
f = ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB))
15471581
try:

0 commit comments

Comments
 (0)