Beispiel #1
0
      g = {}
      exec("a = 11", g, g)
      assert g['a'] == 11
      """)

    def test_import_shadowed(self):
        """Test that we import modules from pytd/ rather than typeshed."""
        # We can't import the following modules from typeshed; this tests that we
        # import them correctly from our internal pytd/ versions.
        for module in ["importlib", "re", "signal"]:
            ty = self.Infer("import %s" % module)
            self.assertTypesMatchPytd(ty, f"import {module}")

    def test_cleanup(self):
        ty = self.Infer("""
      with open("foo.py", "r") as f:
        v = f.read()
      w = 42
    """)
        self.assertTypesMatchPytd(
            ty, """
      from typing import TextIO
      f = ...  # type: TextIO
      v = ...  # type: str
      w = ...  # type: int
    """)


if __name__ == "__main__":
    test_base.main()
Beispiel #2
0
# coding=utf-8
"""Tests for compilation to bytecode."""

from pytype.tests import test_base


class CompileToPycTest(test_base.TargetIndependentTest):
    def testCompilationOfUnicodeSource(self):
        self.Check("print('←↑→↓')")

    def testCompilationOfUnicodeSourceWithEncoding(self):
        self.Check("# encoding: utf-8\nprint('←↑→↓')")
        self.Check("#! my/python\n# encoding: utf-8\nprint('←↑→↓')")


test_base.main(globals(), __name__ == "__main__")