Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
test.test_syntax.SyntaxTestCase Class Reference

List of all members.

Public Member Functions

def test_assign_call
def test_assign_del
def test_global_err_then_warn
def test_break_outside_loop
def test_unexpected_indent
def test_no_indent
def test_bad_outdent
def test_kwargs_last

Private Member Functions

def _check_error

Detailed Description

Definition at line 527 of file test_syntax.py.


Member Function Documentation

def test.test_syntax.SyntaxTestCase._check_error (   self,
  code,
  errtext,
  filename = "<testcase>",
  mode = "exec",
  subclass = None 
) [private]
Check that compiling code raises SyntaxError with errtext.

errtest is a regular expression that must be present in the
test of the exception raised.  If subclass is specified it
is the expected subclass of SyntaxError (e.g. IndentationError).

Definition at line 530 of file test_syntax.py.

00530 
00531                      filename="<testcase>", mode="exec", subclass=None):
00532         """Check that compiling code raises SyntaxError with errtext.
00533 
00534         errtest is a regular expression that must be present in the
00535         test of the exception raised.  If subclass is specified it
00536         is the expected subclass of SyntaxError (e.g. IndentationError).
00537         """
00538         try:
00539             compile(code, filename, mode)
00540         except SyntaxError as err:
00541             if subclass and not isinstance(err, subclass):
00542                 self.fail("SyntaxError is not a %s" % subclass.__name__)
00543             mo = re.search(errtext, str(err))
00544             if mo is None:
00545                 self.fail("SyntaxError did not contain '%r'" % (errtext,))
00546         else:
00547             self.fail("compile() did not raise SyntaxError")

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 548 of file test_syntax.py.

00548 
00549     def test_assign_call(self):
00550         self._check_error("f() = 1", "assign")

Here is the call graph for this function:

Definition at line 551 of file test_syntax.py.

00551 
00552     def test_assign_del(self):
00553         self._check_error("del f()", "delete")

Here is the call graph for this function:

Definition at line 579 of file test_syntax.py.

00579 
00580     def test_bad_outdent(self):
00581         self._check_error("if 1:\n  foo()\n bar()",
00582                           "unindent does not match .* level",
00583                           subclass=IndentationError)

Here is the call graph for this function:

Definition at line 568 of file test_syntax.py.

00568 
00569     def test_break_outside_loop(self):
00570         self._check_error("break", "outside loop")

Here is the call graph for this function:

Definition at line 554 of file test_syntax.py.

00554 
00555     def test_global_err_then_warn(self):
00556         # Bug tickler:  The SyntaxError raised for one global statement
00557         # shouldn't be clobbered by a SyntaxWarning issued for a later one.
00558         source = """if 1:
00559             def error(a):
00560                 global a  # SyntaxError
00561             def warning():
00562                 b = 1
00563                 global b  # SyntaxWarning
00564             """
00565         warnings.filterwarnings(action='ignore', category=SyntaxWarning)
00566         self._check_error(source, "global")
00567         warnings.filters.pop(0)

Here is the call graph for this function:

Definition at line 584 of file test_syntax.py.

00584 
00585     def test_kwargs_last(self):
00586         self._check_error("int(base=10, '2')", "non-keyword arg")

Here is the call graph for this function:

Definition at line 575 of file test_syntax.py.

00575 
00576     def test_no_indent(self):
00577         self._check_error("if 1:\nfoo()", "expected an indented block",
00578                           subclass=IndentationError)

Here is the call graph for this function:

Definition at line 571 of file test_syntax.py.

00571 
00572     def test_unexpected_indent(self):
00573         self._check_error("foo()\n bar()\n", "unexpected indent",
00574                           subclass=IndentationError)

Here is the call graph for this function:


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