Пример #1
0
        public async Task NestedClasses()
        {
            const string code     = @"
x = 'str'

class A:
    def methodA(self):
        return True

class B:
    x: int

    class C:
        def __init__(self):
            self.y = 1
        def methodC(self):
            return False
        
    def methodB1(self):
        return self.C()

    def methodB2(self):
        return self.C().y

c = B().methodB1()
";
            var          analysis = await GetAnalysisAsync(code);

            var model = ModuleModel.FromAnalysis(analysis, Services, AnalysisCachingLevel.Library);
            var json  = ToJson(model);

            Baseline.CompareToFile(BaselineFileName, json);
        }
Пример #2
0
        public async Task SmokeTest()
        {
            const string code  = @"
x = 'str'

class C:
    x: int
    def __init__(self):
        self.y = 1
        
    def method(self):
        return func()

    @property
    def prop(self) -> int:
        return x

def func():
    return 2.0

c = C()
";
            var          model = await GetModelAsync(code);

            var json = ToJson(model);

            Baseline.CompareToFile(BaselineFileName, json);
        }
        public async Task SmokeTest()
        {
            const string code     = @"
x = 'str'

class C:
    x: int
    def __init__(self):
        self.y = 1
        
    def method(self):
        return func()

    @property
    def prop(self) -> int:
        return x

def func():
    return 2.0

c = C()
";
            var          analysis = await GetAnalysisAsync(code);

            var model = ModuleModel.FromAnalysis(analysis, Services, AnalysisCachingLevel.Library);
            var json  = ToJson(model);

            Baseline.CompareToFile(BaselineFileName, json);
        }
        public async Task NestedClasses()
        {
            const string code  = @"
x = 'str'

class A:
    def methodA(self):
        return True

class B:
    x: int

    class C:
        def __init__(self):
            self.y = 1
        def methodC(self):
            return False
        
    def methodB1(self):
        return self.C()

    def methodB2(self):
        return self.C().y

c = B().methodB1()
";
            var          model = await GetModelAsync(code);

            var json = ToJson(model);

            Baseline.CompareToFile(BaselineFileName, json);
        }
        public async Task MemberLocations()
        {
            const string code     = @"
x = 'str'

def sum(a, b):
    return a + b

class B:
    x: int

    class C:
        def __init__(self):
            pass
        def methodC(self):
            pass

    @property
    def propertyB(self):
        return 1

    def methodB2(self):
        return 2
";
            var          analysis = await GetAnalysisAsync(code);

            var model = ModuleModel.FromAnalysis(analysis, Services, AnalysisCachingLevel.Library);
            var json  = ToJson(model);

            Baseline.CompareToFile(BaselineFileName, json);

            using (var dbModule = new PythonDbModule(model, analysis.Document.FilePath, Services)) {
                dbModule.Construct(model);

                var sum = dbModule.GetMember("sum") as IPythonFunctionType;
                sum.Should().NotBeNull();
                sum.Definition.Span.Should().Be(4, 5, 4, 8);

                var b = dbModule.GetMember("B") as IPythonClassType;
                b.Should().NotBeNull();
                b.Definition.Span.Should().Be(7, 7, 7, 8);

                var c = b.GetMember("C") as IPythonClassType;
                c.Should().NotBeNull();
                c.Definition.Span.Should().Be(10, 11, 10, 12);

                var methodC = c.GetMember("methodC") as IPythonFunctionType;
                methodC.Should().NotBeNull();
                methodC.Definition.Span.Should().Be(13, 13, 13, 20);

                var propertyB = b.GetMember("propertyB") as IPythonPropertyType;
                propertyB.Should().NotBeNull();
                propertyB.Definition.Span.Should().Be(17, 9, 17, 18);

                var methodB2 = b.GetMember("methodB2") as IPythonFunctionType;
                methodB2.Should().NotBeNull();
                methodB2.Definition.Span.Should().Be(20, 9, 20, 17);
            }
        }
        public async Task Builtins()
        {
            var analysis = await GetAnalysisAsync(string.Empty);

            var builtins = analysis.Document.Interpreter.ModuleResolution.BuiltinsModule;
            var model    = ModuleModel.FromAnalysis(builtins.Analysis, Services, AnalysisCachingLevel.Library);

            var json = ToJson(model);

            Baseline.CompareToFile(BaselineFileName, json);

            var dbModule = new PythonDbModule(model, null, Services);

            dbModule.Should().HaveSameMembersAs(builtins);
        }
        public async Task ClassOwnDocumentation()
        {
            const string code  = @"
class A:
    '''class A doc'''

class B(A):
    def __init__(self):
    '''__init__ doc'''
        return
";
            var          model = await GetModelAsync(code);

            var json = ToJson(model);

            // In JSON, class A should have 'class A doc' documentation while B should have none.
            Baseline.CompareToFile(BaselineFileName, json);
        }
Пример #8
0
        public async Task ClassOwnDocumentation()
        {
            const string code     = @"
class A:
    '''class A doc'''

class B(A):
    def __init__(self):
    '''__init__ doc'''
        return
";
            var          analysis = await GetAnalysisAsync(code);

            var model = ModuleModel.FromAnalysis(analysis, Services, AnalysisCachingLevel.Library);
            var json  = ToJson(model);

            // In JSON, class A should have 'class A doc' documentation while B should have none.
            Baseline.CompareToFile(BaselineFileName, json);
        }
        public async Task VersionHandling(bool is3x)
        {
            const string code     = @"
if sys.version_info >= (3, 0):
    def func(a, b, c): ...
else:
    def func(a): ...
";
            var          analysis = await GetAnalysisAsync(code, is3x?PythonVersions.LatestAvailable3X : PythonVersions.LatestAvailable2X);

            analysis.Should().HaveFunction("func")
            .Which.Should().HaveSingleOverload()
            .Which.Should().HaveParameters(is3x ? new[] { "a", "b", "c" } : new[] { "a" });

            var model = ModuleModel.FromAnalysis(analysis, Services, AnalysisCachingLevel.Library);
            var json  = ToJson(model);

            Baseline.CompareToFile(GetBaselineFileNameWithSuffix(is3x ? "3" : "2"), json);
        }