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

Commit e2948db

Browse files
committed
- Fixed more tests
- Added some assertions - Added MatrixTestMethodAttribute that allows creation of parametrized tests for multiplication of two sets of input parameters - Removed accidently added obj files
1 parent 3ee5aa1 commit e2948db

18 files changed

+435
-665
lines changed

src/Analysis/Engine/Test/AnalysisTest.cs

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

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+
}

src/UnitTests/Core/Impl/UnitTests.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
99
<ItemGroup>
1010
<PackageReference Include="FluentAssertions" Version="5.4.1" />
11+
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
1112
<PackageReference Include="MicroBuild.Core" Version="0.3.0">
1213
<PrivateAssets>all</PrivateAssets>
1314
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>

src/UnitTests/Core/Impl/obj/Debug/netstandard2.0/UnitTests.Core.AssemblyInfo.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)