Use clearly defined project for tests to avoid scanning the 2000 typeshed files all the time

This commit is contained in:
Dave Halter
2021-01-02 15:31:48 +01:00
parent ca2c732d66
commit c5fb2985a3
2 changed files with 11 additions and 5 deletions

View File

@@ -23,11 +23,9 @@ def builtin_test():
import sqlite3 import sqlite3
# classes is a local module that has an __init__.py and can therefore not be # classes is a local module that has an __init__.py and can therefore not be
# found. test can be found. # found.
#? [] #? []
import classes import classes
#? ['test']
import test
#? ['timedelta'] #? ['timedelta']
from datetime import timedel from datetime import timedel

View File

@@ -108,6 +108,7 @@ from ast import literal_eval
from io import StringIO from io import StringIO
from functools import reduce from functools import reduce
from unittest.mock import ANY from unittest.mock import ANY
from pathlib import Path
import parso import parso
from _pytest.outcomes import Skipped from _pytest.outcomes import Skipped
@@ -122,6 +123,7 @@ from jedi.api.environment import get_default_environment, get_system_environment
from jedi.inference.gradual.conversion import convert_values from jedi.inference.gradual.conversion import convert_values
from jedi.inference.analysis import Warning from jedi.inference.analysis import Warning
test_dir = Path(__file__).absolute().parent
TEST_COMPLETIONS = 0 TEST_COMPLETIONS = 0
TEST_INFERENCE = 1 TEST_INFERENCE = 1
@@ -173,6 +175,7 @@ class IntegrationTestCase(BaseTestCase):
self.start = start self.start = start
self.line = line self.line = line
self.path = path self.path = path
self._project = jedi.Project(test_dir)
@property @property
def module_name(self): def module_name(self):
@@ -188,7 +191,12 @@ class IntegrationTestCase(BaseTestCase):
self.line_nr_test, self.line.rstrip()) self.line_nr_test, self.line.rstrip())
def script(self, environment): def script(self, environment):
return jedi.Script(self.source, path=self.path, environment=environment) return jedi.Script(
self.source,
path=self.path,
environment=environment,
project=self._project
)
def run(self, compare_cb, environment=None): def run(self, compare_cb, environment=None):
testers = { testers = {
@@ -263,7 +271,7 @@ class IntegrationTestCase(BaseTestCase):
self.correct = self.correct.strip() self.correct = self.correct.strip()
compare = sorted( compare = sorted(
(('stub:' if r.is_stub() else '') (('stub:' if r.is_stub() else '')
+ re.sub(r'^test\.completion\.', '', r.module_name), + re.sub(r'^completion\.', '', r.module_name),
r.line, r.line,
r.column) r.column)
for r in result for r in result