From 7a0234215af97ccd127db4f3c795bdb364b9cfbd Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Tue, 12 Nov 2024 10:48:34 -0800 Subject: [PATCH] test: python context --- .../test/RootPathContextService.test.ts | 32 ++++++++++++++----- .../root-path-context/test/files/file1.py | 12 +++---- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts index 8d97dc9ca..196a7b643 100644 --- a/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts +++ b/core/autocomplete/context/root-path-context/test/RootPathContextService.test.ts @@ -6,7 +6,7 @@ const TEST_CASES = [ fileName: "file1.ts", language: "TypeScript", cursorPosition: { line: 10, character: 24 }, - positions: [ + definitionPositions: [ { row: 9, column: 34 }, // Person { row: 9, column: 44 }, // Address ], @@ -16,7 +16,7 @@ const TEST_CASES = [ fileName: "file1.ts", language: "TypeScript", cursorPosition: { line: 22, character: 30 }, - positions: [ + definitionPositions: [ { row: 13, column: 29 }, // BaseClass { row: 13, column: 55 }, // FirstInterface { row: 13, column: 72 }, // SecondInterface @@ -28,11 +28,22 @@ const TEST_CASES = [ nodeType: "function_definition", fileName: "file1.py", language: "Python", + cursorPosition: { line: 4, character: 25 }, + definitionPositions: [ + { row: 3, column: 30 }, // Person + { row: 3, column: 42 }, // Address + ], + }, + { + nodeType: "function_definition (inside a class)", + fileName: "file1.py", + language: "Python", cursorPosition: { line: 12, character: 33 }, - positions: [ - { row: 6, column: 21 }, - { row: 6, column: 37 }, - { row: 6, column: 54 }, + definitionPositions: [ + { row: 6, column: 21 }, // BaseClass + { row: 6, column: 33 }, // Collection + { row: 11, column: 47 }, // Person + { row: 11, column: 59 }, // Address ], }, ]; @@ -40,8 +51,13 @@ const TEST_CASES = [ describe("RootPathContextService", () => { test.each(TEST_CASES)( "Should look for correct type definitions when editing inside a $nodeType in $language", - async ({ fileName, cursorPosition, positions }) => { - await testRootPathContext("files", fileName, cursorPosition, positions); + async ({ fileName, cursorPosition, definitionPositions }) => { + await testRootPathContext( + "files", + fileName, + cursorPosition, + definitionPositions, + ); }, ); }); diff --git a/core/autocomplete/context/root-path-context/test/files/file1.py b/core/autocomplete/context/root-path-context/test/files/file1.py index 81e991800..1659977f5 100644 --- a/core/autocomplete/context/root-path-context/test/files/file1.py +++ b/core/autocomplete/context/root-path-context/test/files/file1.py @@ -1,13 +1,13 @@ -from base_module import BaseClass -from interfaces_module import FirstInterface, SecondInterface +from base_module import BaseClass, Collection, Person, Address +from typing import List -def get_address(person): +def get_address(person: Person) -> Address: return person.address -class Group(BaseClass, FirstInterface, SecondInterface): - def __init__(self, people): +class Group(BaseClass, Collection): + def __init__(self, people: List[Person]) -> None: super().__init__() self.people = people - def get_person_address(self, person): + def get_person_address(self, person: Person) -> Address: return get_address(person)