From 24ebcefda25eb62b74899e5e147ab8a7ac9988c1 Mon Sep 17 00:00:00 2001 From: Tyler Yep Date: Mon, 28 Sep 2020 12:44:14 -0700 Subject: [PATCH] separate test files and rename imports --- didyoumean/__init__.py | 2 -- didyoumean/{didyoumean_api.py => api.py} | 2 +- didyoumean/{didyoumean_internal.py => internal.py} | 6 +++--- didyoumean/{didyoumean_re.py => re.py} | 0 didyoumean/readme_examples.py | 4 ++-- tests/__init__.py | 0 didyoumean/didyoumean_api_tests.py => tests/api_test.py | 6 +++--- .../didyoumean_common_tests.py => tests/common_test.py | 0 .../internal_test.py | 6 +++--- didyoumean/didyoumean_re_tests.py => tests/re_test.py | 8 ++++---- didyoumean/didyoumean_sugg_tests.py => tests/sugg_test.py | 6 +++--- 11 files changed, 19 insertions(+), 21 deletions(-) rename didyoumean/{didyoumean_api.py => api.py} (98%) rename didyoumean/{didyoumean_internal.py => internal.py} (99%) rename didyoumean/{didyoumean_re.py => re.py} (100%) create mode 100644 tests/__init__.py rename didyoumean/didyoumean_api_tests.py => tests/api_test.py (98%) rename didyoumean/didyoumean_common_tests.py => tests/common_test.py (100%) rename didyoumean/didyoumean_internal_tests.py => tests/internal_test.py (99%) rename didyoumean/didyoumean_re_tests.py => tests/re_test.py (99%) rename didyoumean/didyoumean_sugg_tests.py => tests/sugg_test.py (99%) diff --git a/didyoumean/__init__.py b/didyoumean/__init__.py index 527638f..e69de29 100644 --- a/didyoumean/__init__.py +++ b/didyoumean/__init__.py @@ -1,2 +0,0 @@ -"""Empty file. Might grow in the future.""" -import didyoumean_api diff --git a/didyoumean/didyoumean_api.py b/didyoumean/api.py similarity index 98% rename from didyoumean/didyoumean_api.py rename to didyoumean/api.py index 414b4e3..01ddcd3 100644 --- a/didyoumean/didyoumean_api.py +++ b/didyoumean/api.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 """APIs to add suggestions to exceptions.""" -from didyoumean_internal import add_suggestions_to_exception +from didyoumean.internal import add_suggestions_to_exception import functools import sys diff --git a/didyoumean/didyoumean_internal.py b/didyoumean/internal.py similarity index 99% rename from didyoumean/didyoumean_internal.py rename to didyoumean/internal.py index e8cc394..3001253 100755 --- a/didyoumean/didyoumean_internal.py +++ b/didyoumean/internal.py @@ -2,7 +2,7 @@ """Logic to add suggestions to exceptions.""" import keyword import difflib -import didyoumean_re as re +import didyoumean.dre as re import itertools import inspect import errno @@ -170,7 +170,7 @@ def get_types_for_str(tp_name, frame): def merge_dict(*dicts): - """Merge dicts and return a dictionnary mapping key to list of values. + """Merge dicts and return a dictionary mapping key to list of values. Order of the values corresponds to the order of the original dicts. """ @@ -192,7 +192,7 @@ def get_objects_in_frame(frame): """Get objects defined in a given frame. This includes variable, types, builtins, etc. - The function returns a dictionnary mapping names to a (non empty) + The function returns a dictionary mapping names to a (non empty) list of ScopedObj objects in the order following the LEGB Rule. """ # https://www.python.org/dev/peps/pep-0227/ PEP227 Statically Nested Scopes diff --git a/didyoumean/didyoumean_re.py b/didyoumean/re.py similarity index 100% rename from didyoumean/didyoumean_re.py rename to didyoumean/re.py diff --git a/didyoumean/readme_examples.py b/didyoumean/readme_examples.py index 0979b32..c290d89 100755 --- a/didyoumean/readme_examples.py +++ b/didyoumean/readme_examples.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 """Code to generate examples in README.md.""" -from didyoumean_internal import add_suggestions_to_exception -import didyoumean_common_tests as common +from didyoumean.internal import add_suggestions_to_exception +import tests.common_test as common import os diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/didyoumean/didyoumean_api_tests.py b/tests/api_test.py similarity index 98% rename from didyoumean/didyoumean_api_tests.py rename to tests/api_test.py index 51264a3..e98eb23 100755 --- a/didyoumean/didyoumean_api_tests.py +++ b/tests/api_test.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 """Unit tests for didyoumean APIs.""" -from didyoumean_api import didyoumean_decorator, didyoumean_contextmanager,\ +from didyoumean.api import didyoumean_decorator, didyoumean_contextmanager,\ didyoumean_postmortem, didyoumean_enablehook, didyoumean_disablehook -from didyoumean_common_tests import TestWithStringFunction,\ +from tests.common_test import TestWithStringFunction,\ get_exception, no_exception, NoFileIoError, unittest_module import contextlib import sys @@ -266,7 +266,7 @@ def run_with_api(self, code): """Run code with didyoumean after enabling didyoumean hook.""" prev_handler = None shell = DummyShell() - module = sys.modules['didyoumean_api'] + module = sys.modules['didyoumean.api'] shell.set(module) self.assertEqual(shell.handler, prev_handler) didyoumean_enablehook() diff --git a/didyoumean/didyoumean_common_tests.py b/tests/common_test.py similarity index 100% rename from didyoumean/didyoumean_common_tests.py rename to tests/common_test.py diff --git a/didyoumean/didyoumean_internal_tests.py b/tests/internal_test.py similarity index 99% rename from didyoumean/didyoumean_internal_tests.py rename to tests/internal_test.py index dd9e007..e47dc42 100755 --- a/didyoumean/didyoumean_internal_tests.py +++ b/tests/internal_test.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 """Unit tests for code in didyoumean_internal.py.""" -from didyoumean_internal import quote, get_suggestion_string,\ +from didyoumean.internal import quote, get_suggestion_string,\ add_string_to_exception, get_func_by_name,\ get_objects_in_frame, get_subclasses, get_types_for_str,\ get_types_for_str_using_inheritance,\ get_types_for_str_using_names -import didyoumean_common_tests as common -from didyoumean_common_tests import unittest_module,\ +import tests.common_test as common +from tests.common_test import unittest_module,\ CommonTestOldStyleClass2,\ CommonTestNewStyleClass2 # to have these 2 in defined names import itertools diff --git a/didyoumean/didyoumean_re_tests.py b/tests/re_test.py similarity index 99% rename from didyoumean/didyoumean_re_tests.py rename to tests/re_test.py index 3f4fd66..5d7e91b 100755 --- a/didyoumean/didyoumean_re_tests.py +++ b/tests/re_test.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 """Unit tests for regexps from didyoumean_re.py.""" -import didyoumean_re as re +import didyoumean.re as re import sys -from didyoumean_internal import get_subclasses -from didyoumean_common_tests import unittest_module +from didyoumean.internal import get_subclasses +from tests.common_test import unittest_module NO_GROUP = ((), dict()) # Various technical flags to check more that meet the eyes in tests @@ -31,7 +31,7 @@ def re_matches(self, text, regexp, results): and groupdict(). """ groups, named_groups = results - self.assertRegexpMatches(text, regexp) # does pretty printing + self.assertRegexpMatches(text, regexp) # does pretty printing match = re.match(regexp, text) self.assertTrue(match) self.assertEqual(groups, match.groups()) diff --git a/didyoumean/didyoumean_sugg_tests.py b/tests/sugg_test.py similarity index 99% rename from didyoumean/didyoumean_sugg_tests.py rename to tests/sugg_test.py index 3d2b0c0..445490b 100755 --- a/didyoumean/didyoumean_sugg_tests.py +++ b/tests/sugg_test.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 """Unit tests for get_suggestions_for_exception.""" -from didyoumean_internal import get_suggestions_for_exception, quote, \ +from didyoumean.internal import get_suggestions_for_exception, quote, \ STAND_MODULES, AVOID_REC_MSG, \ APPLY_REMOVED_MSG, BUFFER_REMOVED_MSG, CMP_REMOVED_MSG, \ CMP_ARG_REMOVED_MSG, EXC_ATTR_REMOVED_MSG, LONG_REMOVED_MSG, \ MEMVIEW_ADDED_MSG, RELOAD_REMOVED_MSG, STDERR_REMOVED_MSG, \ BREAKPOINT_ADDED_MSG, NO_KEYWORD_ARG_MSG -import didyoumean_common_tests as common -import didyoumean_re as re +import tests.common_test as common +import didyoumean.dre as re import warnings import sys import math