diff --git a/rope/refactor/importutils/importinfo.py b/rope/refactor/importutils/importinfo.py index 283513c4..640200c4 100644 --- a/rope/refactor/importutils/importinfo.py +++ b/rope/refactor/importutils/importinfo.py @@ -73,6 +73,9 @@ def get_imported_names(self, context): primary.split(".")[0] for primary in self.get_imported_primaries(context) ] + def __repr__(self): + return f'<{self.__class__.__name__} "{self.get_import_statement()}">' + def get_import_statement(self): pass diff --git a/ropetest/reprtest.py b/ropetest/reprtest.py index 96954846..22abdee7 100644 --- a/ropetest/reprtest.py +++ b/ropetest/reprtest.py @@ -10,6 +10,7 @@ from rope.contrib import findit from rope.contrib.autoimport import models from rope.refactor import occurrences +from rope.refactor.importutils import importinfo from ropetest import testutils @@ -165,3 +166,24 @@ def test_autoimport_models_finalquery(project, mod1): obj = models.Package.delete_by_package_name assert isinstance(obj, models.FinalQuery) assert repr(obj) == expected_repr + + +def test_repr_normal_import(project): + obj = importinfo.NormalImport([("abc", None), ("ghi", "jkl")]) + expected_repr = '' + assert isinstance(obj, importinfo.NormalImport) + assert repr(obj) == expected_repr + + +def test_repr_from_import(project): + obj = importinfo.FromImport("pkg1.pkg2", 0, [("abc", None), ("ghi", "jkl")]) + expected_repr = '' + assert isinstance(obj, importinfo.FromImport) + assert repr(obj) == expected_repr + + +def test_repr_from_import_with_level(project): + obj = importinfo.FromImport("pkg1.pkg2", 3, [("abc", None), ("ghi", "jkl")]) + expected_repr = '' + assert isinstance(obj, importinfo.FromImport) + assert repr(obj) == expected_repr