Пример #1
0
 def testPytdBuiltin(self):
     """Verify 'import sys'."""
     import_contents = data_files.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)
Пример #2
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"
     ):
         data_files.GetPredefinedFile("builtins",
                                      "-this-file-does-not-exist")
Пример #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 = data_files.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)
Пример #4
0
def _FindStdlibFile(name, extension=".pytd"):
    return data_files.GetPredefinedFile("stdlib", name, extension)
Пример #5
0
def _FindBuiltinFile(name, extension=".pytd"):
    return data_files.GetPredefinedFile("builtins", name, extension)
Пример #6
0
 def testGetPredefinedFileReturnsString(self):
     # smoke test, only checks that it doesn't throw and the result is a string
     self.assertIsInstance(
         data_files.GetPredefinedFile("builtins", "__builtin__"), str)