|
14 | 14 | from io import StringIO |
15 | 15 |
|
16 | 16 | from test import support |
| 17 | +from unittest import mock |
17 | 18 | class StdIOBuffer(StringIO): |
18 | 19 | pass |
19 | 20 |
|
@@ -1421,6 +1422,19 @@ def test_wb_1(self): |
1421 | 1422 | type = argparse.FileType('wb', 1) |
1422 | 1423 | self.assertEqual("FileType('wb', 1)", repr(type)) |
1423 | 1424 |
|
| 1425 | + def test_r_latin(self): |
| 1426 | + type = argparse.FileType('r', encoding='latin_1') |
| 1427 | + self.assertEqual("FileType('r', encoding='latin_1')", repr(type)) |
| 1428 | + |
| 1429 | + def test_w_big5_ignore(self): |
| 1430 | + type = argparse.FileType('w', encoding='big5', errors='ignore') |
| 1431 | + self.assertEqual("FileType('w', encoding='big5', errors='ignore')", |
| 1432 | + repr(type)) |
| 1433 | + |
| 1434 | + def test_r_1_replace(self): |
| 1435 | + type = argparse.FileType('r', 1, errors='replace') |
| 1436 | + self.assertEqual("FileType('r', 1, errors='replace')", repr(type)) |
| 1437 | + |
1424 | 1438 |
|
1425 | 1439 | class RFile(object): |
1426 | 1440 | seen = {} |
@@ -1557,6 +1571,24 @@ class TestFileTypeWB(TempDirMixin, ParserTestCase): |
1557 | 1571 | ] |
1558 | 1572 |
|
1559 | 1573 |
|
| 1574 | +class TestFileTypeOpenArgs(TestCase): |
| 1575 | + """Test that open (the builtin) is correctly called""" |
| 1576 | + |
| 1577 | + def test_open_args(self): |
| 1578 | + FT = argparse.FileType |
| 1579 | + cases = [ |
| 1580 | + (FT('rb'), ('rb', -1, None, None)), |
| 1581 | + (FT('w', 1), ('w', 1, None, None)), |
| 1582 | + (FT('w', errors='replace'), ('w', -1, None, 'replace')), |
| 1583 | + (FT('wb', encoding='big5'), ('wb', -1, 'big5', None)), |
| 1584 | + (FT('w', 0, 'l1', 'strict'), ('w', 0, 'l1', 'strict')), |
| 1585 | + ] |
| 1586 | + with mock.patch('builtins.open') as m: |
| 1587 | + for type, args in cases: |
| 1588 | + type('foo') |
| 1589 | + m.assert_called_with('foo', *args) |
| 1590 | + |
| 1591 | + |
1560 | 1592 | class TestTypeCallable(ParserTestCase): |
1561 | 1593 | """Test some callables as option/argument types""" |
1562 | 1594 |
|
|
0 commit comments