Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
333 changes: 1 addition & 332 deletions src/Analysis/Engine/Test/AnalysisTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

namespace AnalysisTests {
[TestClass]
public partial class AnalysisTest {
public class AnalysisTest {
public TestContext TestContext { get; set; }

[TestInitialize]
Expand Down Expand Up @@ -864,102 +864,6 @@ import mod2
}
*/

[TestMethod, Priority(0)]
public async Task PrivateMembers() {
using (var server = await CreateServerAsync(PythonVersions.LatestAvailable2X)) {
var uri = TestData.GetTempPathUri("test-module.py");

string code = @"
class C:
def __init__(self):
self._C__X = 'abc' # Completions here should only ever show __X
self.__X = 42

class D(C):
def __init__(self):
print(self.__X) # self. here shouldn't have __X or _C__X (could be controlled by Text Editor->Python->general->Hide advanced members to show _C__X)
";

await server.SendDidOpenTextDocument(uri, code);
await server.GetAnalysisAsync(uri);

var completions = await server.SendCompletion(uri, 4, 13);
completions.Should().OnlyHaveLabels("__X", "__init__", "__doc__", "__class__");

completions = await server.SendCompletion(uri, 8, 19);
completions.Should().OnlyHaveLabels("_C__X", "__init__", "__doc__", "__class__");

code = @"
class C(object):
def __init__(self):
self.f(_C__A = 42) # sig help should be _C__A

def f(self, __A):
pass


class D(C):
def __init__(self):
self.f(_C__A=42) # sig help should be _C__A
";

await server.SendDidChangeTextDocumentAsync(uri, code);
await server.GetAnalysisAsync(uri);

var signatures = await server.SendSignatureHelp(uri, 3, 15);
signatures.Should().HaveSingleSignature()
.Which.Should().OnlyHaveParameterLabels("_C__A");

signatures = await server.SendSignatureHelp(uri, 11, 15);
signatures.Should().HaveSingleSignature()
.Which.Should().OnlyHaveParameterLabels("_C__A");

code = @"
class C(object):
def __init__(self):
self.__f(_C__A = 42) # member should be __f

def __f(self, __A):
pass


class D(C):
def __init__(self):
self._C__f(_C__A=42) # member should be _C__f

";

await server.SendDidChangeTextDocumentAsync(uri, code);
await server.GetAnalysisAsync(uri);

completions = await server.SendCompletion(uri, 3, 13);
completions.Should().HaveLabels("__f", "__init__");

completions = await server.SendCompletion(uri, 11, 13);
completions.Should().HaveLabels("_C__f", "__init__");

code = @"
class C(object):
__FOB = 42

def f(self):
abc = C.__FOB # Completion should work here


xyz = C._C__FOB # Advanced members completion should work here
";

await server.SendDidChangeTextDocumentAsync(uri, code);
await server.GetAnalysisAsync(uri);

completions = await server.SendCompletion(uri, 5, 16);
completions.Should().HaveLabels("__FOB", "f");

completions = await server.SendCompletion(uri, 8, 8);
completions.Should().HaveLabels("_C__FOB", "f");
}
}

[TestMethod, Priority(0)]
public async Task BaseInstanceVariable() {
var code = @"
Expand Down Expand Up @@ -3975,28 +3879,6 @@ def f(x = x):
}
}

[TestMethod, Priority(0)]
public async Task RecursiveClass() {
var code = @"
cls = object

class cls(cls):
abc = 42

a = cls().abc
b = cls.abc
";
using (var server = await CreateServerAsync()) {
var analysis = await server.OpenDefaultDocumentAndGetAnalysisAsync(code);
var completion = await server.SendCompletion(TestData.GetDefaultModuleUri(), 8, 0);

analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int)
.And.HaveVariable("b").OfType(BuiltinTypeId.Int);

completion.Should().HaveLabels("cls", "object");
}
}

[TestMethod, Priority(0)]
public async Task BadMethod() {
var code = @"
Expand Down Expand Up @@ -4134,43 +4016,6 @@ public async Task KeywordSplat(string functionDeclaration, int signatureLine, st
}
}

[TestMethod, Priority(0)]
public async Task ForwardRef() {
var code = @"

class D(object):
def oar(self, x):
abc = C()
abc.fob(2)
a = abc.fob(2.0)
a.oar(('a', 'b', 'c', 'd'))

class C(object):
def fob(self, x):
D().oar('abc')
D().oar(['a', 'b', 'c'])
return D()
def baz(self): pass
";
using (var server = await CreateServerAsync(PythonVersions.LatestAvailable2X)) {
var analysis = await server.OpenDefaultDocumentAndGetAnalysisAsync(code);
var completionInD = await server.SendCompletion(TestData.GetDefaultModuleUri(), 3, 4);
var completionInOar = await server.SendCompletion(TestData.GetDefaultModuleUri(), 5, 8);
var completionForAbc = await server.SendCompletion(TestData.GetDefaultModuleUri(), 5, 12);

completionInD.Should().HaveLabels("C", "D", "oar")
.And.NotContainLabels("a", "abc", "self", "x", "fob", "baz");

completionInOar.Should().HaveLabels("C", "D", "a", "oar", "abc", "self", "x")
.And.NotContainLabels("fob", "baz");

completionForAbc.Should().HaveLabels("baz", "fob");

analysis.Should().HaveClass("D").WithFunction("oar")
.Which.Should().HaveParameter("x").OfTypes(BuiltinTypeId.List, BuiltinTypeId.Str, BuiltinTypeId.Tuple);
}
}


[TestMethod, Priority(0)]
public async Task Builtins() {
Expand Down Expand Up @@ -4277,28 +4122,6 @@ def g(a, b):
}
}

[TestMethod, Priority(0)]
public async Task SimpleGlobals() {
var code = @"
class x(object):
def abc(self):
pass

a = x()
x.abc()
";
using (var server = await CreateServerAsync()) {
var objectMemberNames = server.GetBuiltinTypeMemberNames(BuiltinTypeId.Object);

var uri = await server.OpenDefaultDocumentAndGetUriAsync(code);
var completion = await server.SendCompletion(uri, 6, 0);
var completionX = await server.SendCompletion(uri, 6, 2);

completion.Should().HaveLabels("a", "x").And.NotContainLabels("abc", "self");
completionX.Should().HaveLabels(objectMemberNames).And.HaveLabels("abc");
}
}

[TestMethod, Priority(0)]
public async Task FuncCallInIf() {
var code = @"
Expand Down Expand Up @@ -4403,67 +4226,6 @@ def f(a, b, c=0):
}
}

/// <summary>
/// http://pytools.codeplex.com/workitem/799
/// </summary>
[TestMethod, Priority(0)]
public async Task OverrideCompletions2X() {
var code = @"
class oar(list):
def
pass
";
using (var server = await CreateServerAsync(PythonVersions.LatestAvailable2X)) {
var uri = await server.OpenDefaultDocumentAndGetUriAsync(code);
var completions = await server.SendCompletion(uri, 2, 8);

completions.Should().HaveItem("append")
.Which.Should().HaveInsertText("append(self, value):\r\n return super(oar, self).append(value)");
}
}

[DataRow(PythonLanguageVersion.V36, "value")]
[DataRow(PythonLanguageVersion.V37, "object")]
[DataTestMethod, Priority(0)]
public async Task OverrideCompletions3X(PythonLanguageVersion version, string parameterName) {
var code = @"
class oar(list):
def
pass
";
using (var server = await CreateServerAsync(PythonVersions.GetRequiredCPythonConfiguration(version))) {
var uri = await server.OpenDefaultDocumentAndGetUriAsync(code);
var completions = await server.SendCompletion(uri, 2, 8);

completions.Should().HaveItem("append")
.Which.Should().HaveInsertText($"append(self, {parameterName}):\r\n return super().append({parameterName})");
}
}

[TestMethod, Priority(0)]
public async Task OverrideCompletionsNested() {
// Ensure that nested classes are correctly resolved.
var code = @"
class oar(int):
class fob(dict):
def
pass
def
pass
";

using (var server = await CreateServerAsync(PythonVersions.LatestAvailable2X)) {
var uri = await server.OpenDefaultDocumentAndGetUriAsync(code);
var completionsOar = await server.SendCompletion(uri, 5, 8);
var completionsFob = await server.SendCompletion(uri, 3, 12);

completionsOar.Should().NotContainLabels("keys", "items")
.And.HaveItem("bit_length");
completionsFob.Should().NotContainLabels("bit_length")
.And.HaveLabels("keys", "items");
}
}

/// <summary>
/// https://github.com/Microsoft/PTVS/issues/995
/// </summary>
Expand Down Expand Up @@ -6618,32 +6380,6 @@ def with_params_default_starargs(*args, **kwargs):
.And.HaveVariable("rf").WithDescription("method return_func of module.return_func_class objects...")
.WithDocumentation("some help");
}


}

[TestMethod, Priority(0)]
public async Task CompletionDocumentation() {
var text = @"
import sys
z = 43

class fob(object):
@property
def f(self): pass

def g(self): pass

d = fob()
";
using (var server = await CreateServerAsync()) {
var uri = await server.OpenDefaultDocumentAndGetUriAsync(text);
var completionD = await server.SendCompletion(uri, 15, 1);
completionD.Should().HaveItem("d")
.Which.Should().HaveDocumentation("fob");
completionD.Should().HaveItem("z")
.Which.Should().HaveDocumentation("int");
}
}

[TestMethod, Priority(0)]
Expand Down Expand Up @@ -6848,73 +6584,6 @@ print abc
}
}

[TestMethod, Priority(0)]
public async Task TypeAtEndOfMethod() {
var text = @"
class Fob(object):
def oar(self, a):
pass


def fob(self):
pass

x = Fob()
x.oar(100)
";

using (var server = await CreateServerAsync()) {
var uri = await server.OpenDefaultDocumentAndGetUriAsync(text);
var completion = await server.SendCompletion(uri, 5, 8);
completion.Should().HaveItem("a")
.Which.Should().HaveDocumentation("int");
}
}

[TestMethod, Priority(0)]
public async Task TypeAtEndOfIncompleteMethod() {
var text = @"
class Fob(object):
def oar(self, a):





x = Fob()
x.oar(100)
";

using (var server = await CreateServerAsync()) {
var uri = await server.OpenDefaultDocumentAndGetUriAsync(text);
var completion = await server.SendCompletion(uri, 5, 8);
completion.Should().HaveItem("a")
.Which.Should().HaveDocumentation("int");
}
}

[TestMethod, Priority(0)]
public async Task TypeIntersectionUserDefinedTypes() {
var text = @"
class C1(object):
def fob(self): pass

class C2(object):
def oar(self): pass

c = C1()
c.fob()
c = C2()
c.
";

using (var server = await CreateServerAsync()) {
var uri = await server.OpenDefaultDocumentAndGetUriAsync(text);
var completion = await server.SendCompletion(uri, 10, 2);
completion.Should().NotContainLabels("fob", "oar");
}
}

[TestMethod, Priority(0)]
public async Task UpdateMethodMultiFiles() {
var text1 = @"
Expand Down
Loading