def testInheritForeignTypeInForeignTypeInSamePackage(self): package = Package(name=Name(["foo"])) barClass = package.addClass(Name(["Bar"]), sourceName="Bar", typeParameters=[], supertypes=[getRootClassType()], constructors=[], fields=[], methods=[], flags=frozenset([PUBLIC])) bazClass = package.addClass(Name(["Baz"]), sourceName="Baz", typeParameters=[], supertypes=[ClassType(barClass), getRootClassType()], constructors=[], fields=[], methods=[], flags=frozenset([PUBLIC])) loader = FakePackageLoader([package]) info = self.analyzeFromSource("class Quux <: foo.Baz", packageLoader=loader) quuxClass = info.package.findClass(name="Quux") self.assertEquals([ClassType(bazClass), ClassType(barClass), getRootClassType()], quuxClass.supertypes)
def testInheritForeignTypeInForeignTypeInDifferentPackage(self): fooPackage = Package(name=Name(["foo"])) barClass = fooPackage.addClass(Name(["Bar"]), sourceName="Bar", typeParameters=[], supertypes=[getRootClassType()], constructors=[], fields=[], methods=[], flags=frozenset([PUBLIC])) bazPackage = Package(name=Name(["baz"])) loader = FakePackageLoader([fooPackage, bazPackage]) bazPackage.dependencies.append(PackageDependency.fromPackage(fooPackage)) quuxClass = bazPackage.addClass(Name(["Quux"]), sourceName="Quux", typeParameters=[], supertypes=[ClassType(barClass), getRootClassType()], constructors=[], fields=[], methods=[], flags=frozenset([PUBLIC])) info = self.analyzeFromSource("class Zzyzx <: baz.Quux", packageLoader=loader) zzyzxClass = info.package.findClass(name="Zzyzx") self.assertEquals([ClassType(quuxClass), ClassType(barClass), getRootClassType()], zzyzxClass.supertypes)
def testTypeParameterCycleForeign(self): package = Package(name=Name(["foo"])) barClass = package.addClass(Name(["Bar"]), sourceName="Bar", typeParameters=[], supertypes=[getRootClassType()], constructors=[], fields=[], methods=[], flags=frozenset([PUBLIC])) loader = FakePackageLoader([package]) source = "class Baz <: foo.Bar\n" + \ "def f[static T <: Baz >: foo.Bar] = ()" self.assertRaises(InheritanceException, self.analyzeFromSource, source, packageLoader=loader)
def testInheritFromImportedClass(self): foo = Package(name=Name(["foo"])) Bar = foo.addClass(Name(["Bar"]), sourceName="Bar", typeParameters=[], supertypes=[getRootClassType()], constructors=[], fields=[], methods=[], flags=frozenset([PUBLIC])) x = foo.newField(Name(["Bar", "x"]), sourceName="x", flags=frozenset([PUBLIC, LET])) Bar.fields.append(x) source = "import foo.Bar\n" + \ "class Baz <: Bar" info = self.analyzeFromSource(source, packageLoader=FakePackageLoader([foo])) bazScope = info.getScope(info.ast.modules[0].definitions[1]) self.assertTrue(bazScope.isBound("x"))
def testInheritFromForeignType(self): package = Package(name=Name(["foo"])) foreignClass = package.addClass(Name(["Bar"]), sourceName="Bar", typeParameters=[], supertypes=[getRootClassType()], constructors=[], fields=[], methods=[], flags=frozenset([PUBLIC])) field = package.newField(Name(["Bar", "x"]), sourceName="x", flags=frozenset([PUBLIC])) foreignClass.fields = [field] loader = FakePackageLoader([package]) source = "class Baz <: foo.Bar" info = self.analyzeFromSource(source, packageLoader=loader) bazClass = info.package.findClass(name="Baz") self.assertEquals([ClassType(foreignClass), getRootClassType()], bazClass.supertypes) bazScope = info.getScope(bazClass) self.assertTrue(bazScope.isBound("x"))