diff options
author | Georg Brandl <georg@python.org> | 2006-02-19 14:57:47 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-02-19 14:57:47 (GMT) |
commit | c98eeede175a9a0a6d05b7a6e6b105bcd0fc79fa (patch) | |
tree | 3ade5a77f5303b09814abe7c311a808317a5ac6c /Lib/test/test_fileinput.py | |
parent | c029f873cb170a5525ef78b00b3957e52be41cda (diff) | |
download | cpython-c98eeede175a9a0a6d05b7a6e6b105bcd0fc79fa.zip cpython-c98eeede175a9a0a6d05b7a6e6b105bcd0fc79fa.tar.gz cpython-c98eeede175a9a0a6d05b7a6e6b105bcd0fc79fa.tar.bz2 |
Patch #1215184: FileInput now can be given an opening hook which can
be used to control how files are opened.
Diffstat (limited to 'Lib/test/test_fileinput.py')
-rw-r--r-- | Lib/test/test_fileinput.py | 24 |
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) |