From de42908f7ef06a10254046d74ff8929ecb59c661 Mon Sep 17 00:00:00 2001 From: KapilBansal320 Date: Thu, 24 Sep 2020 12:58:23 +0530 Subject: [PATCH 1/2] [fix] Fixed error in ReStructuredText Check #150 Fixes #150 --- openwisp_utils/qa.py | 10 ++-------- setup.py | 5 ++--- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/openwisp_utils/qa.py b/openwisp_utils/qa.py index 0dc32d13..9e01532d 100644 --- a/openwisp_utils/qa.py +++ b/openwisp_utils/qa.py @@ -10,7 +10,6 @@ import docutils import readme_renderer.rst as readme_rst -from rstcheck import ignore_sphinx def _parse_migration_check_args(): @@ -193,9 +192,7 @@ def check_rst_files(): settings_overrides.update(readme_rst.SETTINGS) settings_overrides['report_level'] = 2 settings_overrides['warning_stream'] = string_io - files = [_ for _ in iglob('./**/*.rst', recursive=True)] - # Added to register sphinx directives with docutils - ignore_sphinx() + files = [_ for _ in iglob('*.rst', recursive=True)] for file in files: data = read_rst_file(file) try: @@ -249,10 +246,7 @@ def _find_issue_mentions(message): preceding_2words = '{} {}'.format( words[issue_location - 2], words[issue_location - 1] ) - allowed_refs = [ - 'related to', - 'refers to', - ] + allowed_refs = ['related to', 'refers to'] if preceding_2words.lower() in allowed_refs: good_mentions += 1 continue diff --git a/setup.py b/setup.py index 9722ed9b..2411771e 100644 --- a/setup.py +++ b/setup.py @@ -37,9 +37,9 @@ 'checkmigrations = openwisp_utils.qa:check_migration_name', 'checkcommit = openwisp_utils.qa:check_commit_message', 'checkrst = openwisp_utils.qa:check_rst_files', - ], + ] }, - scripts=['openwisp-qa-check', 'openwisp-qa-format',], + scripts=['openwisp-qa-check', 'openwisp-qa-format'], zip_safe=False, install_requires=['django-model-utils>=4.0.0,<4.1.0'], extras_require={ @@ -48,7 +48,6 @@ 'flake8<=3.9', 'isort~=5.0', 'readme-renderer~=26.0', - 'rstcheck', 'coveralls', # depends on coverage as well ], 'rest': [ From ee46617e19f993a6dd5143c3330b225c56a31082 Mon Sep 17 00:00:00 2001 From: KapilBansal320 Date: Thu, 24 Sep 2020 13:04:36 +0530 Subject: [PATCH 2/2] [refactor] Reformatting code using openwisp-qa-format --- openwisp_utils/admin.py | 7 ++----- openwisp_utils/tests.py | 3 +-- tests/settings.py | 4 ++-- tests/test_project/admin.py | 12 ++---------- tests/test_project/api/urls.py | 2 +- tests/test_project/apps.py | 4 +--- tests/test_project/migrations/0001_initial.py | 4 ++-- .../migrations/0002_add_key_id_project.py | 4 +--- tests/test_project/tests/test_api.py | 4 +--- tests/test_project/tests/test_qa.py | 13 ++----------- tests/test_project/tests/test_test_utils.py | 4 ++-- 11 files changed, 17 insertions(+), 44 deletions(-) diff --git a/openwisp_utils/admin.py b/openwisp_utils/admin.py index 741a81bc..961143cb 100644 --- a/openwisp_utils/admin.py +++ b/openwisp_utils/admin.py @@ -10,10 +10,7 @@ class TimeReadonlyAdminMixin(object): """ def __init__(self, *args, **kwargs): - self.readonly_fields += ( - 'created', - 'modified', - ) + self.readonly_fields += ('created', 'modified') super().__init__(*args, **kwargs) @@ -147,7 +144,7 @@ def receive_url(self, obj): ) baseurl = self.receive_url_baseurl if not baseurl: - baseurl = '{0}://{1}'.format(self.request.scheme, self.request.get_host(),) + baseurl = '{0}://{1}'.format(self.request.scheme, self.request.get_host()) if self.receive_url_querystring_arg: url = '{0}{1}?{2}={3}'.format( baseurl, diff --git a/openwisp_utils/tests.py b/openwisp_utils/tests.py index fac048ea..112a1b87 100644 --- a/openwisp_utils/tests.py +++ b/openwisp_utils/tests.py @@ -45,8 +45,7 @@ def addSuccess(self, test): def display_slow_tests(self): print_color( - f'\nSummary of slow tests (>{self.slow_test_threshold[0]}s)\n', - 'white_bold', + f'\nSummary of slow tests (>{self.slow_test_threshold[0]}s)\n', 'white_bold' ) self._module = None slow_tests_counter = 0 diff --git a/tests/settings.py b/tests/settings.py index cc6d8d9a..0704f4dd 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -71,7 +71,7 @@ 'openwisp_utils.admin_theme.context_processor.admin_theme_settings', ], }, - }, + } ] DATABASES = { @@ -96,7 +96,7 @@ 'DEFAULT_THROTTLE_RATES': {'anon': '20/hour'}, } -CACHES = {'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache',}} +CACHES = {'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}} # local settings must be imported before test runner otherwise they'll be ignored try: diff --git a/tests/test_project/admin.py b/tests/test_project/admin.py index 576ea726..e225c8b8 100644 --- a/tests/test_project/admin.py +++ b/tests/test_project/admin.py @@ -36,16 +36,8 @@ class OperatorInline(admin.StackedInline): class ProjectAdmin(UUIDAdmin, ReceiveUrlAdmin): inlines = [OperatorInline] list_display = ('name',) - fields = ( - 'uuid', - 'name', - 'key', - 'receive_url', - ) - readonly_fields = ( - 'uuid', - 'receive_url', - ) + fields = ('uuid', 'name', 'key', 'receive_url') + readonly_fields = ('uuid', 'receive_url') receive_url_name = 'receive_project' diff --git a/tests/test_project/api/urls.py b/tests/test_project/api/urls.py index 76903d93..969c37b0 100644 --- a/tests/test_project/api/urls.py +++ b/tests/test_project/api/urls.py @@ -7,5 +7,5 @@ r'^receive_project/(?P[^/\?]+)/$', views.receive_project, name='receive_project', - ), + ) ] diff --git a/tests/test_project/apps.py b/tests/test_project/apps.py index bc22affc..105812f5 100644 --- a/tests/test_project/apps.py +++ b/tests/test_project/apps.py @@ -18,7 +18,5 @@ def ready(self, *args, **kwargs): def add_default_menu_items(self): menu_setting = 'OPENWISP_DEFAULT_ADMIN_MENU_ITEMS' - items = [ - {'model': 'test_project.Shelf'}, - ] + items = [{'model': 'test_project.Shelf'}] setattr(settings, menu_setting, items) diff --git a/tests/test_project/migrations/0001_initial.py b/tests/test_project/migrations/0001_initial.py index 5c1dab11..19c8e581 100644 --- a/tests/test_project/migrations/0001_initial.py +++ b/tests/test_project/migrations/0001_initial.py @@ -89,7 +89,7 @@ class Migration(migrations.Migration): ), ('name', models.CharField(max_length=64, verbose_name='name')), ], - options={'abstract': False,}, + options={'abstract': False}, ), migrations.CreateModel( name='Operator', @@ -153,6 +153,6 @@ class Migration(migrations.Migration): ), ), ], - options={'abstract': False,}, + options={'abstract': False}, ), ] diff --git a/tests/test_project/migrations/0002_add_key_id_project.py b/tests/test_project/migrations/0002_add_key_id_project.py index 59a352d3..4ffe0d0e 100644 --- a/tests/test_project/migrations/0002_add_key_id_project.py +++ b/tests/test_project/migrations/0002_add_key_id_project.py @@ -10,9 +10,7 @@ class Migration(migrations.Migration): - dependencies = [ - ('test_project', '0001_initial'), - ] + dependencies = [('test_project', '0001_initial')] operations = [ migrations.AddField( diff --git a/tests/test_project/tests/test_api.py b/tests/test_project/tests/test_api.py index 6baf6a9b..f9e3c8af 100644 --- a/tests/test_project/tests/test_api.py +++ b/tests/test_project/tests/test_api.py @@ -9,9 +9,7 @@ class TestApi(CreateMixin, TestCase): shelf_model = Shelf - operator_permission_filter = [ - {'codename__endswith': 'shelf'}, - ] + operator_permission_filter = [{'codename__endswith': 'shelf'}] def test_validator_pass(self): s1 = self._create_shelf(name='shelf1') diff --git a/tests/test_project/tests/test_qa.py b/tests/test_project/tests/test_qa.py index 3e058614..bc5ca0e9 100644 --- a/tests/test_project/tests/test_qa.py +++ b/tests/test_project/tests/test_qa.py @@ -69,11 +69,7 @@ def test_qa_call_check_migration_name_failure(self): self.fail('SystemExit not raised') def test_migration_failure_message(self): - bad_migration = [ - 'checkmigrations', - '--migration-path', - MIGRATIONS_DIR, - ] + bad_migration = ['checkmigrations', '--migration-path', MIGRATIONS_DIR] with patch('argparse._sys.argv', bad_migration): captured_output = io.StringIO() sys.stdout = captured_output # redirect stdout @@ -169,12 +165,7 @@ def test_qa_call_check_commit_message_failure(self): '--message', '[qa] Updated file and fixed problem\n\nAdded more files. Fixes #20', ], - [ - 'commitcheck', - '--quiet', - '--message', - '[qa] Improved Y\n\nRelated to #2', - ], + ['commitcheck', '--quiet', '--message', '[qa] Improved Y\n\nRelated to #2'], [ 'commitcheck', '--quiet', diff --git a/tests/test_project/tests/test_test_utils.py b/tests/test_project/tests/test_test_utils.py index f8cff0d3..2dd0621d 100644 --- a/tests/test_project/tests/test_test_utils.py +++ b/tests/test_project/tests/test_test_utils.py @@ -16,7 +16,7 @@ def test_status_signal_emitted(self): with catch_signal(status_signal) as handler: self._generate_signal() handler.assert_called_once_with( - status='working', sender=self, signal=status_signal, + status='working', sender=self, signal=status_signal ) def test_deep_merge_dicts(self): @@ -44,7 +44,7 @@ def test_deep_merge_dicts(self): def test_time_logging_runner(self): runner = TimeLoggingTestRunner() suite = runner.build_suite( - ['test_project.tests.test_test_utils.TestUtils.test_status_signal_emitted'], + ['test_project.tests.test_test_utils.TestUtils.test_status_signal_emitted'] ) with captured_stdout() as stdout, captured_stderr() as stderr: runner.run_suite(suite)