summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2012-12-15 20:39:32 (GMT)
committerPetri Lehtinen <petri@digip.org>2012-12-15 20:42:47 (GMT)
commit74d6c250e1ce0e5efc03575eaaa1b8cab66241eb (patch)
tree172bc4bd59fe0d52a877d1811a7bcc3c9d50b624 /Lib/test
parent09bb89b8cf24431ef78bbaa227d2832fb852bb18 (diff)
downloadcpython-74d6c250e1ce0e5efc03575eaaa1b8cab66241eb.zip
cpython-74d6c250e1ce0e5efc03575eaaa1b8cab66241eb.tar.gz
cpython-74d6c250e1ce0e5efc03575eaaa1b8cab66241eb.tar.bz2
#11175: argparse.FileType now accepts encoding and errors arguments.
Patch by Lucas Maystre.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_argparse.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index c06c940..00cde2e 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -14,6 +14,7 @@ import argparse
from io import StringIO
from test import support
+from unittest import mock
class StdIOBuffer(StringIO):
pass
@@ -1421,6 +1422,19 @@ class TestFileTypeRepr(TestCase):
type = argparse.FileType('wb', 1)
self.assertEqual("FileType('wb', 1)", repr(type))
+ def test_r_latin(self):
+ type = argparse.FileType('r', encoding='latin_1')
+ self.assertEqual("FileType('r', encoding='latin_1')", repr(type))
+
+ def test_w_big5_ignore(self):
+ type = argparse.FileType('w', encoding='big5', errors='ignore')
+ self.assertEqual("FileType('w', encoding='big5', errors='ignore')",
+ repr(type))
+
+ def test_r_1_replace(self):
+ type = argparse.FileType('r', 1, errors='replace')
+ self.assertEqual("FileType('r', 1, errors='replace')", repr(type))
+
class RFile(object):
seen = {}
@@ -1557,6 +1571,24 @@ class TestFileTypeWB(TempDirMixin, ParserTestCase):
]
+class TestFileTypeOpenArgs(TestCase):
+ """Test that open (the builtin) is correctly called"""
+
+ def test_open_args(self):
+ FT = argparse.FileType
+ cases = [
+ (FT('rb'), ('rb', -1, None, None)),
+ (FT('w', 1), ('w', 1, None, None)),
+ (FT('w', errors='replace'), ('w', -1, None, 'replace')),
+ (FT('wb', encoding='big5'), ('wb', -1, 'big5', None)),
+ (FT('w', 0, 'l1', 'strict'), ('w', 0, 'l1', 'strict')),
+ ]
+ with mock.patch('builtins.open') as m:
+ for type, args in cases:
+ type('foo')
+ m.assert_called_with('foo', *args)
+
+
class TestTypeCallable(ParserTestCase):
"""Test some callables as option/argument types"""