Skip to content

Commit b66c699

Browse files
committed
Add test: get_package_source on .venv in project
1 parent 55169bb commit b66c699

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

ropetest/contrib/autoimport/utilstest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for autoimport utility functions, written in pytest"""
22

3+
import venv
34
from pathlib import Path
45

56
from rope.contrib.autoimport import utils
@@ -22,6 +23,29 @@ def test_get_package_source_pytest(example_external_package_path):
2223
assert source == Source.SITE_PACKAGE
2324

2425

26+
def test_get_package_source_venv_in_project_dir(example_external_package_path, project):
27+
# Many Python dev tools create .venv folders inside the project directory.
28+
# Modules in such folders should count as SITE_PACKAGE files despite
29+
# technically being inside the project folder.
30+
31+
# Set up actual venv in project folder:
32+
project_venv_path = project.root.pathlib/".venv"
33+
venv.create(project_venv_path)
34+
35+
# Crude approximation of a package installed into this venv:
36+
project_venv_site_packages_path = next(project_venv_path.glob("lib/python*/site-packages"))
37+
project.prefs["python_path"].append(project_venv_site_packages_path)
38+
module_path = project_venv_site_packages_path / "foo.py"
39+
module_path.touch()
40+
41+
# Such directories are normally part of `ignored_resources` (e.g. `.venv`
42+
# is in there by default):
43+
project.prefs["ignored_resources"] += [".venv"]
44+
45+
source = utils.get_package_source(module_path, project, "foo")
46+
assert source == Source.SITE_PACKAGE
47+
48+
2549
def test_get_package_source_typing(typing_path):
2650
assert utils.get_package_source(typing_path, None, "typing") == Source.STANDARD
2751

0 commit comments

Comments
 (0)