TypeShed { public static Set<Symbol> symbolsForModule(String moduleName) { if (!TypeShed.typeShedSymbols.containsKey(moduleName)) { Set<Symbol> symbols = searchTypeShedForModule(moduleName); typeShedSymbols.put(moduleName, symbols); return symbols; } return TypeShed.typeShedSymbols.get(moduleName); } private  TypeShed(); static Map<String, Symbol> builtinSymbols(); static Set<Symbol> symbolsForModule(String moduleName); @CheckForNull static Symbol symbolWithFQN(String stdLibModuleName, String fullyQualifiedName); static ClassSymbol typeShedClass(String fullyQualifiedName); static Collection<Symbol> stubFilesSymbols();  }
@Test public void should_resolve_packages() { assertThat(TypeShed.symbolsForModule("urllib")).isNotEmpty(); assertThat(TypeShed.symbolsForModule("ctypes")).isNotEmpty(); assertThat(TypeShed.symbolsForModule("email")).isNotEmpty(); assertThat(TypeShed.symbolsForModule("json")).isNotEmpty(); assertThat(TypeShed.symbolsForModule("docutils")).isNotEmpty(); assertThat(TypeShed.symbolsForModule("ctypes.util")).isNotEmpty(); assertThat(TypeShed.symbolsForModule("lib2to3.pgen2.grammar")).isNotEmpty(); assertThat(TypeShed.symbolsForModule("cryptography")).isEmpty(); assertThat(TypeShed.symbolsForModule("kazoo")).isEmpty(); }
@Test public void package_relative_import() { Map<String, Symbol> osSymbols = TypeShed.symbolsForModule("os").stream().collect(Collectors.toMap(Symbol::name, Function.identity(), AmbiguousSymbolImpl::create)); Symbol sysSymbol = osSymbols.get("sys"); assertThat(sysSymbol.kind()).isEqualTo(Kind.AMBIGUOUS); Symbol timesResult = osSymbols.get("times_result"); assertThat(timesResult.kind()).isEqualTo(Kind.CLASS); assertThat(timesResult.fullyQualifiedName()).isEqualTo("posix.times_result"); Map<String, Symbol> requestsSymbols = TypeShed.symbolsForModule("requests").stream().collect(Collectors.toMap(Symbol::name, Function.identity(), AmbiguousSymbolImpl::create)); Symbol requestSymbol = requestsSymbols.get("request"); assertThat(requestSymbol.kind()).isEqualTo(Kind.FUNCTION); assertThat(requestSymbol.fullyQualifiedName()).isEqualTo("requests.api.request"); }
@Test public void two_exported_symbols_with_same_local_names() { Map<String, Symbol> osSymbols = TypeShed.symbolsForModule("os").stream().collect(Collectors.toMap(Symbol::name, Function.identity(), AmbiguousSymbolImpl::create)); Map<String, Symbol> posixSymbols = TypeShed.symbolsForModule("posix").stream().collect(Collectors.toMap(Symbol::name, Function.identity())); Symbol setupSymbolFromPosix = posixSymbols.get("stat_result"); Symbol setupSymbolFromOs = osSymbols.get("stat_result"); assertThat(setupSymbolFromPosix.kind()).isEqualTo(Kind.AMBIGUOUS); assertThat(setupSymbolFromOs.kind()).isEqualTo(Kind.AMBIGUOUS); }
@Test public void package_django() { Map<String, Symbol> djangoSymbols = TypeShed.symbolsForModule("django.http").stream().collect(Collectors.toMap(Symbol::name, Function.identity(), AmbiguousSymbolImpl::create)); Symbol responseSymbol = djangoSymbols.get("HttpResponse"); assertThat(responseSymbol.kind()).isEqualTo(Kind.CLASS); assertThat(responseSymbol.fullyQualifiedName()).isEqualTo("django.http.response.HttpResponse"); }
@Test public void package_django_class_property_type() { Map<String, Symbol> djangoSymbols = TypeShed.symbolsForModule("django.http.request").stream().collect(Collectors.toMap(Symbol::name, Function.identity(), AmbiguousSymbolImpl::create)); Symbol requestSymbol = djangoSymbols.get("HttpRequest"); assertThat(requestSymbol.kind()).isEqualTo(Kind.CLASS); assertThat(((ClassSymbol) requestSymbol).declaredMembers().iterator().next().annotatedTypeName()).isEqualTo("django.http.request.QueryDict"); }
@Test public void package_sqlite3_connect_type_in_ambiguous_symbol() { Map<String, Symbol> djangoSymbols = TypeShed.symbolsForModule("sqlite3").stream().collect(Collectors.toMap(Symbol::name, Function.identity(), AmbiguousSymbolImpl::create)); Symbol requestSymbol = djangoSymbols.get("connect"); assertThat(((FunctionSymbolImpl) ((((AmbiguousSymbolImpl) requestSymbol).alternatives()).toArray()[0])).annotatedReturnTypeName()).isEqualTo("sqlite3.dbapi2.Connection"); }