Ejemplo n.º 1
0
 def testGetPredefinedFileThrows(self):
     # smoke test, only checks that it does throw
     with self.assertRaisesRegexp(
             IOError,
             r"File not found|Resource not found|No such file or directory"
     ):
         utils.GetPredefinedFile("builtins", "-this-file-does-not-exist")
Ejemplo n.º 2
0
 def testPytdBuiltin(self):
     """Verify 'import sys'."""
     import_contents = utils.GetPredefinedFile("builtins", "sys")
     with open(
             os.path.join(os.path.dirname(pytd.__file__), "builtins",
                          "sys.pytd"), "rb") as fi:
         file_contents = fi.read()
     self.assertMultiLineEqual(import_contents, file_contents)
Ejemplo n.º 3
0
def ParsePredefinedPyTD(pytd_subdir, module, python_version):
  """Load and parse a *.pytd from "pytd/{pytd_subdir}/{module}.pytd".

  Args:
    pytd_subdir: the directory where the module should be found
    module: the module name (without any file extension)
    python_version: sys.version_info[:2]

  Returns:
    The AST of the module; None if the module doesn't exist in pytd_subdir.
  """
  try:
    src = utils.GetPredefinedFile(pytd_subdir, module)
  except IOError:
    return None
  return ParsePyTD(src, filename=os.path.join(pytd_subdir, module + ".pytd"),
                   module=module,
                   python_version=python_version).Replace(name=module)
Ejemplo n.º 4
0
 def testGetPredefinedFileReturnsString(self):
     # smoke test, only checks that it doesn't throw and the result is a string
     self.assertIsInstance(
         utils.GetPredefinedFile("builtins", "__builtin__"), str)
Ejemplo n.º 5
0
def _FindBuiltinFile(name, extension=".pytd"):
    # TODO(kramm): fix circular import
    from pytype.pytd import utils  # pylint: disable=g-import-not-at-top
    return utils.GetPredefinedFile("builtins", name, extension)
Ejemplo n.º 6
0
def _FindStdlibFile(name, extension=".pytd"):
  return utils.GetPredefinedFile("stdlib", name, extension)
Ejemplo n.º 7
0
def _FindBuiltinFile(name, extension=".pytd"):
  return utils.GetPredefinedFile("builtins", name, extension)