summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-12-06 01:04:26 (GMT)
committerGuido van Rossum <guido@python.org>2007-12-06 01:04:26 (GMT)
commitf64db9f6db6dc631368faaeaa5547769a01682cc (patch)
treefe6ff3ed1fb0ed0d3edfe193f303a31a3d93a003 /Lib/test
parent786720876c4a473284a0324c8e3b43ed87e8f42c (diff)
downloadcpython-f64db9f6db6dc631368faaeaa5547769a01682cc.zip
cpython-f64db9f6db6dc631368faaeaa5547769a01682cc.tar.gz
cpython-f64db9f6db6dc631368faaeaa5547769a01682cc.tar.bz2
Fix the rest of issue 1400, by introducing a proper implementation of
line buffering. The TextIOWrapper class no longer calls isatty() on every write() call.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/output/test_cProfile28
-rw-r--r--Lib/test/output/test_profile28
-rw-r--r--Lib/test/test_io.py17
3 files changed, 43 insertions, 30 deletions
diff --git a/Lib/test/output/test_cProfile b/Lib/test/output/test_cProfile
index 2b799ec..0037924 100644
--- a/Lib/test/output/test_cProfile
+++ b/Lib/test/output/test_cProfile
@@ -5,10 +5,10 @@ test_cProfile
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 1.000 1.000 <string>:1(<module>)
- 2 0.000 0.000 0.000 0.000 io.py:1193(flush)
- 1 0.000 0.000 0.000 0.000 io.py:257(flush)
- 1 0.000 0.000 0.000 0.000 io.py:644(closed)
- 1 0.000 0.000 0.000 0.000 io.py:862(flush)
+ 2 0.000 0.000 0.000 0.000 io.py:1201(flush)
+ 1 0.000 0.000 0.000 0.000 io.py:259(flush)
+ 1 0.000 0.000 0.000 0.000 io.py:646(closed)
+ 1 0.000 0.000 0.000 0.000 io.py:864(flush)
8 0.064 0.008 0.080 0.010 test_cProfile.py:103(subhelper)
28 0.028 0.001 0.028 0.001 test_cProfile.py:115(__getattr__)
1 0.270 0.270 1.000 1.000 test_cProfile.py:30(testfunc)
@@ -30,11 +30,11 @@ test_cProfile
Function called...
ncalls tottime cumtime
<string>:1(<module>) -> 1 0.270 1.000 test_cProfile.py:30(testfunc)
-io.py:1193(flush) -> 1 0.000 0.000 io.py:257(flush)
- 1 0.000 0.000 io.py:862(flush)
-io.py:257(flush) ->
-io.py:644(closed) ->
-io.py:862(flush) -> 1 0.000 0.000 io.py:644(closed)
+io.py:1201(flush) -> 1 0.000 0.000 io.py:259(flush)
+ 1 0.000 0.000 io.py:864(flush)
+io.py:259(flush) ->
+io.py:646(closed) ->
+io.py:864(flush) -> 1 0.000 0.000 io.py:646(closed)
test_cProfile.py:103(subhelper) -> 16 0.016 0.016 test_cProfile.py:115(__getattr__)
test_cProfile.py:115(__getattr__) ->
test_cProfile.py:30(testfunc) -> 1 0.014 0.130 test_cProfile.py:40(factorial)
@@ -53,7 +53,7 @@ test_cProfile.py:89(helper2_indirect) -> 2 0.006 0.040
test_cProfile.py:93(helper2) -> 8 0.064 0.080 test_cProfile.py:103(subhelper)
8 0.000 0.008 {hasattr}
{exec} -> 1 0.000 1.000 <string>:1(<module>)
- 2 0.000 0.000 io.py:1193(flush)
+ 2 0.000 0.000 io.py:1201(flush)
{hasattr} -> 12 0.012 0.012 test_cProfile.py:115(__getattr__)
{method 'append' of 'list' objects} ->
{method 'disable' of '_lsprof.Profiler' objects} ->
@@ -65,10 +65,10 @@ test_cProfile.py:93(helper2) -> 8 0.064 0.080
Function was called by...
ncalls tottime cumtime
<string>:1(<module>) <- 1 0.000 1.000 {exec}
-io.py:1193(flush) <- 2 0.000 0.000 {exec}
-io.py:257(flush) <- 1 0.000 0.000 io.py:1193(flush)
-io.py:644(closed) <- 1 0.000 0.000 io.py:862(flush)
-io.py:862(flush) <- 1 0.000 0.000 io.py:1193(flush)
+io.py:1201(flush) <- 2 0.000 0.000 {exec}
+io.py:259(flush) <- 1 0.000 0.000 io.py:1201(flush)
+io.py:646(closed) <- 1 0.000 0.000 io.py:864(flush)
+io.py:864(flush) <- 1 0.000 0.000 io.py:1201(flush)
test_cProfile.py:103(subhelper) <- 8 0.064 0.080 test_cProfile.py:93(helper2)
test_cProfile.py:115(__getattr__) <- 16 0.016 0.016 test_cProfile.py:103(subhelper)
12 0.012 0.012 {hasattr}
diff --git a/Lib/test/output/test_profile b/Lib/test/output/test_profile
index ca09f8c..5ecdbae 100644
--- a/Lib/test/output/test_profile
+++ b/Lib/test/output/test_profile
@@ -10,10 +10,10 @@ test_profile
12 0.000 0.000 0.012 0.001 :0(hasattr)
1 0.000 0.000 0.000 0.000 :0(setprofile)
1 0.000 0.000 1.000 1.000 <string>:1(<module>)
- 2 0.000 0.000 0.000 0.000 io.py:1193(flush)
- 1 0.000 0.000 0.000 0.000 io.py:257(flush)
- 1 0.000 0.000 0.000 0.000 io.py:644(closed)
- 1 0.000 0.000 0.000 0.000 io.py:862(flush)
+ 2 0.000 0.000 0.000 0.000 io.py:1201(flush)
+ 1 0.000 0.000 0.000 0.000 io.py:259(flush)
+ 1 0.000 0.000 0.000 0.000 io.py:646(closed)
+ 1 0.000 0.000 0.000 0.000 io.py:864(flush)
0 0.000 0.000 profile:0(profiler)
1 0.000 0.000 1.000 1.000 profile:0(testfunc())
8 0.064 0.008 0.080 0.010 test_profile.py:103(subhelper)
@@ -33,15 +33,15 @@ Function called...
:0(append) ->
:0(exc_info) ->
:0(exec) -> <string>:1(<module>)(1) 1.000
- io.py:1193(flush)(2) 0.000
+ io.py:1201(flush)(2) 0.000
:0(hasattr) -> test_profile.py:115(__getattr__)(12) 0.028
:0(setprofile) ->
<string>:1(<module>) -> test_profile.py:30(testfunc)(1) 1.000
-io.py:1193(flush) -> io.py:257(flush)(1) 0.000
- io.py:862(flush)(1) 0.000
-io.py:257(flush) ->
-io.py:644(closed) ->
-io.py:862(flush) -> io.py:644(closed)(1) 0.000
+io.py:1201(flush) -> io.py:259(flush)(1) 0.000
+ io.py:864(flush)(1) 0.000
+io.py:259(flush) ->
+io.py:646(closed) ->
+io.py:864(flush) -> io.py:646(closed)(1) 0.000
profile:0(profiler) -> profile:0(testfunc())(1) 1.000
profile:0(testfunc()) -> :0(exec)(1) 1.000
:0(setprofile)(1) 0.000
@@ -74,10 +74,10 @@ Function was called by...
test_profile.py:93(helper2)(8) 0.400
:0(setprofile) <- profile:0(testfunc())(1) 1.000
<string>:1(<module>) <- :0(exec)(1) 1.000
-io.py:1193(flush) <- :0(exec)(2) 1.000
-io.py:257(flush) <- io.py:1193(flush)(1) 0.000
-io.py:644(closed) <- io.py:862(flush)(1) 0.000
-io.py:862(flush) <- io.py:1193(flush)(1) 0.000
+io.py:1201(flush) <- :0(exec)(2) 1.000
+io.py:259(flush) <- io.py:1201(flush)(1) 0.000
+io.py:646(closed) <- io.py:864(flush)(1) 0.000
+io.py:864(flush) <- io.py:1201(flush)(1) 0.000
profile:0(profiler) <-
profile:0(testfunc()) <- profile:0(profiler)(1) 0.000
test_profile.py:103(subhelper) <- test_profile.py:93(helper2)(8) 0.400
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index f5b4a94..87e871b 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -496,6 +496,17 @@ class TextIOWrapperTest(unittest.TestCase):
def tearDown(self):
test_support.unlink(test_support.TESTFN)
+ def testLineBuffering(self):
+ r = io.BytesIO()
+ b = io.BufferedWriter(r, 1000)
+ t = io.TextIOWrapper(b, newline="\n", line_buffering=True)
+ t.write("X")
+ self.assertEquals(r.getvalue(), b"") # No flush happened
+ t.write("Y\nZ")
+ self.assertEquals(r.getvalue(), b"XY\nZ") # All got flushed
+ t.write("A\rB")
+ self.assertEquals(r.getvalue(), b"XY\nZA\rB")
+
def testEncodingErrorsReading(self):
# (1) default
b = io.BytesIO(b"abc\n\xff\n")
@@ -525,13 +536,15 @@ class TextIOWrapperTest(unittest.TestCase):
self.assertRaises(UnicodeError, t.write, "\xff")
# (3) ignore
b = io.BytesIO()
- t = io.TextIOWrapper(b, encoding="ascii", errors="ignore", newline="\n")
+ t = io.TextIOWrapper(b, encoding="ascii", errors="ignore",
+ newline="\n")
t.write("abc\xffdef\n")
t.flush()
self.assertEquals(b.getvalue(), b"abcdef\n")
# (4) replace
b = io.BytesIO()
- t = io.TextIOWrapper(b, encoding="ascii", errors="replace", newline="\n")
+ t = io.TextIOWrapper(b, encoding="ascii", errors="replace",
+ newline="\n")
t.write("abc\xffdef\n")
t.flush()
self.assertEquals(b.getvalue(), b"abc?def\n")