|
13 | 13 | // See the Apache Version 2.0 License for specific language governing |
14 | 14 | // permissions and limitations under the License. |
15 | 15 |
|
| 16 | +using System.IO; |
16 | 17 | using System.Threading.Tasks; |
17 | 18 | using FluentAssertions; |
| 19 | +using Microsoft.Python.Analysis.Analyzer; |
| 20 | +using Microsoft.Python.Analysis.Documents; |
18 | 21 | using Microsoft.Python.Core.Text; |
19 | 22 | using Microsoft.Python.LanguageServer.Sources; |
20 | 23 | using Microsoft.Python.Parsing.Tests; |
@@ -52,6 +55,61 @@ def method(self, a:int, b) -> float: |
52 | 55 | sig.signatures[0].label.Should().Be("method(a: int, b) -> float"); |
53 | 56 | } |
54 | 57 |
|
| 58 | + [TestMethod, Priority(0)] |
| 59 | + public async Task ClassInitializer() { |
| 60 | + const string code = @" |
| 61 | +class C: |
| 62 | + def __init__(self, a:int, b): |
| 63 | + pass |
| 64 | +
|
| 65 | +C() |
| 66 | +"; |
| 67 | + var analysis = await GetAnalysisAsync(code); |
| 68 | + var src = new SignatureSource(new PlainTextDocumentationSource()); |
| 69 | + |
| 70 | + var sig = src.GetSignature(analysis, new SourceLocation(6, 3)); |
| 71 | + sig.activeSignature.Should().Be(0); |
| 72 | + sig.activeParameter.Should().Be(0); |
| 73 | + sig.signatures.Length.Should().Be(1); |
| 74 | + sig.signatures[0].label.Should().Be("C(a: int, b)"); |
| 75 | + } |
| 76 | + |
| 77 | + [TestMethod, Priority(0)] |
| 78 | + public async Task ImportedClassInitializer() { |
| 79 | + const string module1Code = @" |
| 80 | +class C: |
| 81 | + def __init__(self, a:int, b): |
| 82 | + pass |
| 83 | +"; |
| 84 | + |
| 85 | + const string appCode = @" |
| 86 | +import module1 |
| 87 | +
|
| 88 | +module1.C() |
| 89 | +"; |
| 90 | + var module1Uri = TestData.GetTestSpecificUri("module1.py"); |
| 91 | + var appUri = TestData.GetTestSpecificUri("app.py"); |
| 92 | + |
| 93 | + var root = Path.GetDirectoryName(appUri.AbsolutePath); |
| 94 | + await CreateServicesAsync(root, PythonVersions.LatestAvailable3X); |
| 95 | + var rdt = Services.GetService<IRunningDocumentTable>(); |
| 96 | + var analyzer = Services.GetService<IPythonAnalyzer>(); |
| 97 | + |
| 98 | + rdt.OpenDocument(module1Uri, module1Code); |
| 99 | + |
| 100 | + var app = rdt.OpenDocument(appUri, appCode); |
| 101 | + await analyzer.WaitForCompleteAnalysisAsync(); |
| 102 | + var analysis = await app.GetAnalysisAsync(-1); |
| 103 | + |
| 104 | + var src = new SignatureSource(new PlainTextDocumentationSource()); |
| 105 | + |
| 106 | + var sig = src.GetSignature(analysis, new SourceLocation(4, 11)); |
| 107 | + sig.activeSignature.Should().Be(0); |
| 108 | + sig.activeParameter.Should().Be(0); |
| 109 | + sig.signatures.Length.Should().Be(1); |
| 110 | + sig.signatures[0].label.Should().Be("C(a: int, b)"); |
| 111 | + } |
| 112 | + |
55 | 113 | [TestMethod, Priority(0)] |
56 | 114 | public async Task GenericClassMethod() { |
57 | 115 | const string code = @" |
|
0 commit comments