You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by gc...@apache.org on 2023/03/09 22:38:57 UTC
[allura] 01/05: [#8502] fixing more code violations
This is an automated email from the ASF dual-hosted git repository.
gcruz pushed a commit to branch gc/8502
in repository https://gitbox.apache.org/repos/asf/allura.git
commit de9c2e0b03150bd6eeab505e9c8d145821a2fd01
Author: Guillermo Cruz <gu...@slashdotmedia.com>
AuthorDate: Mon Mar 6 12:37:59 2023 -0600
[#8502] fixing more code violations
---
Allura/allura/config/middleware.py | 30 +++++++++++-----------
Allura/allura/ext/admin/admin_main.py | 4 +--
Allura/allura/model/filesystem.py | 2 +-
.../allura/tests/functional/test_neighborhood.py | 6 ++---
Allura/allura/tests/model/test_timeline.py | 2 +-
Allura/allura/tests/test_multifactor.py | 4 +--
Allura/allura/tests/test_plugin.py | 6 ++---
.../allura/tests/unit/spam/test_stopforumspam.py | 6 ++---
Allura/setup.py | 2 +-
AlluraTest/alluratest/test_syntax.py | 10 ++------
.../tests/github/functional/test_github.py | 2 +-
ForgeTracker/forgetracker/import_support.py | 4 +--
12 files changed, 36 insertions(+), 42 deletions(-)
diff --git a/Allura/allura/config/middleware.py b/Allura/allura/config/middleware.py
index 99b88645f..043943ef8 100644
--- a/Allura/allura/config/middleware.py
+++ b/Allura/allura/config/middleware.py
@@ -49,21 +49,21 @@ except ImportError:
else:
patches.newrelic()
-from allura.config.app_cfg import AlluraJinjaRenderer # noqa: E402
-from allura.config.app_cfg import ForgeConfig # noqa: E402
-from allura.lib.custom_middleware import AlluraTimerMiddleware # noqa: E402
-from allura.lib.custom_middleware import SSLMiddleware # noqa: E402
-from allura.lib.custom_middleware import StaticFilesMiddleware # noqa: E402
-from allura.lib.custom_middleware import CSRFMiddleware # noqa: E402
-from allura.lib.custom_middleware import CORSMiddleware # noqa: E402
-from allura.lib.custom_middleware import LoginRedirectMiddleware # noqa: E402
-from allura.lib.custom_middleware import RememberLoginMiddleware # noqa: E402
-from allura.lib.custom_middleware import SetRequestHostFromConfig # noqa: E402
-from allura.lib.custom_middleware import MingTaskSessionSetupMiddleware # noqa: E402
-from allura.lib.custom_middleware import ContentSecurityPolicyMiddleware # noqa: E402
-from allura.lib.custom_middleware import StatusCodeRedirect # noqa: E402
-from allura.lib import helpers as h # noqa: E402
-from allura.lib.utils import configure_ming # noqa: E402
+from allura.config.app_cfg import AlluraJinjaRenderer
+from allura.config.app_cfg import ForgeConfig
+from allura.lib.custom_middleware import AlluraTimerMiddleware
+from allura.lib.custom_middleware import SSLMiddleware
+from allura.lib.custom_middleware import StaticFilesMiddleware
+from allura.lib.custom_middleware import CSRFMiddleware
+from allura.lib.custom_middleware import CORSMiddleware
+from allura.lib.custom_middleware import LoginRedirectMiddleware
+from allura.lib.custom_middleware import RememberLoginMiddleware
+from allura.lib.custom_middleware import SetRequestHostFromConfig
+from allura.lib.custom_middleware import MingTaskSessionSetupMiddleware
+from allura.lib.custom_middleware import ContentSecurityPolicyMiddleware
+from allura.lib.custom_middleware import StatusCodeRedirect
+from allura.lib import helpers as h
+from allura.lib.utils import configure_ming
__all__ = ['make_app']
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index 3cf3eba29..9dd17d062 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -666,7 +666,7 @@ class ProjectAdminController(BaseController):
else:
require_access(c.project, 'admin')
installable_tools = AdminApp.installable_tools_for(c.project)
- if not ep_name.lower() in [t['name'].lower() for t in installable_tools]:
+ if ep_name.lower() not in [t['name'].lower() for t in installable_tools]:
flash('Installation limit exceeded.', 'error')
return
mount_point = new['mount_point'] or ep_name
@@ -946,7 +946,7 @@ class ProjectAdminRestController(BaseController):
}
installable_tools = AdminApp.installable_tools_for(c.project)
tools_names = [t['name'] for t in installable_tools]
- if not (tool in tools_names):
+ if tool not in tools_names:
return {
'success': False,
'info': 'Incorrect tool name, or limit is reached.'
diff --git a/Allura/allura/model/filesystem.py b/Allura/allura/model/filesystem.py
index ed0808383..bd5da977b 100644
--- a/Allura/allura/model/filesystem.py
+++ b/Allura/allura/model/filesystem.py
@@ -181,7 +181,7 @@ class File(MappedClass):
convert_bmp=False):
if content_type is None:
content_type = utils.guess_mime_type(filename)
- if not content_type.lower() in SUPPORTED_BY_PIL:
+ if content_type.lower() not in SUPPORTED_BY_PIL:
log.debug('Content type %s from file %s not supported',
content_type, filename)
return None, None
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index d9fd3fc21..13f46dfff 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -769,9 +769,9 @@ class TestNeighborhood(TestController):
assert "My home text!" in r
# check tool options
opts = p.app_config('wiki').options
- assert False == opts.show_discussion
- assert False == opts.show_left_bar
- assert False == opts.show_right_bar
+ assert opts.show_discussion is False
+ assert opts.show_left_bar is False
+ assert opts.show_right_bar is False
assert "http://foo.com/testtemp/" == opts.some_url
# check that custom groups/perms/users were setup correctly
roles = p.named_roles
diff --git a/Allura/allura/tests/model/test_timeline.py b/Allura/allura/tests/model/test_timeline.py
index ad1b252af..264057b68 100644
--- a/Allura/allura/tests/model/test_timeline.py
+++ b/Allura/allura/tests/model/test_timeline.py
@@ -36,5 +36,5 @@ class TestActivityObject_Functional:
wiki_app = p.app_instance('wiki')
app_config = wiki_app.config
- assert (bool(app_config.has_activity_access('read', user=M.User.anonymous(), activity=None)) ==
+ assert (bool(app_config.has_activity_access('read', user=M.User.anonymous(), activity=None)) is
True)
\ No newline at end of file
diff --git a/Allura/allura/tests/test_multifactor.py b/Allura/allura/tests/test_multifactor.py
index 8ba2454bc..7192e298a 100644
--- a/Allura/allura/tests/test_multifactor.py
+++ b/Allura/allura/tests/test_multifactor.py
@@ -138,7 +138,7 @@ class TestAnyTotpServiceImplementation:
def test_none(self):
srv = self.Service()
user = self.mock_user()
- assert None == srv.get_secret_key(user)
+ assert srv.get_secret_key(user) is None
def test_set_get(self):
srv = self.Service()
@@ -152,7 +152,7 @@ class TestAnyTotpServiceImplementation:
srv.set_secret_key(user, self.sample_key)
assert self.sample_key == srv.get_secret_key(user)
srv.set_secret_key(user, None)
- assert None == srv.get_secret_key(user)
+ assert srv.get_secret_key(user) is None
@patch('allura.lib.multifactor.time')
def test_rate_limiting(self, time):
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 5efd39cc1..8248362b6 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -224,7 +224,7 @@ class TestProjectRegistrationProviderPhoneVerification:
'request-id', '1111')
assert result == g.phone_service.check.return_value
assert (
- self.user.get_tool_data('phone_verification', 'number_hash') ==
+ self.user.get_tool_data('phone_verification', 'number_hash') is
None)
audit.assert_called_once_with(
'Phone verification failed. Hash: hash', user=self.user)
@@ -689,7 +689,7 @@ class TestLocalAuthenticationProvider:
def test_login_details_from_auditlog(self):
user = M.User(username='asfdasdf')
- assert (self.provider.login_details_from_auditlog(M.AuditLog(message='')) ==
+ assert (self.provider.login_details_from_auditlog(M.AuditLog(message='')) is
None)
detail = self.provider.login_details_from_auditlog(M.AuditLog(message='IP Address: 1.2.3.4\nFoo', user=user))
@@ -702,7 +702,7 @@ class TestLocalAuthenticationProvider:
assert detail.ua is None
assert (self.provider.login_details_from_auditlog(M.AuditLog(
- message='blah blah IP Address: 1.2.3.4\nFoo', user=user)) ==
+ message='blah blah IP Address: 1.2.3.4\nFoo', user=user)) is
None)
detail = self.provider.login_details_from_auditlog(M.AuditLog(
diff --git a/Allura/allura/tests/unit/spam/test_stopforumspam.py b/Allura/allura/tests/unit/spam/test_stopforumspam.py
index bb827183e..590bcc049 100644
--- a/Allura/allura/tests/unit/spam/test_stopforumspam.py
+++ b/Allura/allura/tests/unit/spam/test_stopforumspam.py
@@ -42,10 +42,10 @@ class TestStopForumSpam:
@mock.patch('allura.lib.spam.stopforumspamfilter.request')
def test_check(self, request):
request.remote_addr = '1.2.3.4'
- assert True == self.sfs.check(self.content, artifact=self.artifact)
+ assert self.sfs.check(self.content, artifact=self.artifact) is True
request.remote_addr = '1.1.1.1'
- assert False == self.sfs.check(self.content, artifact=self.artifact)
+ assert self.sfs.check(self.content, artifact=self.artifact) is False
request.remote_addr = None # e.g. from background task processing inbound email
- assert False == self.sfs.check(self.content, artifact=self.artifact)
+ assert self.sfs.check(self.content, artifact=self.artifact) is False
diff --git a/Allura/setup.py b/Allura/setup.py
index aa5f79113..ece157874 100644
--- a/Allura/setup.py
+++ b/Allura/setup.py
@@ -26,7 +26,7 @@ lists, wiki pages, blogs and more for any number of individual projects.
'''
setup(
name='Allura',
- version=__version__,
+ version=__version__, # noqa
description='Base distribution of the Allura development platform',
long_description=PROJECT_DESCRIPTION,
author='Allura Team',
diff --git a/AlluraTest/alluratest/test_syntax.py b/AlluraTest/alluratest/test_syntax.py
index 21ffd869e..097eeb593 100644
--- a/AlluraTest/alluratest/test_syntax.py
+++ b/AlluraTest/alluratest/test_syntax.py
@@ -79,18 +79,12 @@ def run_linter(files):
def run_pyflakes(files):
# skip some that aren't critical errors
- skips = [
- 'imported but unused',
- 'redefinition of unused',
- 'assigned to but never used',
- '__version__',
- ]
files = [f for f in files if '/migrations/' not in f]
- cmd = "ruff check " + ' '.join(files) + " | grep -v '" + "' | grep -v '".join(skips) + "'"
+ cmd = "ruff check " + ' '.join(files) + " | grep -v '" + "'"
#print("CMD", cmd)
if run(cmd) != 1:
# print 'Command was: %s' % cmd
- raise Exception('ruff failure, see stdout')
+ raise Exception('ruff failure, see stdout', sys.stderr)
class TestLinters:
diff --git a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
index f6404d758..17b9fb18f 100644
--- a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
+++ b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
@@ -95,5 +95,5 @@ class TestGitHubOAuth(TestController):
def test_project_import_login_required(self):
r = self.app.get('/p/import_project/github/', extra_environ=dict(username='*anonymous'))
- assert None == r.location
+ assert r.location is None
r.mustcontain('Login Required')
diff --git a/ForgeTracker/forgetracker/import_support.py b/ForgeTracker/forgetracker/import_support.py
index 31561e0c0..13acf1c0b 100644
--- a/ForgeTracker/forgetracker/import_support.py
+++ b/ForgeTracker/forgetracker/import_support.py
@@ -175,7 +175,7 @@ class ImportSupport:
break
else:
milestone = {'due_date': '',
- 'complete': not ticket_status in c.app.globals.open_status_names,
+ 'complete': ticket_status not in c.app.globals.open_status_names,
'description': '',
'name': value,
'old_name': value}
@@ -289,7 +289,7 @@ class ImportSupport:
def find_unknown_users(self, users):
unknown = set()
for u in users:
- if u and not u in self.options['user_map'] and not M.User.by_username(u):
+ if u and u not in self.options['user_map'] and not M.User.by_username(u):
unknown.add(u)
return unknown