示例#1
0
 def test_get_pytd_paths(self):
     # Set TYPESHED_HOME to pytype's internal typeshed copy.
     t = typeshed.Typeshed()
     old_env = os.environ.copy()
     os.environ["TYPESHED_HOME"] = t.root
     try:
         # Check that get_pytd_paths() works with a typeshed installation that
         # reads from TYPESHED_HOME.
         t = typeshed.Typeshed()
         paths = {
             p.rsplit("pytype/", 1)[-1]
             for p in t.get_pytd_paths([2, 7])
         }
         self.assertSetEqual(paths, {"pytd/builtins/2", "pytd/stdlib/2"})
     finally:
         os.environ = old_env
示例#2
0
 def test_get_all_module_names_2(self):
     t = typeshed.Typeshed()
     modules = t.get_all_module_names([2, 7])
     self.assertIn("collections", modules)
     self.assertIn("csv", modules)
     self.assertIn("ctypes", modules)
     self.assertIn("xml.etree.ElementTree", modules)
     self.assertIn("six.moves", modules)
示例#3
0
def _generate_builtins_pickle(options):
    """Create a pickled file with the standard library (typeshed + builtins)."""
    loader = load_pytd.create_loader(options)
    t = typeshed.Typeshed()
    module_names = t.get_all_module_names(options.python_version)
    blacklist = set(t.blacklisted_modules(options.python_version))
    for m in sorted(module_names):
        if m not in blacklist:
            loader.import_name(m)
    loader.save_to_pickle(options.generate_builtins)
示例#4
0
def initialize_typeshed_or_die():
    """Initialize a Typeshed object or die.

  Returns:
    An instance of Typeshed()
  """
    try:
        return typeshed.Typeshed()
    except IOError as e:
        print(str(e))
        sys.exit(1)
示例#5
0
def _generate_builtins_pickle(options):
  """Create a pickled file with the standard library (typeshed + builtins)."""
  loader = load_pytd.create_loader(options)
  t = typeshed.Typeshed()
  module_names = t.get_all_module_names(options.python_version)
  blacklist = set(t.blacklisted_modules(options.python_version))
  if options.python_version[0] == 3:
    # TODO(mdemello): plistlib should be in the typeshed blacklist and isn't.
    blacklist.add("plistlib")
  for m in sorted(module_names):
    if m not in blacklist:
      loader.import_name(m)
  loader.save_to_pickle(options.generate_builtins)
def determine_files_to_test(*, typeshed_location: str,
                            paths: Sequence[str]) -> List[str]:
    """Determine all files to test, checking if it's in the exclude list and which Python versions to use.

    Returns a list of pairs of the file path and Python version as an int."""
    filenames = find_stubs_in_paths(paths)
    ts = typeshed.Typeshed()
    skipped = set(ts.read_blacklist())
    files = []
    for f in sorted(filenames):
        rel = _get_relative(f)
        if rel in skipped or "@python2" in f:
            continue
        files.append(f)
    return files
示例#7
0
class TestTypeshedParsing(unittest.TestCase):
  """Test that we can parse a given pyi file."""
  # Files that we currently can't parse
  WANTED = re.compile(r"stdlib/(2\.7|2and3)/.*\.pyi$")
  t = typeshed.Typeshed()
  TYPESHED_DIR = t.root
  SKIPPED_FILES = list(t.read_blacklist())
  SKIPPED = re.compile("(%s)$" % "|".join(SKIPPED_FILES))

  # Generate test methods
  # pylint: disable=no-self-argument,g-wrong-blank-lines,undefined-loop-variable
  for f in _walk_dir(TYPESHED_DIR):
    if WANTED.search(f) and not SKIPPED.search(f):
      def _bind(f):
        return lambda self: _test_parse(f)
      locals()[_filename_to_testname(f)] = _bind(f)
      del _bind
  del f
def determine_files_to_test(*, typeshed_location: str,
                            paths: Sequence[str]) -> List[Tuple[str, int]]:
    """Determine all files to test, checking if it's in the exclude list and which Python versions to use.

    Returns a list of pairs of the file path and Python version as an int."""
    filenames = find_stubs_in_paths(paths)
    ts = typeshed.Typeshed()
    skipped = set(ts.read_blacklist())
    files = []
    for f in sorted(filenames):
        rel = _get_relative(f)
        if rel in skipped:
            continue
        versions = ts.get_python_major_versions(rel)
        if versions:
            files.extend((f, v) for v in versions)
        else:
            print("Unrecognized path: {}".format(f))
    return files
示例#9
0
 def test_blacklisted_modules(self):
     t = typeshed.Typeshed()
     for module_name in t.blacklisted_modules([2, 7]):
         self.assertNotIn("/", module_name)
     for module_name in t.blacklisted_modules([3, 6]):
         self.assertNotIn("/", module_name)
示例#10
0
 def test_read_blacklist(self):
     t = typeshed.Typeshed()
     for filename in t.read_blacklist():
         self.assertTrue(
             filename.startswith("stdlib")
             or filename.startswith("third_party"))
示例#11
0
 def test_get_all_stdlib_module_names_3(self):
     t = typeshed.Typeshed()
     modules = t.get_all_stdlib_module_names([3, 5])
     self.assertIn("asyncio", modules)
     self.assertIn("collections", modules)
     self.assertIn("configparser", modules)
示例#12
0
 def setUp(self):
     super(TestTypeshedLoading, self).setUp()
     self.ts = typeshed.Typeshed()
示例#13
0
 def setUp(self):
   super().setUp()
   self.ts = typeshed.Typeshed()
示例#14
0
 def setUp(self):
     super(TestTypeshedLoading, self).setUp()
     self.ts = typeshed.Typeshed(typeshed_location="typeshed",
                                 use_pickled=False)