Back to index

python3.2  3.2.2
Public Member Functions
test.test_codeop.CodeopTests Class Reference

List of all members.

Public Member Functions

def assertValid
def assertIncomplete
def assertInvalid
def test_valid
def test_incomplete
def test_invalid
def test_filename

Detailed Description

Definition at line 20 of file test_codeop.py.


Member Function Documentation

def test.test_codeop.CodeopTests.assertIncomplete (   self,
  str,
  symbol = 'single' 
)
succeed iff str is the start of a valid piece of code

Definition at line 45 of file test_codeop.py.

00045 
00046     def assertIncomplete(self, str, symbol='single'):
00047         '''succeed iff str is the start of a valid piece of code'''
00048         self.assertEqual(compile_command(str, symbol=symbol), None)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_codeop.CodeopTests.assertInvalid (   self,
  str,
  symbol = 'single',
  is_syntax = 1 
)
succeed iff str is the start of an invalid piece of code

Definition at line 49 of file test_codeop.py.

00049 
00050     def assertInvalid(self, str, symbol='single', is_syntax=1):
00051         '''succeed iff str is the start of an invalid piece of code'''
00052         try:
00053             compile_command(str,symbol=symbol)
00054             self.fail("No exception thrown for invalid code")
00055         except SyntaxError:
00056             self.assertTrue(is_syntax)
00057         except OverflowError:
00058             self.assertTrue(not is_syntax)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_codeop.CodeopTests.assertValid (   self,
  str,
  symbol = 'single' 
)
succeed iff str is a valid piece of code

Definition at line 22 of file test_codeop.py.

00022 
00023     def assertValid(self, str, symbol='single'):
00024         '''succeed iff str is a valid piece of code'''
00025         if is_jython:
00026             code = compile_command(str, "<input>", symbol)
00027             self.assertTrue(code)
00028             if symbol == "single":
00029                 d,r = {},{}
00030                 saved_stdout = sys.stdout
00031                 sys.stdout = io.StringIO()
00032                 try:
00033                     exec(code, d)
00034                     exec(compile(str,"<input>","single"), r)
00035                 finally:
00036                     sys.stdout = saved_stdout
00037             elif symbol == 'eval':
00038                 ctx = {'a': 2}
00039                 d = { 'value': eval(code,ctx) }
00040                 r = { 'value': eval(str,ctx) }
00041             self.assertEqual(unify_callables(r),unify_callables(d))
00042         else:
00043             expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT)
00044             self.assertEqual(compile_command(str, "<input>", symbol), expected)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 292 of file test_codeop.py.

00292 
00293     def test_filename(self):
00294         self.assertEqual(compile_command("a = 1\n", "abc").co_filename,
00295                          compile("a = 1\n", "abc", 'single').co_filename)
00296         self.assertNotEqual(compile_command("a = 1\n", "abc").co_filename,
00297                             compile("a = 1\n", "def", 'single').co_filename)
00298 

Here is the call graph for this function:

Definition at line 125 of file test_codeop.py.

00125 
00126     def test_incomplete(self):
00127         ai = self.assertIncomplete
00128 
00129         ai("(a **")
00130         ai("(a,b,")
00131         ai("(a,b,(")
00132         ai("(a,b,(")
00133         ai("a = (")
00134         ai("a = {")
00135         ai("b + {")
00136 
00137         ai("if 9==3:\n   pass\nelse:")
00138         ai("if 9==3:\n   pass\nelse:\n")
00139         ai("if 9==3:\n   pass\nelse:\n   pass")
00140         ai("if 1:")
00141         ai("if 1:\n")
00142         ai("if 1:\n pass\n if 1:\n  pass\n else:")
00143         ai("if 1:\n pass\n if 1:\n  pass\n else:\n")
00144         ai("if 1:\n pass\n if 1:\n  pass\n else:\n  pass")
00145 
00146         ai("def x():")
00147         ai("def x():\n")
00148         ai("def x():\n\n")
00149 
00150         ai("def x():\n  pass")
00151         ai("def x():\n  pass\n ")
00152         ai("def x():\n  pass\n  ")
00153         ai("\n\ndef x():\n  pass")
00154 
00155         ai("a = 9+ \\")
00156         ai("a = 'a\\")
00157         ai("a = '''xy")
00158 
00159         ai("","eval")
00160         ai("\n","eval")
00161         ai("(","eval")
00162         ai("(\n\n\n","eval")
00163         ai("(9+","eval")
00164         ai("9+ \\","eval")
00165         ai("lambda z: \\","eval")
00166 
00167         ai("if True:\n if True:\n  if True:   \n")
00168 
00169         ai("@a(")
00170         ai("@a(b")
00171         ai("@a(b,")
00172         ai("@a(b,c")
00173         ai("@a(b,c,")
00174 
00175         ai("from a import (")
00176         ai("from a import (b")
00177         ai("from a import (b,")
00178         ai("from a import (b,c")
00179         ai("from a import (b,c,")
00180 
00181         ai("[");
00182         ai("[a");
00183         ai("[a,");
00184         ai("[a,b");
00185         ai("[a,b,");
00186 
00187         ai("{");
00188         ai("{a");
00189         ai("{a:");
00190         ai("{a:b");
00191         ai("{a:b,");
00192         ai("{a:b,c");
00193         ai("{a:b,c:");
00194         ai("{a:b,c:d");
00195         ai("{a:b,c:d,");
00196 
00197         ai("a(")
00198         ai("a(b")
00199         ai("a(b,")
00200         ai("a(b,c")
00201         ai("a(b,c,")
00202 
00203         ai("a[")
00204         ai("a[b")
00205         ai("a[b,")
00206         ai("a[b:")
00207         ai("a[b:c")
00208         ai("a[b:c:")
00209         ai("a[b:c:d")
00210 
00211         ai("def a(")
00212         ai("def a(b")
00213         ai("def a(b,")
00214         ai("def a(b,c")
00215         ai("def a(b,c,")
00216 
00217         ai("(")
00218         ai("(a")
00219         ai("(a,")
00220         ai("(a,b")
00221         ai("(a,b,")
00222 
00223         ai("if a:\n pass\nelif b:")
00224         ai("if a:\n pass\nelif b:\n pass\nelse:")
00225 
00226         ai("while a:")
00227         ai("while a:\n pass\nelse:")
00228 
00229         ai("for a in b:")
00230         ai("for a in b:\n pass\nelse:")
00231 
00232         ai("try:")
00233         ai("try:\n pass\nexcept:")
00234         ai("try:\n pass\nfinally:")
00235         ai("try:\n pass\nexcept:\n pass\nfinally:")
00236 
00237         ai("with a:")
00238         ai("with a as b:")
00239 
00240         ai("class a:")
00241         ai("class a(")
00242         ai("class a(b")
00243         ai("class a(b,")
00244         ai("class a():")
00245 
00246         ai("[x for")
00247         ai("[x for x in")
00248         ai("[x for x in (")
00249 
00250         ai("(x for")
00251         ai("(x for x in")
00252         ai("(x for x in (")

Here is the call graph for this function:

Definition at line 253 of file test_codeop.py.

00253 
00254     def test_invalid(self):
00255         ai = self.assertInvalid
00256         ai("a b")
00257 
00258         ai("a @")
00259         ai("a b @")
00260         ai("a ** @")
00261 
00262         ai("a = ")
00263         ai("a = 9 +")
00264 
00265         ai("def x():\n\npass\n")
00266 
00267         ai("\n\n if 1: pass\n\npass")
00268 
00269         ai("a = 9+ \\\n")
00270         ai("a = 'a\\ ")
00271         ai("a = 'a\\\n")
00272 
00273         ai("a = 1","eval")
00274         ai("a = (","eval")
00275         ai("]","eval")
00276         ai("())","eval")
00277         ai("[}","eval")
00278         ai("9+","eval")
00279         ai("lambda z:","eval")
00280         ai("a b","eval")
00281 
00282         ai("return 2.3")
00283         ai("if (a == 1 and b = 2): pass")
00284 
00285         ai("del 1")
00286         ai("del ()")
00287         ai("del (1,)")
00288         ai("del [1]")
00289         ai("del '1'")
00290 
00291         ai("[i for i in range(10)] = (1, 2, 3)")

Here is the call graph for this function:

Definition at line 59 of file test_codeop.py.

00059 
00060     def test_valid(self):
00061         av = self.assertValid
00062 
00063         # special case
00064         if not is_jython:
00065             self.assertEqual(compile_command(""),
00066                              compile("pass", "<input>", 'single',
00067                                      PyCF_DONT_IMPLY_DEDENT))
00068             self.assertEqual(compile_command("\n"),
00069                              compile("pass", "<input>", 'single',
00070                                      PyCF_DONT_IMPLY_DEDENT))
00071         else:
00072             av("")
00073             av("\n")
00074 
00075         av("a = 1")
00076         av("\na = 1")
00077         av("a = 1\n")
00078         av("a = 1\n\n")
00079         av("\n\na = 1\n\n")
00080 
00081         av("def x():\n  pass\n")
00082         av("if 1:\n pass\n")
00083 
00084         av("\n\nif 1: pass\n")
00085         av("\n\nif 1: pass\n\n")
00086 
00087         av("def x():\n\n pass\n")
00088         av("def x():\n  pass\n  \n")
00089         av("def x():\n  pass\n \n")
00090 
00091         av("pass\n")
00092         av("3**3\n")
00093 
00094         av("if 9==3:\n   pass\nelse:\n   pass\n")
00095         av("if 1:\n pass\n if 1:\n  pass\n else:\n  pass\n")
00096 
00097         av("#a\n#b\na = 3\n")
00098         av("#a\n\n   \na=3\n")
00099         av("a=3\n\n")
00100         av("a = 9+ \\\n3")
00101 
00102         av("3**3","eval")
00103         av("(lambda z: \n z**3)","eval")
00104 
00105         av("9+ \\\n3","eval")
00106         av("9+ \\\n3\n","eval")
00107 
00108         av("\n\na**3","eval")
00109         av("\n \na**3","eval")
00110         av("#a\n#b\na**3","eval")
00111 
00112         av("\n\na = 1\n\n")
00113         av("\n\nif 1: a=1\n\n")
00114 
00115         av("if 1:\n pass\n if 1:\n  pass\n else:\n  pass\n")
00116         av("#a\n\n   \na=3\n\n")
00117 
00118         av("\n\na**3","eval")
00119         av("\n \na**3","eval")
00120         av("#a\n#b\na**3","eval")
00121 
00122         av("def f():\n try: pass\n finally: [x for x in (1,2)]\n")
00123         av("def f():\n pass\n#foo\n")
00124         av("@a.b.c\ndef f():\n pass\n")

Here is the call graph for this function:


The documentation for this class was generated from the following file: