class TestPythonAstCompiler_25_grammar(BaseTestCompiler):
    def setup_method(self, method):
        self.compiler = PythonAstCompiler(self.space, "2.5")

    def test_from_future_import(self):
        source = """from __future__ import with_statement
with somtehing as stuff:
    pass
        """
        code = self.compiler.compile(source, '<filename>', 'exec', 0)
        assert isinstance(code, PyCode)
        assert code.co_filename == '<filename>'

        source2 = "with = 3"

        code = self.compiler.compile(source, '<filename2>', 'exec', 0)
        assert isinstance(code, PyCode)
        assert code.co_filename == '<filename2>'

    def test_with_empty_tuple(self):
        source = py.code.Source("""
        from __future__ import with_statement

        with x as ():
            pass
        """)
        try:
            self.compiler.compile(str(source), '<filename>', 'exec', 0)
        except OperationError, e:
            if not e.match(self.space, self.space.w_SyntaxError):
                raise
        else:
Beispiel #2
0
class TestPythonAstCompiler_25_grammar(BaseTestCompiler):
    def setup_method(self, method):
        self.compiler = PythonAstCompiler(self.space, "2.5")

    def test_from_future_import(self):
        source = """from __future__ import with_statement
with somtehing as stuff:
    pass
        """
        code = self.compiler.compile(source, '<filename>', 'exec', 0)
        assert isinstance(code, PyCode)
        assert code.co_filename == '<filename>'

        source2 = "with = 3"

        code = self.compiler.compile(source, '<filename2>', 'exec', 0)
        assert isinstance(code, PyCode)
        assert code.co_filename == '<filename2>'

    def test_with_empty_tuple(self):
        source = py.code.Source("""
        from __future__ import with_statement

        with x as ():
            pass
        """)
        try:
            self.compiler.compile(str(source), '<filename>', 'exec', 0)
        except OperationError, e:
            if not e.match(self.space, self.space.w_SyntaxError):
                raise
        else:
Beispiel #3
0
class TestPythonAstCompiler_25_grammar:
    def setup_method(self, method):
        self.compiler = PythonAstCompiler(self.space, "2.5a")

    def test_from_future_import(self):
        source = """from __future__ import with_statement
with somtehing as stuff:
    pass
        """
        code = self.compiler.compile(source, '<filename>', 'exec', 0)
        assert isinstance(code, PyCode)
        assert code.co_filename == '<filename>'

        source2 = "with = 3"

        code = self.compiler.compile(source, '<filename2>', 'exec', 0)
        assert isinstance(code, PyCode)
        assert code.co_filename == '<filename2>'
Beispiel #4
0
class TestPythonAstCompiler_25_grammar:
    def setup_method(self, method):
        self.compiler = PythonAstCompiler(self.space, "2.5a")

    def test_from_future_import(self):
        source = """from __future__ import with_statement
with somtehing as stuff:
    pass
        """
        code = self.compiler.compile(source, "<filename>", "exec", 0)
        assert isinstance(code, PyCode)
        assert code.co_filename == "<filename>"

        source2 = "with = 3"

        code = self.compiler.compile(source, "<filename2>", "exec", 0)
        assert isinstance(code, PyCode)
        assert code.co_filename == "<filename2>"
Beispiel #5
0
class TestPythonAstCompiler_25_grammar(BaseTestCompiler):
    def setup_method(self, method):
        self.compiler = PythonAstCompiler(self.space, "2.5")

    def test_from_future_import(self):
        source = """from __future__ import with_statement
with somtehing as stuff:
    pass
        """
        code = self.compiler.compile(source, '<filename>', 'exec', 0)
        assert isinstance(code, PyCode)
        assert code.co_filename == '<filename>'

        source2 = "with = 3"

        code = self.compiler.compile(source, '<filename2>', 'exec', 0)
        assert isinstance(code, PyCode)
        assert code.co_filename == '<filename2>'

    def test_with_empty_tuple(self):
        source = py.code.Source("""
        from __future__ import with_statement

        with x as ():
            pass
        """)
        try:
            self.compiler.compile(str(source), '<filename>', 'exec', 0)
        except OperationError as e:
            if not e.match(self.space, self.space.w_SyntaxError):
                raise
        else:
            py.test.fail("Did not raise")

    def test_assign_to_yield(self):
        code = 'def f(): (yield bar) += y'
        try:
            self.compiler.compile(code, '', 'single', 0)
        except OperationError as e:
            if not e.match(self.space, self.space.w_SyntaxError):
                raise
        else:
            py.test.fail("Did not raise")

    def test_invalid_genexp(self):
        code = 'dict(a = i for i in xrange(10))'
        try:
            self.compiler.compile(code, '', 'single', 0)
        except OperationError as e:
            if not e.match(self.space, self.space.w_SyntaxError):
                raise
        else:
            py.test.fail("Did not raise")
Beispiel #6
0
class TestPythonAstCompiler_25_grammar(BaseTestCompiler):
    def setup_method(self, method):
        self.compiler = PythonAstCompiler(self.space, "2.5")

    def test_from_future_import(self):
        source = """from __future__ import with_statement
with somtehing as stuff:
    pass
        """
        code = self.compiler.compile(source, '<filename>', 'exec', 0)
        assert isinstance(code, PyCode)
        assert code.co_filename == '<filename>'

        source2 = "with = 3"

        code = self.compiler.compile(source, '<filename2>', 'exec', 0)
        assert isinstance(code, PyCode)
        assert code.co_filename == '<filename2>'

    def test_with_empty_tuple(self):
        source = py.code.Source("""
        from __future__ import with_statement

        with x as ():
            pass
        """)
        try:
            self.compiler.compile(str(source), '<filename>', 'exec', 0)
        except OperationError as e:
            if not e.match(self.space, self.space.w_SyntaxError):
                raise
        else:
            py.test.fail("Did not raise")

    def test_assign_to_yield(self):
        code = 'def f(): (yield bar) += y'
        try:
            self.compiler.compile(code, '', 'single', 0)
        except OperationError as e:
            if not e.match(self.space, self.space.w_SyntaxError):
                raise
        else:
            py.test.fail("Did not raise")

    def test_invalid_genexp(self):
        code = 'dict(a = i for i in xrange(10))'
        try:
            self.compiler.compile(code, '', 'single', 0)
        except OperationError as e:
            if not e.match(self.space, self.space.w_SyntaxError):
                raise
        else:
            py.test.fail("Did not raise")
Beispiel #7
0
 def createcompiler(self):
     "Factory function creating a compiler object."
     # XXX simple selection logic for now
     try:
         return self.default_compiler
     except AttributeError:
         if self.config.objspace.compiler == 'cpython':
             compiler = CPythonCompiler(self)
         elif self.config.objspace.compiler == 'ast':
             compiler = PythonAstCompiler(self)
         else:
             raise ValueError('unknown --compiler option value: %r' %
                              (self.config.objspace.compiler, ))
         self.default_compiler = compiler
         return compiler
Beispiel #8
0
 def setup_method(self, method):
     self.compiler = PythonAstCompiler(self.space, "2.5")
 def setup_method(self, method):
     self.compiler = PythonAstCompiler(self.space, "2.5")