From 4deefc20b7123e5feab170826b6bbdfd3ea09539 Mon Sep 17 00:00:00 2001 From: Fabio Caccamo Date: Wed, 1 Mar 2023 17:54:58 +0100 Subject: [PATCH] Add `flake8-bugbear` to `pre-commit`. --- .pre-commit-config.yaml | 2 ++ admin_interface/migrations/0011_add_environment_options.py | 5 ++++- admin_interface/models.py | 3 ++- tests/test_models.py | 2 +- tests/test_multidb.py | 3 ++- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b7b2b0..afb4c0e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,6 +29,8 @@ repos: rev: 6.0.0 hooks: - id: flake8 + additional_dependencies: + - flake8-bugbear - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 diff --git a/admin_interface/migrations/0011_add_environment_options.py b/admin_interface/migrations/0011_add_environment_options.py index 0dd8101..a2ce25e 100644 --- a/admin_interface/migrations/0011_add_environment_options.py +++ b/admin_interface/migrations/0011_add_environment_options.py @@ -24,7 +24,10 @@ class Migration(migrations.Migration): field=colorfield.fields.ColorField( blank=True, default="#E74C3C", - help_text="(red: #E74C3C, orange: #E67E22, yellow: #F1C40F, green: #2ECC71, blue: #3498DB)", # noqa: E501 + help_text=( + "(red: #E74C3C, orange: #E67E22, yellow: #F1C40F, " + "green: #2ECC71, blue: #3498DB)" + ), max_length=10, verbose_name="color", ), diff --git a/admin_interface/models.py b/admin_interface/models.py index c119bb8..646396b 100644 --- a/admin_interface/models.py +++ b/admin_interface/models.py @@ -116,7 +116,8 @@ class Theme(models.Model): blank=True, default="#E74C3C", help_text=_( - "(red: #E74C3C, orange: #E67E22, yellow: #F1C40F, green: #2ECC71, blue: #3498DB)" # noqa: E501 + "(red: #E74C3C, orange: #E67E22, yellow: #F1C40F, " + "green: #2ECC71, blue: #3498DB)" ), max_length=10, verbose_name=_("color"), diff --git a/tests/test_models.py b/tests/test_models.py index bcffdba..5754e96 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -75,7 +75,7 @@ class AdminInterfaceModelsTestCase(TestCase): theme_4 = Theme.objects.create(name="Custom 4", active=True) theme_5 = Theme.objects.create(name="Custom 5", active=True) themes = [theme_1, theme_2, theme_3, theme_4, theme_5] - for i in range(5): + for _ in range(5): random.shuffle(themes) for theme in themes: theme.set_active() diff --git a/tests/test_multidb.py b/tests/test_multidb.py index 018bcce..e315d7d 100644 --- a/tests/test_multidb.py +++ b/tests/test_multidb.py @@ -1,4 +1,5 @@ from django.test import TestCase +from django.test.testcases import DatabaseOperationForbidden from admin_interface.models import Theme @@ -22,7 +23,7 @@ class AdminInterfaceModelsWithDBRoutingTestCase(TestCase): assert db_for_theme == "replica" def test_dbrouter_errors_when_fetching_from_default(self): - with self.assertRaises(Exception): + with self.assertRaises(DatabaseOperationForbidden): Theme.objects.get_active() def test_dbrouter_fetches_db(self):