コード例 #1
0
    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"))
コード例 #2
0
 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"))