6 from test_support
import verify
, TestFailed
, verbose
, TESTFN
9 from StringIO
import StringIO
11 teststr
= "The smooth-scaled python crept over the sleeping dog\n"
13 M5&AE('-M;V]T:\"US8V%L960@<'ET:&]N(&-R97!T(&]V97(@=&AE('-L965P
15 encoded1
= "begin 666 t1\n"+expected
+"\n \nend\n"
17 print '1. encode file->file'
18 inp
= StringIO(teststr
)
20 uu
.encode(inp
, out
, "t1")
21 verify(out
.getvalue() == encoded1
)
22 inp
= StringIO(teststr
)
24 uu
.encode(inp
, out
, "t1", 0644)
25 verify(out
.getvalue() == "begin 644 t1\n"+expected
+"\n \nend\n")
28 print '2. decode file->file'
29 inp
= StringIO(encoded1
)
32 verify(out
.getvalue() == teststr
)
33 inp
= StringIO("""UUencoded files may contain many lines,
34 even some that have 'begin' in them.\n"""+encoded1
)
37 verify(out
.getvalue() == teststr
)
40 stdoutsave
= sys
.stdout
43 print '3. encode stdin->stdout'
44 sys
.stdin
= StringIO(teststr
)
45 sys
.stdout
= StringIO()
46 uu
.encode("-", "-", "t1", 0666)
47 verify(sys
.stdout
.getvalue() == encoded1
)
49 print >>stdoutsave
, '4. decode stdin->stdout'
50 sys
.stdin
= StringIO(encoded1
)
51 sys
.stdout
= StringIO()
53 verify(sys
.stdout
.getvalue() == teststr
)
56 sys
.stdout
= stdoutsave
59 print '5. encode file->file'
63 fin
= open(tmpIn
, 'w')
67 fin
= open(tmpIn
, 'r')
68 fout
= open(tmpOut
, 'w')
69 uu
.encode(fin
, fout
, tmpIn
, mode
=0644)
73 fout
= open(tmpOut
, 'r')
76 verify(s
== 'begin 644 ' + tmpIn
+ '\n' + expected
+ '\n \nend\n')
80 print '6. decode file-> file'
82 fin
= open(tmpIn
, 'r')
86 # XXX is there an xp way to verify the mode?
107 print '7. error: truncated input'
108 inp
= StringIO("begin 644 t1\n"+expected
)
112 raise TestFailed("No exception thrown")
114 verify(str(e
) == 'Truncated input file')
117 print '8. error: missing begin'
122 raise TestFailed("No exception thrown")
124 verify(str(e
) == 'No valid begin line found in input file')