Skip to content

Commit

Permalink
remove dependencies on build package while running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lieryan committed Feb 6, 2024
1 parent 8539462 commit 3ee79c2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include README.rst COPYING setup.py MANIFEST.in CHANGELOG.md
include README.rst COPYING setup.py MANIFEST.in CHANGELOG.md ropetest-package-fixtures/example-external-package/dist/example_external_package-1.0.0.tar.gz ropetest-package-fixtures/example-external-package/dist/example_external_package-1.0.0-py3-none-any.whl
recursive-include rope *.py
recursive-include docs *.rst
recursive-include ropetest *.py
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ profile = "black"

[tool.pytest.ini_options]

testpaths = "ropetest"
python_files = [
"*test.py",
"__init__.py",
Expand Down
13 changes: 6 additions & 7 deletions ropetest/contrib/autoimport/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@ def typing_path():


@pytest.fixture
def build_env_path():
from build import env

yield pathlib.Path(env.__file__)
def example_external_package_module_path(example_external_package):
from example_external_package import example_module
yield pathlib.Path(example_module.__file__)


@pytest.fixture
def build_path():
import build
def example_external_package_path(example_external_package):
import example_external_package

# Uses __init__.py so we need the parent

yield pathlib.Path(build.__file__).parent
yield pathlib.Path(example_external_package.__file__).parent


@pytest.fixture
Expand Down
17 changes: 12 additions & 5 deletions ropetest/contrib/autoimport/utilstest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ def test_get_package_source_not_project(mod1_path):
assert utils.get_package_source(mod1_path, None, "") == Source.UNKNOWN


def test_get_package_source_pytest(build_path):
def test_get_package_source_pytest(example_external_package_path):
# pytest is not installed as part of the standard library
# but should be installed into site_packages,
# so it should return Source.SITE_PACKAGE
assert utils.get_package_source(build_path, None, "build") == Source.SITE_PACKAGE
source = utils.get_package_source(example_external_package_path, None, "example_module")
assert source == Source.SITE_PACKAGE


def test_get_package_source_typing(typing_path):
Expand All @@ -33,9 +34,15 @@ def test_get_modname_single_file(typing_path):
assert utils.get_modname_from_path(typing_path, typing_path) == "typing"


def test_get_modname_folder(build_path, build_env_path):

assert utils.get_modname_from_path(build_env_path, build_path) == "build.env"
def test_get_modname_folder(
example_external_package_path,
example_external_package_module_path,
):
modname = utils.get_modname_from_path(
example_external_package_module_path,
example_external_package_path,
)
assert modname == "example_external_package.example_module"


def test_get_package_tuple_sample(project_path):
Expand Down
17 changes: 10 additions & 7 deletions ropetest/contrib/autoimporttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ def test_handling_builtin_modules(self):
self.importer.update_module("sys")
self.assertIn("sys", self.importer.get_modules("exit"))

def test_search_submodule(self):
self.importer.update_module("build")
import_statement = ("from build import env", "env")
self.assertIn(import_statement, self.importer.search("env", exact_match=True))
self.assertIn(import_statement, self.importer.search("en"))
self.assertIn(import_statement, self.importer.search("env"))

def test_search_module(self):
self.importer.update_module("os")
import_statement = ("import os", "os")
Expand Down Expand Up @@ -184,6 +177,16 @@ def test_skipping_directories_not_accessible_because_of_permission_error(self):
self.assertGreater(len(self.importer._dump_all()), 0)


def test_search_submodule(example_external_package):
project = testutils.sample_project(extension_modules=["sys"])
importer = autoimport.AutoImport(project, observe=False)
importer.update_module("example_external_package")
import_statement = ("from example_external_package import example_module", "example_module")
assert import_statement in importer.search("example_module", exact_match=True)
assert import_statement in importer.search("exam")
assert import_statement in importer.search("example_module")


class AutoImportObservingTest(unittest.TestCase):
def setUp(self):
super().setUp()
Expand Down

0 comments on commit 3ee79c2

Please sign in to comment.