From 980441794c8b5e49f85ba088de157884283a91a3 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Fri, 13 May 2016 10:14:08 -0400 Subject: [PATCH 1/9] Add is_site_packages(), refactoring to DRY --- importanize/utils.py | 23 +++++++++++++++++------ tests/test_utils.py | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/importanize/utils.py b/importanize/utils.py index 62978fd..1591e6d 100644 --- a/importanize/utils.py +++ b/importanize/utils.py @@ -8,7 +8,7 @@ @contextmanager -def ignore_site_packages_paths(): +def site_packages_paths(filter_func): paths = sys.path[:] # remove working directory so that all # local imports fail @@ -18,22 +18,21 @@ def ignore_site_packages_paths(): # so that only stdlib imports will succeed sys.path = list(set(filter( None, - filter(lambda i: all(('site-packages' not in i, - 'python' in i or 'pypy' in i)), + filter(lambda i: all((filter_func(i), 'python' in i or 'pypy' in i)), map(operator.methodcaller('lower'), sys.path)) ))) yield sys.path = paths -def is_std_lib(module): +def _is_installed_module(module, filter_func, builtin_result): if not module: return False if module in sys.builtin_module_names: - return True + return builtin_result - with ignore_site_packages_paths(): + with site_packages_paths(filter_func): imported_module = sys.modules.pop(module, None) try: import_module(module) @@ -45,6 +44,18 @@ def is_std_lib(module): if imported_module: sys.modules[module] = imported_module +def is_std_lib(module): + return _is_installed_module( + module, + lambda i: "site-packages" not in i, + True) + +def is_site_packages(module): + return _is_installed_module( + module, + lambda i: "site-packages" in i, + False) + def list_strip(data): """ diff --git a/tests/test_utils.py b/tests/test_utils.py index 3caef12..8d90da6 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -7,19 +7,20 @@ import mock from importanize.utils import ( - ignore_site_packages_paths, + site_packages_paths, is_std_lib, + is_site_packages, list_strip, read, ) class TestUtils(unittest.TestCase): - def test_ignore_site_packages_paths(self): + def test_site_packages_paths(self): sys.path.append(os.getcwd()) paths = sys.path[:] - with ignore_site_packages_paths(): + with site_packages_paths(lambda i: "site-packages" not in i): self.assertNotEqual(sys.path, paths) self.assertLess(len(sys.path), len(paths)) @@ -94,6 +95,35 @@ def test_list_strip(self): ['hello', 'world'] ) + def test_is_site_packages(self): + self.assertFalse(is_site_packages('')) + + stdlib_modules = ( + 'argparse', + 'codecs', + ) + for module in stdlib_modules: + msg = '{} should not be sitepackages' + self.assertFalse(is_site_packages(module), + msg.format(module)) + + self.assertFalse(is_site_packages('foo')) + + site_packages_modules = (module_name + for module_name in sys.modules + if "site-packages" in module_name + ) + for module in site_packages_modules: + msg = '{} should be sitepackages' + self.assertFalse(is_site_packages(module), + msg.format(module)) + + def test_list_strip(self): + self.assertListEqual( + list_strip([' hello ', 'world']), + ['hello', 'world'] + ) + @mock.patch('importanize.utils.open', create=True) def test_read(self, mock_open): actual = read(mock.sentinel.path) From fa2043d476af0c2368665d2c580f946197e58454 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Fri, 13 May 2016 10:14:24 -0400 Subject: [PATCH 2/9] Add SitePackagesGroup --- importanize/groups.py | 7 ++++++- tests/test_groups.py | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/importanize/groups.py b/importanize/groups.py index 317cbcb..385b26b 100644 --- a/importanize/groups.py +++ b/importanize/groups.py @@ -8,7 +8,7 @@ import six from .formatters import DEFAULT_FORMATTER -from .utils import is_std_lib +from .utils import is_std_lib, is_site_packages @six.python_2_unicode_compatible @@ -93,6 +93,10 @@ class StdLibGroup(BaseImportGroup): def should_add_statement(self, statement): return is_std_lib(statement.root_module) +class SitePackagesGroup(BaseImportGroup): + def should_add_statement(self, statement): + return is_site_packages(statement.root_module) + class PackagesGroup(BaseImportGroup): def __init__(self, *args, **kwargs): @@ -119,6 +123,7 @@ def should_add_statement(self, statement): GROUP_MAPPING = OrderedDict(( ('stdlib', StdLibGroup), + ('sitepackages', SitePackagesGroup), ('packages', PackagesGroup), ('local', LocalGroup), ('remainder', RemainderGroup), diff --git a/tests/test_groups.py b/tests/test_groups.py index 63701bc..23d0032 100644 --- a/tests/test_groups.py +++ b/tests/test_groups.py @@ -12,6 +12,7 @@ PackagesGroup, RemainderGroup, StdLibGroup, + SitePackagesGroup, ) from importanize.statements import ImportLeaf, ImportStatement @@ -184,6 +185,14 @@ def test_str(self, mock_as_string): mock_as_string.assert_called_once_with() +class TestSitePackagesGroup(unittest.TestCase): + @mock.patch('importanize.groups.is_site_packages') + def test_should_add_statement(self, mock_is_std_lib): + statement = mock.MagicMock() + actual = SitePackagesGroup().should_add_statement(statement) + self.assertEqual(actual, mock_is_std_lib.return_value) + mock_is_std_lib.assert_called_once_with(statement.root_module) + class TestStdLibGroup(unittest.TestCase): @mock.patch('importanize.groups.is_std_lib') def test_should_add_statement(self, mock_is_std_lib): From 0571393c02190fc74a7e9dfe0346e4dc570db604 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Fri, 13 May 2016 11:07:58 -0400 Subject: [PATCH 3/9] Update Docs --- AUTHORS.rst | 1 + README.rst | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index 849496d..2ee2c81 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -10,3 +10,4 @@ Contributors ~~~~~~~~~~~~ Benjamin Abel - https://github.com/benjaminabel +Pamela McA'Nulty - https://github.com/PamelaM diff --git a/README.rst b/README.rst index 2fb4525..cf8789d 100644 --- a/README.rst +++ b/README.rst @@ -73,6 +73,9 @@ Config file is simply a ``json`` file like this:: { "type": "stdlib" }, + { + "type": "sitepackages" + }, { "type": "remainder" }, @@ -110,6 +113,7 @@ to organize imports and will output import groups in the same order as defined in the config file. These are the supported group types: * ``stdlib`` - standard library imports including ``__future__`` +* ``sitepackages`` - imports coming from the ``site-packages`` directory * ``local`` - local imports which start with ``"."``. for example ``from .foo import bar`` * ``packages`` - if this group is specified, additional key ``packages`` From 51529a82294fb290d181d1c8515b644ce69e13f1 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Fri, 13 May 2016 11:27:29 -0400 Subject: [PATCH 4/9] lint remediations --- importanize/groups.py | 1 + tests/test_groups.py | 1 + 2 files changed, 2 insertions(+) diff --git a/importanize/groups.py b/importanize/groups.py index 385b26b..3cfa0eb 100644 --- a/importanize/groups.py +++ b/importanize/groups.py @@ -93,6 +93,7 @@ class StdLibGroup(BaseImportGroup): def should_add_statement(self, statement): return is_std_lib(statement.root_module) + class SitePackagesGroup(BaseImportGroup): def should_add_statement(self, statement): return is_site_packages(statement.root_module) diff --git a/tests/test_groups.py b/tests/test_groups.py index 23d0032..8d95ac5 100644 --- a/tests/test_groups.py +++ b/tests/test_groups.py @@ -193,6 +193,7 @@ def test_should_add_statement(self, mock_is_std_lib): self.assertEqual(actual, mock_is_std_lib.return_value) mock_is_std_lib.assert_called_once_with(statement.root_module) + class TestStdLibGroup(unittest.TestCase): @mock.patch('importanize.groups.is_std_lib') def test_should_add_statement(self, mock_is_std_lib): From 73195d70f875ccd517cf78197f5f11ac1dcadd8c Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Fri, 13 May 2016 11:28:01 -0400 Subject: [PATCH 5/9] lint remedations and add try/finally in utils.site_packages_paths --- importanize/utils.py | 46 +++++++++++++++++++++------------------ tests/test_utils.py | 51 ++++++++++++++++++++++++++++++++------------ 2 files changed, 62 insertions(+), 35 deletions(-) diff --git a/importanize/utils.py b/importanize/utils.py index 1591e6d..d42947a 100644 --- a/importanize/utils.py +++ b/importanize/utils.py @@ -10,39 +10,42 @@ @contextmanager def site_packages_paths(filter_func): paths = sys.path[:] - # remove working directory so that all - # local imports fail - if os.getcwd() in sys.path: - sys.path.remove(os.getcwd()) - # remove all third-party paths - # so that only stdlib imports will succeed - sys.path = list(set(filter( - None, - filter(lambda i: all((filter_func(i), 'python' in i or 'pypy' in i)), - map(operator.methodcaller('lower'), sys.path)) - ))) - yield - sys.path = paths - - -def _is_installed_module(module, filter_func, builtin_result): - if not module: + try: + # remove working directory so that all + # local imports fail + if os.getcwd() in sys.path: + sys.path.remove(os.getcwd()) + # remove all third-party paths + # so that only stdlib imports will succeed + sys.path = list(set(filter( + None, + filter(lambda i: all((filter_func(i), 'python' in i or 'pypy' in i)), + map(operator.methodcaller('lower'), sys.path)) + ))) + yield + finally: + sys.path = paths + + +def _is_installed_module(module_name, filter_func, builtin_result): + if not module_name: return False - if module in sys.builtin_module_names: + if module_name in sys.builtin_module_names: return builtin_result with site_packages_paths(filter_func): - imported_module = sys.modules.pop(module, None) + imported_module = sys.modules.pop(module_name, None) try: - import_module(module) + import_module(module_name) except ImportError: return False else: return True finally: if imported_module: - sys.modules[module] = imported_module + sys.modules[module_name] = imported_module + def is_std_lib(module): return _is_installed_module( @@ -50,6 +53,7 @@ def is_std_lib(module): lambda i: "site-packages" not in i, True) + def is_site_packages(module): return _is_installed_module( module, diff --git a/tests/test_utils.py b/tests/test_utils.py index 8d90da6..6d641f5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -28,6 +28,24 @@ def test_site_packages_paths(self): self.assertListEqual(sys.path, paths) sys.path.remove(os.getcwd()) + def test_site_packages_paths_exception(self): + sys.path.append(os.getcwd()) + paths = sys.path[:] + + try: + with site_packages_paths(lambda i: "site-packages" not in i): + self.assertNotEqual(sys.path, paths) + self.assertLess(len(sys.path), len(paths)) + raise ValueError("TEST EXCEPTION") + + except ValueError as e: + if "TEST EXCEPTION" not in str(e): + raise + + self.assertIn(os.getcwd(), sys.path) + self.assertListEqual(sys.path, paths) + sys.path.remove(os.getcwd()) + def test_is_std_lib(self): self.assertFalse(is_std_lib('')) @@ -89,12 +107,6 @@ def test_is_std_lib(self): self.assertFalse(is_std_lib('foo')) - def test_list_strip(self): - self.assertListEqual( - list_strip([' hello ', 'world']), - ['hello', 'world'] - ) - def test_is_site_packages(self): self.assertFalse(is_site_packages('')) @@ -105,18 +117,29 @@ def test_is_site_packages(self): for module in stdlib_modules: msg = '{} should not be sitepackages' self.assertFalse(is_site_packages(module), - msg.format(module)) + msg.format(module)) self.assertFalse(is_site_packages('foo')) - site_packages_modules = (module_name - for module_name in sys.modules - if "site-packages" in module_name - ) + def _is_site_package(name, module): + if name in ("pkg_resources",): + return False + return "site-packages" in getattr(module, "__file__", "") + + site_packages_modules = [ + name + for name, module in sys.modules.items() + if _is_site_package(name, module) + ] + self.assertNotEqual(site_packages_modules, []) for module in site_packages_modules: - msg = '{} should be sitepackages' - self.assertFalse(is_site_packages(module), - msg.format(module)) + try: + msg = '{} should be sitepackages' + self.assertTrue(is_site_packages(module), + msg.format(module)) + except Exception: + print("Module Name: {}".format(module)) + raise def test_list_strip(self): self.assertListEqual( From 7005f92cddb8a8f1fc2d8b251abef20689b265c9 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Fri, 13 May 2016 18:22:59 -0400 Subject: [PATCH 6/9] Refactored to actually, you know, work --- importanize/groups.py | 4 +-- importanize/utils.py | 51 ++++++++++++++---------------- tests/test_groups.py | 2 +- tests/test_utils.py | 73 +++++++++++++++++++------------------------ 4 files changed, 60 insertions(+), 70 deletions(-) diff --git a/importanize/groups.py b/importanize/groups.py index 3cfa0eb..1a7dc9d 100644 --- a/importanize/groups.py +++ b/importanize/groups.py @@ -8,7 +8,7 @@ import six from .formatters import DEFAULT_FORMATTER -from .utils import is_std_lib, is_site_packages +from .utils import is_std_lib, is_site_package @six.python_2_unicode_compatible @@ -96,7 +96,7 @@ def should_add_statement(self, statement): class SitePackagesGroup(BaseImportGroup): def should_add_statement(self, statement): - return is_site_packages(statement.root_module) + return is_site_package(statement.root_module) class PackagesGroup(BaseImportGroup): diff --git a/importanize/utils.py b/importanize/utils.py index d42947a..2006be9 100644 --- a/importanize/utils.py +++ b/importanize/utils.py @@ -8,7 +8,7 @@ @contextmanager -def site_packages_paths(filter_func): +def ignore_site_packages_paths(): paths = sys.path[:] try: # remove working directory so that all @@ -19,46 +19,43 @@ def site_packages_paths(filter_func): # so that only stdlib imports will succeed sys.path = list(set(filter( None, - filter(lambda i: all((filter_func(i), 'python' in i or 'pypy' in i)), + filter(lambda i: all(('site-packages' not in i, + 'python' in i or 'pypy' in i)), map(operator.methodcaller('lower'), sys.path)) ))) yield finally: sys.path = paths +def _safe_import_module(module_name): + imported_module = sys.modules.pop(module_name, None) + try: + return import_module(module_name) + except ImportError: + return None + finally: + if imported_module: + sys.modules[module_name] = imported_module -def _is_installed_module(module_name, filter_func, builtin_result): +def is_std_lib(module_name): if not module_name: return False if module_name in sys.builtin_module_names: - return builtin_result - - with site_packages_paths(filter_func): - imported_module = sys.modules.pop(module_name, None) - try: - import_module(module_name) - except ImportError: - return False - else: - return True - finally: - if imported_module: - sys.modules[module_name] = imported_module - + return True -def is_std_lib(module): - return _is_installed_module( - module, - lambda i: "site-packages" not in i, - True) + with ignore_site_packages_paths(): + return bool(_safe_import_module(module_name)) +def is_site_package(module_name): + if not module_name: + return False -def is_site_packages(module): - return _is_installed_module( - module, - lambda i: "site-packages" in i, - False) + module = _safe_import_module(module_name) + module_path = getattr(module, "__file__", "") + if "site-packages" not in module_path: + return False + return "python" in module_path or "pypy" in module_path def list_strip(data): diff --git a/tests/test_groups.py b/tests/test_groups.py index 8d95ac5..2cad360 100644 --- a/tests/test_groups.py +++ b/tests/test_groups.py @@ -186,7 +186,7 @@ def test_str(self, mock_as_string): class TestSitePackagesGroup(unittest.TestCase): - @mock.patch('importanize.groups.is_site_packages') + @mock.patch('importanize.groups.is_site_package') def test_should_add_statement(self, mock_is_std_lib): statement = mock.MagicMock() actual = SitePackagesGroup().should_add_statement(statement) diff --git a/tests/test_utils.py b/tests/test_utils.py index 6d641f5..2e7ddc7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -7,45 +7,42 @@ import mock from importanize.utils import ( - site_packages_paths, + ignore_site_packages_paths, is_std_lib, - is_site_packages, + is_site_package, list_strip, read, ) class TestUtils(unittest.TestCase): - def test_site_packages_paths(self): - sys.path.append(os.getcwd()) - paths = sys.path[:] - - with site_packages_paths(lambda i: "site-packages" not in i): - self.assertNotEqual(sys.path, paths) - self.assertLess(len(sys.path), len(paths)) - - self.assertIn(os.getcwd(), sys.path) - self.assertListEqual(sys.path, paths) - sys.path.remove(os.getcwd()) - - def test_site_packages_paths_exception(self): + def _test_ignore_site_packages_paths(self, raise_msg=None): sys.path.append(os.getcwd()) paths = sys.path[:] try: - with site_packages_paths(lambda i: "site-packages" not in i): + with ignore_site_packages_paths(): self.assertNotEqual(sys.path, paths) self.assertLess(len(sys.path), len(paths)) - raise ValueError("TEST EXCEPTION") - + if raise_msg: + raise ValueError(raise_msg) except ValueError as e: - if "TEST EXCEPTION" not in str(e): + if raise_msg not in str(e): raise self.assertIn(os.getcwd(), sys.path) self.assertListEqual(sys.path, paths) sys.path.remove(os.getcwd()) + + def test_site_packages_paths(self): + self._test_ignore_site_packages_paths(raise_msg=None) + + + def test_site_packages_paths_exception(self): + self._test_ignore_site_packages_paths(raise_msg="TEST EXCEPTION") + + def test_is_std_lib(self): self.assertFalse(is_std_lib('')) @@ -107,39 +104,35 @@ def test_is_std_lib(self): self.assertFalse(is_std_lib('foo')) - def test_is_site_packages(self): - self.assertFalse(is_site_packages('')) + def test_is_site_package(self): + self.assertFalse(is_site_package('')) + # -- Be sure that stdlib modules are not site-packages stdlib_modules = ( 'argparse', 'codecs', ) for module in stdlib_modules: msg = '{} should not be sitepackages' - self.assertFalse(is_site_packages(module), + self.assertFalse(is_site_package(module), msg.format(module)) - self.assertFalse(is_site_packages('foo')) + # -- Be sure that fake modules are not site-packages + self.assertFalse(is_site_package('foo')) - def _is_site_package(name, module): - if name in ("pkg_resources",): - return False - return "site-packages" in getattr(module, "__file__", "") - site_packages_modules = [ - name - for name, module in sys.modules.items() - if _is_site_package(name, module) - ] - self.assertNotEqual(site_packages_modules, []) + # -- These packages come from requirements-dev.txt + site_packages_modules = ( + "coverage", + "mock", + "rednose", + "tox", + ) for module in site_packages_modules: - try: - msg = '{} should be sitepackages' - self.assertTrue(is_site_packages(module), - msg.format(module)) - except Exception: - print("Module Name: {}".format(module)) - raise + msg = '{} should be sitepackages' + self.assertTrue(is_site_package(module), + msg.format(module)) + def test_list_strip(self): self.assertListEqual( From 4e9e577160541182df5fc6ff46f79c032642da90 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Fri, 13 May 2016 18:26:04 -0400 Subject: [PATCH 7/9] Refactor for linter --- importanize/utils.py | 3 +++ tests/test_utils.py | 5 ----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/importanize/utils.py b/importanize/utils.py index 2006be9..361b071 100644 --- a/importanize/utils.py +++ b/importanize/utils.py @@ -27,6 +27,7 @@ def ignore_site_packages_paths(): finally: sys.path = paths + def _safe_import_module(module_name): imported_module = sys.modules.pop(module_name, None) try: @@ -37,6 +38,7 @@ def _safe_import_module(module_name): if imported_module: sys.modules[module_name] = imported_module + def is_std_lib(module_name): if not module_name: return False @@ -47,6 +49,7 @@ def is_std_lib(module_name): with ignore_site_packages_paths(): return bool(_safe_import_module(module_name)) + def is_site_package(module_name): if not module_name: return False diff --git a/tests/test_utils.py b/tests/test_utils.py index 2e7ddc7..82b82f1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -34,15 +34,12 @@ def _test_ignore_site_packages_paths(self, raise_msg=None): self.assertListEqual(sys.path, paths) sys.path.remove(os.getcwd()) - def test_site_packages_paths(self): self._test_ignore_site_packages_paths(raise_msg=None) - def test_site_packages_paths_exception(self): self._test_ignore_site_packages_paths(raise_msg="TEST EXCEPTION") - def test_is_std_lib(self): self.assertFalse(is_std_lib('')) @@ -120,7 +117,6 @@ def test_is_site_package(self): # -- Be sure that fake modules are not site-packages self.assertFalse(is_site_package('foo')) - # -- These packages come from requirements-dev.txt site_packages_modules = ( "coverage", @@ -133,7 +129,6 @@ def test_is_site_package(self): self.assertTrue(is_site_package(module), msg.format(module)) - def test_list_strip(self): self.assertListEqual( list_strip([' hello ', 'world']), From 827f6adf13fdeb6c32db61e16f6a7c950374fa6c Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Fri, 13 May 2016 18:33:20 -0400 Subject: [PATCH 8/9] 100% code coverage --- tests/test_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 82b82f1..f2aff26 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -28,7 +28,8 @@ def _test_ignore_site_packages_paths(self, raise_msg=None): raise ValueError(raise_msg) except ValueError as e: if raise_msg not in str(e): - raise + # -- This only happens if there's a bug in this test + raise # pragma: no cover self.assertIn(os.getcwd(), sys.path) self.assertListEqual(sys.path, paths) From 207435c254ea537cf2502456a343f897831949c8 Mon Sep 17 00:00:00 2001 From: Pamela McA'Nulty Date: Sat, 14 May 2016 13:58:46 -0400 Subject: [PATCH 9/9] Add sitepackage to input/output tests, make sitepakages part of defaults --- README.rst | 5 ++++- importanize/groups.py | 2 +- importanize/main.py | 3 +++ tests/test_data/input.txt | 1 + tests/test_data/output_grouped.txt | 2 ++ tests/test_data/output_inline_grouped.txt | 2 ++ tests/test_main.py | 2 ++ 7 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index cf8789d..c5e4092 100644 --- a/README.rst +++ b/README.rst @@ -93,11 +93,14 @@ Config file is simply a ``json`` file like this:: Default config looks something like:: - { + { "groups": [ { "type": "stdlib" }, + { + "type": "sitepackages" + }, { "type": "remainder" }, diff --git a/importanize/groups.py b/importanize/groups.py index 1a7dc9d..23d5692 100644 --- a/importanize/groups.py +++ b/importanize/groups.py @@ -121,7 +121,7 @@ class RemainderGroup(BaseImportGroup): def should_add_statement(self, statement): return True - +# -- RemainderGroup goes last and catches everything left over GROUP_MAPPING = OrderedDict(( ('stdlib', StdLibGroup), ('sitepackages', SitePackagesGroup), diff --git a/importanize/main.py b/importanize/main.py index f22baea..1d752e3 100644 --- a/importanize/main.py +++ b/importanize/main.py @@ -29,6 +29,9 @@ { 'type': 'stdlib', }, + { + 'type': 'sitepackages', + }, { 'type': 'remainder', }, diff --git a/tests/test_data/input.txt b/tests/test_data/input.txt index 60cfc2a..8b9cff3 100644 --- a/tests/test_data/input.txt +++ b/tests/test_data/input.txt @@ -14,6 +14,7 @@ from a.b import d import z from z import * +import coverage # in site-packages from z import foo import something # with comment diff --git a/tests/test_data/output_grouped.txt b/tests/test_data/output_grouped.txt index 4654a1e..6be7f89 100644 --- a/tests/test_data/output_grouped.txt +++ b/tests/test_data/output_grouped.txt @@ -4,6 +4,8 @@ from __future__ import print_function, unicode_literals import datetime from os import path as ospath +import coverage # in site-packages + import something # with comment import z from a import b diff --git a/tests/test_data/output_inline_grouped.txt b/tests/test_data/output_inline_grouped.txt index 3055132..4f38d79 100644 --- a/tests/test_data/output_inline_grouped.txt +++ b/tests/test_data/output_inline_grouped.txt @@ -4,6 +4,8 @@ from __future__ import print_function, unicode_literals import datetime from os import path as ospath +import coverage # in site-packages + import something # with comment import z from a import b diff --git a/tests/test_main.py b/tests/test_main.py index 8e27a77..daa70e3 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -53,6 +53,8 @@ def test_run_importanize_print(self, mock_print): mock.MagicMock(print=True, formatter='grouped')) ) + + # self.assertMultiLineEqual(mock_print.call_args[0][0], expected) mock_print.assert_called_once_with(expected) @mock.patch(TESTING_MODULE + '.print', create=True)