Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit b5beb30

Browse files
author
MikhailArkhipov
committed
Merge branch 'master' into 84
2 parents cf96b56 + 3327905 commit b5beb30

20 files changed

+441
-683
lines changed

build/Common.Build.Core.settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<BuildOutputRoot Condition="'$(BuildOutputRoot)' == ''">$(BuildRoot)output\</BuildOutputRoot>
6666
<BuildOutputRoot Condition="!HasTrailingSlash($(BuildOutputRoot))">$(BuildOutputRoot)\</BuildOutputRoot>
6767

68-
<OutputPath Condition="'$(OutputPath)' == ''">$(BuildOutputRoot)bin\</OutputPath>
68+
<OutputPath Condition="'$(OutputPath)' == ''">$(BuildOutputRoot)bin\$(Configuration)\</OutputPath>
6969
<OutputPath Condition="!HasTrailingSlash($(OutputPath))">$(OutputPath)\</OutputPath>
7070

7171
<BinariesOutputPath Condition="'$(BinariesOutputPath)' == ''">$(BuildOutputRoot)bin\binaries\</BinariesOutputPath>

src/Analysis/Engine/Test/AnalysisTest.cs

Lines changed: 246 additions & 211 deletions
Large diffs are not rendered by default.

src/Analysis/Engine/Test/AstAnalysisTests.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,13 @@ public async Task AstTypeStubPaths_NoStubs() {
359359
server,
360360
"import Package.Module\n\nc = Package.Module.Class()",
361361
new AnalysisLimits { UseTypeStubPackages = false },
362-
searchPaths: Enumerable.Empty<string>(),
362+
searchPaths: new[] { TestData.GetPath("TestData\\AstAnalysis") },
363363
stubPaths: Enumerable.Empty<string>());
364364

365-
var type = analysis.Should().HavePythonModuleVariable("Package")
366-
.Which.Should().HaveNestedModule("Module")
367-
.Which.Should().HaveClass("Class")
368-
.Which;
365+
analysis.Should().HavePythonModuleVariable("Package");
369366

370367
analysis.Should().HaveVariable("c")
371368
.WithValue<IBuiltinInstanceInfo>()
372-
.Which.Should().HaveMemberType(PythonMemberType.Instance)
373-
.And.HavePythonType(type)
374369
.Which.Should().HaveMembers("untyped_method", "inferred_method")
375370
.And.NotHaveMembers("typed_method", "typed_method_2");
376371
}
@@ -388,9 +383,7 @@ public async Task AstTypeStubPaths_MergeStubs() {
388383
searchPaths: new[] { TestData.GetPath("TestData\\AstAnalysis") },
389384
stubPaths: Enumerable.Empty<string>());
390385

391-
analysis.Should().HavePythonModuleVariable("Package")
392-
.Which.Should().HaveNestedModule("Module")
393-
.Which.Should().HaveMultipleTypesMember("Class");
386+
analysis.Should().HavePythonModuleVariable("Package");
394387

395388
analysis.Should().HaveVariable("c")
396389
.WithValue<IBuiltinInstanceInfo>()
@@ -410,9 +403,7 @@ public async Task AstTypeStubPaths_MergeStubsPath() {
410403
searchPaths: new[] { TestData.GetPath("TestData\\AstAnalysis") },
411404
stubPaths: new[] { TestData.GetPath("TestData\\AstAnalysis\\Stubs") });
412405

413-
analysis.Should().HavePythonModuleVariable("Package")
414-
.Which.Should().HaveNestedModule("Module")
415-
.Which.Should().HaveMultipleTypesMember("Class"); // member information comes from multiple sources
406+
analysis.Should().HavePythonModuleVariable("Package"); // member information comes from multiple sources
416407

417408
analysis.Should().HaveVariable("c")
418409
.WithValue<IBuiltinInstanceInfo>()
@@ -449,16 +440,14 @@ private async Task<IModuleAnalysis> GetStubBasedAnalysis(
449440
AnalysisLimits limits,
450441
IEnumerable<string> searchPaths,
451442
IEnumerable<string> stubPaths) {
452-
var uri = await server.OpenDefaultDocumentAndGetUriAsync(code);
453-
await server.GetAnalysisAsync(uri);
454443

455444
if (limits != null) {
456445
server.Analyzer.Limits = limits;
457446
}
458447
server.Analyzer.SetSearchPaths(searchPaths);
459448
server.Analyzer.SetTypeStubPaths(stubPaths);
460449

461-
server.EnqueueItem(uri);
450+
var uri = await server.OpenDefaultDocumentAndGetUriAsync(code);
462451
return await server.GetAnalysisAsync(uri);
463452
}
464453

src/Analysis/Engine/Test/FluentAssertions/AnalysisValueAssertions.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ public AndConstraint<TAssertions> HaveType(BuiltinTypeId typeId, string because
6363
return new AndConstraint<TAssertions>((TAssertions)this);
6464
}
6565

66+
public AndConstraint<TAssertions> HaveDescription(string description, string because = "", params object[] reasonArgs) {
67+
Execute.Assertion.ForCondition(string.Equals(Subject.Description, description, StringComparison.Ordinal))
68+
.BecauseOf(because, reasonArgs)
69+
.FailWith($"Expected {GetName()} to be {description}{{reason}}, but it is {Subject.Description}.");
70+
71+
return new AndConstraint<TAssertions>((TAssertions)this);
72+
}
73+
6674
public AndConstraint<TAssertions> HaveOnlyMembers(params string[] memberNames)
6775
=> HaveOnlyMembers(memberNames, string.Empty);
6876

@@ -137,7 +145,7 @@ public AndConstraint<TAssertions> HaveMemberType(PythonMemberType memberType, st
137145
}
138146

139147
public AndWhichConstraint<TAssertions, IPythonType> HavePythonType(IPythonType pythonType, string because = "", params object[] reasonArgs) {
140-
Execute.Assertion.ForCondition(Subject.PythonType == pythonType)
148+
Execute.Assertion.ForCondition(Equals(Subject.PythonType, pythonType))
141149
.BecauseOf(because, reasonArgs)
142150
.FailWith(Subject.PythonType != null
143151
? $"Expected {GetName()} to be {GetQuotedName(pythonType)}{{reason}}, but it is {GetQuotedName(Subject.PythonType)}."

src/Analysis/Engine/Test/FluentAssertions/SignatureHelpAssertions.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
1010
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
1111
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12-
// MERCHANTABLITY OR NON-INFRINGEMENT.
12+
// MERCHANTABILITY OR NON-INFRINGEMENT.
1313
//
1414
// See the Apache Version 2.0 License for specific language governing
1515
// permissions and limitations under the License.
1616

17+
using System;
1718
using System.Diagnostics.CodeAnalysis;
1819
using FluentAssertions;
1920
using FluentAssertions.Execution;
@@ -29,6 +30,17 @@ public SignatureHelpAssertions(SignatureHelp subject) {
2930

3031
protected override string Identifier => nameof(SignatureHelp);
3132

33+
public AndWhichConstraint<SignatureHelpAssertions, SignatureInformation> OnlyHaveSignature(string signature, string because = "", params object[] reasonArgs) {
34+
var constraint = HaveSingleSignature();
35+
var actual = constraint.Which.label;
36+
37+
Execute.Assertion.ForCondition(string.Equals(actual, signature, StringComparison.Ordinal))
38+
.BecauseOf(because, reasonArgs)
39+
.FailWith($"Expected SignatureHelp to have single signature '{signature}'{{reason}}, but it has '{actual}'.");
40+
41+
return constraint;
42+
}
43+
3244
public AndWhichConstraint<SignatureHelpAssertions, SignatureInformation> HaveSingleSignature(string because = "", params object[] reasonArgs) {
3345
NotBeNull(because, reasonArgs);
3446

src/Analysis/Engine/Test/FluentAssertions/SignatureInformationAssertions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using FluentAssertions.Execution;
2222
using FluentAssertions.Primitives;
2323
using Microsoft.Python.LanguageServer;
24+
using Microsoft.PythonTools.Analysis.Documentation;
2425

2526
namespace Microsoft.PythonTools.Analysis.FluentAssertions {
2627
[ExcludeFromCodeCoverage]
@@ -59,5 +60,23 @@ public AndConstraint<SignatureInformationAssertions> OnlyHaveParameterLabels(IEn
5960

6061
return new AndConstraint<SignatureInformationAssertions>(this);
6162
}
63+
64+
public AndConstraint<SignatureInformationAssertions> HaveMarkdownDocumentation(string documentation, string because = "", params object[] reasonArgs) {
65+
NotBeNull(because, reasonArgs);
66+
67+
var errorMessage = Subject.documentation == null
68+
? $"Expected signature '{Subject.label}' to have markdown documentation {documentation}{{reason}}, but it has no documentation"
69+
: Subject.documentation.kind != MarkupKind.Markdown
70+
? $"Expected signature '{Subject.label}' to have markdown documentation '{documentation}'{{reason}}, but it has {Subject.documentation.kind} documentation"
71+
: !string.Equals(Subject.documentation.value, documentation)
72+
? $"Expected signature '{Subject.label}' to have markdown documentation '{documentation}'{{reason}}, but it has '{Subject.documentation.value}'"
73+
: null;
74+
75+
Execute.Assertion.ForCondition(errorMessage == null)
76+
.BecauseOf(because, reasonArgs)
77+
.FailWith(errorMessage);
78+
79+
return new AndConstraint<SignatureInformationAssertions>(this);
80+
}
6281
}
6382
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Python Tools for Visual Studio
2+
// Copyright(c) Microsoft Corporation
3+
// All rights reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the License); you may not use
6+
// this file except in compliance with the License. You may obtain a copy of the
7+
// License at http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
10+
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
11+
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12+
// MERCHANTABILITY OR NON-INFRINGEMENT.
13+
//
14+
// See the Apache Version 2.0 License for specific language governing
15+
// permissions and limitations under the License.
16+
17+
using System;
18+
19+
namespace Microsoft.Python.UnitTests.Core.MSTest {
20+
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
21+
public class MatrixColumnAttribute : VectorAttribute {
22+
public MatrixColumnAttribute(object data) : base(data) { }
23+
public MatrixColumnAttribute(object data, params object[] moreData) : base(data, moreData) { }
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Python Tools for Visual Studio
2+
// Copyright(c) Microsoft Corporation
3+
// All rights reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the License); you may not use
6+
// this file except in compliance with the License. You may obtain a copy of the
7+
// License at http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
10+
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
11+
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12+
// MERCHANTABILITY OR NON-INFRINGEMENT.
13+
//
14+
// See the Apache Version 2.0 License for specific language governing
15+
// permissions and limitations under the License.
16+
17+
using System;
18+
19+
namespace Microsoft.Python.UnitTests.Core.MSTest {
20+
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
21+
public class MatrixRowAttribute : VectorAttribute {
22+
public MatrixRowAttribute(object data) : base(data) { }
23+
public MatrixRowAttribute(object data, params object[] moreData) : base(data, moreData) { }
24+
}
25+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Python Tools for Visual Studio
2+
// Copyright(c) Microsoft Corporation
3+
// All rights reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the License); you may not use
6+
// this file except in compliance with the License. You may obtain a copy of the
7+
// License at http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
10+
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
11+
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12+
// MERCHANTABILITY OR NON-INFRINGEMENT.
13+
//
14+
// See the Apache Version 2.0 License for specific language governing
15+
// permissions and limitations under the License.
16+
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Globalization;
20+
using System.Linq;
21+
using System.Reflection;
22+
using Microsoft.VisualStudio.TestTools.UnitTesting;
23+
24+
namespace Microsoft.Python.UnitTests.Core.MSTest {
25+
[AttributeUsage(AttributeTargets.Method)]
26+
public class MatrixTestMethodAttribute : DataTestMethodAttribute, ITestDataSource {
27+
private readonly Dictionary<object[], string> _names = new Dictionary<object[], string>();
28+
29+
public string NameFormat { get; set; }
30+
31+
public MatrixTestMethodAttribute() {
32+
NameFormat = "{0} ({1}) x ({2})";
33+
}
34+
35+
public IEnumerable<object[]> GetData(MethodInfo methodInfo) {
36+
var rows = methodInfo.GetCustomAttributes<MatrixRowAttribute>();
37+
var columns = methodInfo.GetCustomAttributes<MatrixColumnAttribute>().ToArray();
38+
foreach (var row in rows) {
39+
foreach (var column in columns) {
40+
var data = new object[row.Data.Length + column.Data.Length];
41+
Array.Copy(row.Data, 0, data, 0, row.Data.Length);
42+
Array.Copy(column.Data, 0, data, row.Data.Length, column.Data.Length);
43+
44+
var rowName = row.DisplayName ?? string.Join(", ", row.Data);
45+
var columnName = column.DisplayName ?? string.Join(", ", column.Data);
46+
var name = string.Format(CultureInfo.CurrentCulture, NameFormat, methodInfo.Name, rowName, columnName);
47+
_names[data] = name;
48+
49+
yield return data;
50+
}
51+
}
52+
}
53+
54+
public string GetDisplayName(MethodInfo methodInfo, object[] data) {
55+
return _names.TryGetValue(data, out var name) ? name : methodInfo.Name + new Random().Next();
56+
}
57+
}
58+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Python Tools for Visual Studio
2+
// Copyright(c) Microsoft Corporation
3+
// All rights reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the License); you may not use
6+
// this file except in compliance with the License. You may obtain a copy of the
7+
// License at http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
10+
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
11+
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12+
// MERCHANTABILITY OR NON-INFRINGEMENT.
13+
//
14+
// See the Apache Version 2.0 License for specific language governing
15+
// permissions and limitations under the License.
16+
17+
using System;
18+
19+
namespace Microsoft.Python.UnitTests.Core.MSTest {
20+
public class VectorAttribute : Attribute {
21+
public VectorAttribute(object data) {
22+
Data = new[] {data};
23+
}
24+
25+
public VectorAttribute(object data, params object[] moreData) {
26+
if (moreData == null) {
27+
moreData = new object[1];
28+
}
29+
30+
Data = new object[moreData.Length + 1];
31+
Data[0] = data;
32+
Array.Copy(moreData, 0, Data, 1, moreData.Length);
33+
}
34+
35+
public object[] Data { get; }
36+
37+
public string DisplayName { get; set; }
38+
}
39+
}

0 commit comments

Comments
 (0)