Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_uu.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 140d471b061a |
| children | 8c2635afbfe1 |
| rev | line source |
|---|---|
|
18483
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
1 """ |
|
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
2 Tests for uu module. |
|
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
3 Nick Mathewson |
|
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
4 """ |
|
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
5 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
6 import unittest |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
7 from test import test_support |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
8 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
9 import sys, os, uu, cStringIO |
|
18483
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
10 import uu |
|
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
11 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
12 plaintext = "The smooth-scaled python crept over the sleeping dog\n" |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
13 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
14 encodedtext = """\ |
|
18483
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
15 M5&AE('-M;V]T:\"US8V%L960@<'ET:&]N(&-R97!T(&]V97(@=&AE('-L965P |
|
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
16 (:6YG(&1O9PH """ |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
17 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
18 encodedtextwrapped = "begin %03o %s\n" + encodedtext.replace("%", "%%") + "\n \nend\n" |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
19 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
20 class UUTest(unittest.TestCase): |
|
18483
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
21 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
22 def test_encode(self): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
23 inp = cStringIO.StringIO(plaintext) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
24 out = cStringIO.StringIO() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
25 uu.encode(inp, out, "t1") |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
26 self.assertEqual(out.getvalue(), encodedtextwrapped % (0666, "t1")) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
27 inp = cStringIO.StringIO(plaintext) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
28 out = cStringIO.StringIO() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
29 uu.encode(inp, out, "t1", 0644) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
30 self.assertEqual(out.getvalue(), encodedtextwrapped % (0644, "t1")) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
31 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
32 def test_decode(self): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
33 inp = cStringIO.StringIO(encodedtextwrapped % (0666, "t1")) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
34 out = cStringIO.StringIO() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
35 uu.decode(inp, out) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
36 self.assertEqual(out.getvalue(), plaintext) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
37 inp = cStringIO.StringIO( |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
38 "UUencoded files may contain many lines,\n" + |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
39 "even some that have 'begin' in them.\n" + |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
40 encodedtextwrapped % (0666, "t1") |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
41 ) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
42 out = cStringIO.StringIO() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
43 uu.decode(inp, out) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
44 self.assertEqual(out.getvalue(), plaintext) |
|
18483
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
45 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
46 def test_truncatedinput(self): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
47 inp = cStringIO.StringIO("begin 644 t1\n" + encodedtext) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
48 out = cStringIO.StringIO() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
49 try: |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
50 uu.decode(inp, out) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
51 self.fail("No exception thrown") |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
52 except uu.Error, e: |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
53 self.assertEqual(str(e), "Truncated input file") |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
54 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
55 def test_missingbegin(self): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
56 inp = cStringIO.StringIO("") |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
57 out = cStringIO.StringIO() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
58 try: |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
59 uu.decode(inp, out) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
60 self.fail("No exception thrown") |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
61 except uu.Error, e: |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
62 self.assertEqual(str(e), "No valid begin line found in input file") |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
63 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
64 class UUStdIOTest(unittest.TestCase): |
|
18483
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
65 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
66 def setUp(self): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
67 self.stdin = sys.stdin |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
68 self.stdout = sys.stdout |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
69 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
70 def tearDown(self): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
71 sys.stdin = self.stdin |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
72 sys.stdout = self.stdout |
|
18483
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
73 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
74 def test_encode(self): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
75 sys.stdin = cStringIO.StringIO(plaintext) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
76 sys.stdout = cStringIO.StringIO() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
77 uu.encode("-", "-", "t1", 0666) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
78 self.assertEqual( |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
79 sys.stdout.getvalue(), |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
80 encodedtextwrapped % (0666, "t1") |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
81 ) |
|
18483
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
82 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
83 def test_decode(self): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
84 sys.stdin = cStringIO.StringIO(encodedtextwrapped % (0666, "t1")) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
85 sys.stdout = cStringIO.StringIO() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
86 uu.decode("-", "-") |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
87 self.assertEqual(sys.stdout.getvalue(), plaintext) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
88 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
89 class UUFileTest(unittest.TestCase): |
|
18483
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
90 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
91 def _kill(self, f): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
92 # close and remove file |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
93 try: |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
94 f.close() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
95 except (SystemExit, KeyboardInterrupt): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
96 raise |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
97 except: |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
98 pass |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
99 try: |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
100 os.unlink(f.name) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
101 except (SystemExit, KeyboardInterrupt): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
102 raise |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
103 except: |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
104 pass |
|
18483
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
105 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
106 def setUp(self): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
107 self.tmpin = test_support.TESTFN + "i" |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
108 self.tmpout = test_support.TESTFN + "o" |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
109 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
110 def tearDown(self): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
111 del self.tmpin |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
112 del self.tmpout |
|
18483
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
113 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
114 def test_encode(self): |
|
46061
f3e648fee4c1
Fix a bunch of UnboundLocalErrors when the tests fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
45468
diff
changeset
|
115 fin = fout = None |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
116 try: |
|
46388
8d555850f73d
Remove the test file before writing it in case there is no write permission.
Neal Norwitz <nnorwitz@gmail.com>
parents:
46061
diff
changeset
|
117 test_support.unlink(self.tmpin) |
|
40662
ca607d748f64
Try reverting part of r53145 that seems to cause the Windows buildbots to fail in test_uu.UUFileTest.test_encode
Neal Norwitz <nnorwitz@gmail.com>
parents:
40511
diff
changeset
|
118 fin = open(self.tmpin, 'wb') |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
119 fin.write(plaintext) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
120 fin.close() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
121 |
|
40662
ca607d748f64
Try reverting part of r53145 that seems to cause the Windows buildbots to fail in test_uu.UUFileTest.test_encode
Neal Norwitz <nnorwitz@gmail.com>
parents:
40511
diff
changeset
|
122 fin = open(self.tmpin, 'rb') |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
123 fout = open(self.tmpout, 'w') |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
124 uu.encode(fin, fout, self.tmpin, mode=0644) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
125 fin.close() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
126 fout.close() |
|
18483
2fbb25c3072e
SF patch #440144: Tests and minor bugfix for uu module.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
127 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
128 fout = open(self.tmpout, 'r') |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
129 s = fout.read() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
130 fout.close() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
131 self.assertEqual(s, encodedtextwrapped % (0644, self.tmpin)) |
|
35901
2b0cf50e77ec
Add a test for uu.encode() that passed filenames as
Walter Dörwald <walter@livinglogic.de>
parents:
28985
diff
changeset
|
132 |
|
2b0cf50e77ec
Add a test for uu.encode() that passed filenames as
Walter Dörwald <walter@livinglogic.de>
parents:
28985
diff
changeset
|
133 # in_file and out_file as filenames |
|
40511
5c67484c4cf5
[Bug #776202] Apply Walter Doerwald's patch to use text mode for encoded files
Andrew M. Kuchling <amk@amk.ca>
parents:
35901
diff
changeset
|
134 uu.encode(self.tmpin, self.tmpout, self.tmpin, mode=0644) |
|
35901
2b0cf50e77ec
Add a test for uu.encode() that passed filenames as
Walter Dörwald <walter@livinglogic.de>
parents:
28985
diff
changeset
|
135 fout = open(self.tmpout, 'r') |
|
2b0cf50e77ec
Add a test for uu.encode() that passed filenames as
Walter Dörwald <walter@livinglogic.de>
parents:
28985
diff
changeset
|
136 s = fout.read() |
|
2b0cf50e77ec
Add a test for uu.encode() that passed filenames as
Walter Dörwald <walter@livinglogic.de>
parents:
28985
diff
changeset
|
137 fout.close() |
|
2b0cf50e77ec
Add a test for uu.encode() that passed filenames as
Walter Dörwald <walter@livinglogic.de>
parents:
28985
diff
changeset
|
138 self.assertEqual(s, encodedtextwrapped % (0644, self.tmpin)) |
|
2b0cf50e77ec
Add a test for uu.encode() that passed filenames as
Walter Dörwald <walter@livinglogic.de>
parents:
28985
diff
changeset
|
139 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
140 finally: |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
141 self._kill(fin) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
142 self._kill(fout) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
143 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
144 def test_decode(self): |
|
46061
f3e648fee4c1
Fix a bunch of UnboundLocalErrors when the tests fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
45468
diff
changeset
|
145 f = None |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
146 try: |
|
46388
8d555850f73d
Remove the test file before writing it in case there is no write permission.
Neal Norwitz <nnorwitz@gmail.com>
parents:
46061
diff
changeset
|
147 test_support.unlink(self.tmpin) |
|
40511
5c67484c4cf5
[Bug #776202] Apply Walter Doerwald's patch to use text mode for encoded files
Andrew M. Kuchling <amk@amk.ca>
parents:
35901
diff
changeset
|
148 f = open(self.tmpin, 'w') |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
149 f.write(encodedtextwrapped % (0644, self.tmpout)) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
150 f.close() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
151 |
|
40511
5c67484c4cf5
[Bug #776202] Apply Walter Doerwald's patch to use text mode for encoded files
Andrew M. Kuchling <amk@amk.ca>
parents:
35901
diff
changeset
|
152 f = open(self.tmpin, 'r') |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
153 uu.decode(f) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
154 f.close() |
|
19347
3d97a4b5c6aa
Test that uu.py will not override an existing file if out_file isn't
Barry Warsaw <barry@python.org>
parents:
18957
diff
changeset
|
155 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
156 f = open(self.tmpout, 'r') |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
157 s = f.read() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
158 f.close() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
159 self.assertEqual(s, plaintext) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
160 # XXX is there an xp way to verify the mode? |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
161 finally: |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
162 self._kill(f) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
163 |
|
65821
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
164 def test_decode_filename(self): |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
165 f = None |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
166 try: |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
167 test_support.unlink(self.tmpin) |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
168 f = open(self.tmpin, 'w') |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
169 f.write(encodedtextwrapped % (0644, self.tmpout)) |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
170 f.close() |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
171 |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
172 uu.decode(self.tmpin) |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
173 |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
174 f = open(self.tmpout, 'r') |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
175 s = f.read() |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
176 f.close() |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
177 self.assertEqual(s, plaintext) |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
178 finally: |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
179 self._kill(f) |
|
140d471b061a
Merged revisions 86037 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
46388
diff
changeset
|
180 |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
181 def test_decodetwice(self): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
182 # Verify that decode() will refuse to overwrite an existing file |
|
46061
f3e648fee4c1
Fix a bunch of UnboundLocalErrors when the tests fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
45468
diff
changeset
|
183 f = None |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
184 try: |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
185 f = cStringIO.StringIO(encodedtextwrapped % (0644, self.tmpout)) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
186 |
|
40511
5c67484c4cf5
[Bug #776202] Apply Walter Doerwald's patch to use text mode for encoded files
Andrew M. Kuchling <amk@amk.ca>
parents:
35901
diff
changeset
|
187 f = open(self.tmpin, 'r') |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
188 uu.decode(f) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
189 f.close() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
190 |
|
40511
5c67484c4cf5
[Bug #776202] Apply Walter Doerwald's patch to use text mode for encoded files
Andrew M. Kuchling <amk@amk.ca>
parents:
35901
diff
changeset
|
191 f = open(self.tmpin, 'r') |
|
28985
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
192 self.assertRaises(uu.Error, uu.decode, f) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
193 f.close() |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
194 finally: |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
195 self._kill(f) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
196 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
197 def test_main(): |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
198 test_support.run_unittest(UUTest, UUStdIOTest, UUFileTest) |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
199 |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
200 if __name__=="__main__": |
|
b54a84d29c00
Port test_uu.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
24710
diff
changeset
|
201 test_main() |
