Lines Matching refs:self

31     def __init__(self, initial_value="", encoding="utf-8",
33 super(FakeIO, self).__init__(io.BytesIO(),
37 self._encoding = encoding
38 self._errors = errors
42 self.write(initial_value)
43 self.seek(0)
45 def getvalue(self):
46 self.flush()
47 return self.buffer.getvalue().decode(self._encoding, self._errors)
61 def test_encode(self):
65 self.assertEqual(out.getvalue(), encodedtextwrapped(0o666, "t1"))
69 self.assertEqual(out.getvalue(), encodedtextwrapped(0o644, "t1"))
73 self.assertEqual(out.getvalue(), encodedtextwrapped(0o666, "t1", True))
74 with self.assertRaises(TypeError):
78 def test_decode(self):
83 self.assertEqual(out.getvalue(), plaintext)
91 self.assertEqual(out.getvalue(), plaintext)
93 def test_truncatedinput(self):
98 self.fail("No exception raised")
100 self.assertEqual(str(e), "Truncated input file")
102 def test_missingbegin(self):
107 self.fail("No exception raised")
109 self.assertEqual(str(e), "No valid begin line found in input file")
111 def test_garbage_padding(self):
130 with self.subTest("uu.decode()"):
134 self.assertEqual(out.getvalue(), plaintext)
136 with self.subTest("uu_codec"):
139 self.assertEqual(decoded, plaintext)
141 def test_newlines_escaped(self):
148 self.assertIn(safefilename, out.getvalue())
150 def test_no_directory_traversal(self):
157 with self.assertRaisesRegex(uu.Error, 'directory'):
161 with self.assertRaisesRegex(uu.Error, 'directory'):
170 with self.assertRaisesRegex(uu.Error, 'directory'):
174 with self.assertRaisesRegex(uu.Error, 'directory'):
180 def setUp(self):
181 self.stdin = sys.stdin
182 self.stdout = sys.stdout
184 def tearDown(self):
185 sys.stdin = self.stdin
186 sys.stdout = self.stdout
188 def test_encode(self):
192 self.assertEqual(sys.stdout.getvalue(),
195 def test_decode(self):
200 sys.stdout = self.stdout
201 sys.stdin = self.stdin
202 self.assertEqual(stdout.getvalue(), plaintext.decode("ascii"))
206 def setUp(self):
208 self.tmpin = os_helper.TESTFN_ASCII + "i"
209 self.tmpout = os_helper.TESTFN_ASCII + "o"
210 self.addCleanup(os_helper.unlink, self.tmpin)
211 self.addCleanup(os_helper.unlink, self.tmpout)
213 def test_encode(self):
214 with open(self.tmpin, 'wb') as fin:
217 with open(self.tmpin, 'rb') as fin:
218 with open(self.tmpout, 'wb') as fout:
219 uu.encode(fin, fout, self.tmpin, mode=0o644)
221 with open(self.tmpout, 'rb') as fout:
223 self.assertEqual(s, encodedtextwrapped(0o644, self.tmpin))
226 uu.encode(self.tmpin, self.tmpout, self.tmpin, mode=0o644)
227 with open(self.tmpout, 'rb') as fout:
229 self.assertEqual(s, encodedtextwrapped(0o644, self.tmpin))
233 def test_decode(self):
234 with open(self.tmpin, 'wb') as f:
235 f.write(encodedtextwrapped(0o644, self.tmpout))
237 with open(self.tmpin, 'rb') as f:
240 with open(self.tmpout, 'rb') as f:
242 self.assertEqual(s, plaintext)
246 def test_decode_filename(self):
247 with open(self.tmpin, 'wb') as f:
248 f.write(encodedtextwrapped(0o644, self.tmpout))
250 uu.decode(self.tmpin)
252 with open(self.tmpout, 'rb') as f:
254 self.assertEqual(s, plaintext)
257 def test_decodetwice(self):
259 with open(self.tmpin, 'wb') as f:
260 f.write(encodedtextwrapped(0o644, self.tmpout))
261 with open(self.tmpin, 'rb') as f:
264 with open(self.tmpin, 'rb') as f:
265 self.assertRaises(uu.Error, uu.decode, f)
268 def test_decode_mode(self):
271 with open(self.tmpin, 'wb') as f:
272 f.write(encodedtextwrapped(expected_mode, self.tmpout))
275 self.addCleanup(os.chmod, self.tmpout, expected_mode | stat.S_IWRITE)
277 with open(self.tmpin, 'rb') as f:
280 self.assertEqual(
281 stat.S_IMODE(os.stat(self.tmpout).st_mode),