Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(36843)

Side by Side Diff: Lib/test/test_pep3120.py

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_pep247.py ('k') | Lib/test/test_pep380.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is marked as binary in the CVS, to prevent MacCVS from recoding it. 1 # This file is marked as binary in the CVS, to prevent MacCVS from recoding it.
2 2
3 import unittest 3 import unittest
4 from test import support 4 from test import support
5 5
6 class PEP3120Test(unittest.TestCase): 6 class PEP3120Test(unittest.TestCase):
7 7
8 def test_pep3120(self): 8 def test_pep3120(self):
9 self.assertEqual( 9 self.assertEqual(
10 "Питон".encode("utf-8"), 10 "Питон".encode("utf-8"),
11 b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd' 11 b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
12 ) 12 )
13 self.assertEqual( 13 self.assertEqual(
14 "\П".encode("utf-8"), 14 "\П".encode("utf-8"),
15 b'\\\xd0\x9f' 15 b'\\\xd0\x9f'
16 ) 16 )
17 17
18 def test_badsyntax(self): 18 def test_badsyntax(self):
19 try: 19 try:
20 import test.badsyntax_pep3120 20 import test.badsyntax_pep3120
21 except SyntaxError as msg: 21 except SyntaxError as msg:
22 msg = str(msg).lower() 22 msg = str(msg).lower()
23 self.assertTrue('utf-8' in msg) 23 self.assertIn('utf-8', msg)
24 else: 24 else:
25 self.fail("expected exception didn't occur") 25 self.fail("expected exception didn't occur")
26 26
27 27
28 class BuiltinCompileTests(unittest.TestCase): 28 class BuiltinCompileTests(unittest.TestCase):
29 29
30 # Issue 3574. 30 # Issue 3574.
31 def test_latin1(self): 31 def test_latin1(self):
32 # Allow compile() to read Latin-1 source. 32 # Allow compile() to read Latin-1 source.
33 source_code = '# coding: Latin-1\nu = "Ç"\n'.encode("Latin-1") 33 source_code = '# coding: Latin-1\nu = "Ç"\n'.encode("Latin-1")
34 try: 34 try:
35 code = compile(source_code, '<dummy>', 'exec') 35 code = compile(source_code, '<dummy>', 'exec')
36 except SyntaxError: 36 except SyntaxError:
37 self.fail("compile() cannot handle Latin-1 source") 37 self.fail("compile() cannot handle Latin-1 source")
38 ns = {} 38 ns = {}
39 exec(code, ns) 39 exec(code, ns)
40 self.assertEqual('Ç', ns['u']) 40 self.assertEqual('Ç', ns['u'])
41 41
42 42
43 def test_main(): 43 def test_main():
44 support.run_unittest(PEP3120Test, BuiltinCompileTests) 44 support.run_unittest(PEP3120Test, BuiltinCompileTests)
45 45
46 if __name__=="__main__": 46 if __name__=="__main__":
47 test_main() 47 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_pep247.py ('k') | Lib/test/test_pep380.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+