summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_fileinput.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_fileinput.py')
-rw-r--r--Lib/test/test_fileinput.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py
index 4080a25..ff3fc24 100644
--- a/Lib/test/test_fileinput.py
+++ b/Lib/test/test_fileinput.py
@@ -6,7 +6,7 @@ Nick Mathewson
from test.test_support import verify, verbose, TESTFN, TestFailed
import sys, os, re
from StringIO import StringIO
-from fileinput import FileInput
+from fileinput import FileInput, hook_encoded
# The fileinput module has 2 interfaces: the FileInput class which does
# all the work, and a few functions (input, etc.) that use a global _state
@@ -200,3 +200,25 @@ try:
verify(lines == ["A\n", "B\n", "C\n", "D"])
finally:
remove_tempfiles(t1)
+
+if verbose:
+ print "18. Test file opening hook"
+try:
+ # cannot use openhook and inplace mode
+ fi = FileInput(inplace=1, openhook=lambda f,m: None)
+ raise TestFailed("FileInput should raise if both inplace "
+ "and openhook arguments are given")
+except ValueError:
+ pass
+try:
+ fi = FileInput(openhook=1)
+ raise TestFailed("FileInput should check openhook for being callable")
+except ValueError:
+ pass
+try:
+ t1 = writeTmp(1, ["A\nB"])
+ fi = FileInput(files=t1, openhook=hook_encoded("rot13"))
+ lines = list(fi)
+ verify(lines == ["N\n", "O"])
+finally:
+ remove_tempfiles(t1)