Skip to content

Commit 341986d

Browse files
committed
Appease ruff
1 parent 0f612a8 commit 341986d

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Change log
1010
- Fixed the broken argument validation of ``./manage.py f3dumpdata``.
1111
- Switched to hatchling and ruff.
1212
- Made ``specs_for_*_models`` helpers return a list instead of a generator.
13+
- Changed the ``assert`` statement for checking the dump version into a
14+
``raise`` statement since assertions could be optimized out.
15+
- Renamed ``InvalidSpec`` to ``InvalidSpecError`` to make ruff happier.
1316

1417

1518
`0.5`_ (2023-03-15)

feincms3_data/data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class InvalidVersionError(Exception):
4242
pass
4343

4444

45-
class InvalidSpec(Exception):
45+
class InvalidSpecError(Exception):
4646
pass
4747

4848

@@ -59,9 +59,9 @@ class InvalidSpec(Exception):
5959

6060
def _validate_spec(spec):
6161
if "model" not in spec:
62-
raise InvalidSpec(f"The spec {spec!r} requires a 'model' key")
62+
raise InvalidSpecError(f"The spec {spec!r} requires a 'model' key")
6363
if unknown := (set(spec.keys()) - _valid_keys):
64-
raise InvalidSpec(f"The spec {spec!r} contains unknown keys: {unknown!r}")
64+
raise InvalidSpecError(f"The spec {spec!r} contains unknown keys: {unknown!r}")
6565
return spec
6666

6767

tests/testapp/test_data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.test import TransactionTestCase
55

66
from feincms3_data.data import (
7-
InvalidSpec,
7+
InvalidSpecError,
88
InvalidVersionError,
99
_validate_spec,
1010
datasets,
@@ -53,12 +53,12 @@ def related_names():
5353

5454
class DataTest(TransactionTestCase):
5555
def test_invalid_spec_missing_model(self):
56-
with self.assertRaises(InvalidSpec) as cm:
56+
with self.assertRaises(InvalidSpecError) as cm:
5757
_validate_spec({})
5858
self.assertIn("requires a 'model' key", str(cm.exception))
5959

6060
def test_invalid_spec_unknown_keys(self):
61-
with self.assertRaises(InvalidSpec) as cm:
61+
with self.assertRaises(InvalidSpecError) as cm:
6262
specs_for_models([Parent], {"hello": "world"})
6363
self.assertIn("contains unknown keys: {'hello'}", str(cm.exception))
6464

@@ -394,7 +394,7 @@ def test_invalid_dumps(self):
394394
with self.assertRaises(InvalidVersionError):
395395
load_dump({"version": -1})
396396

397-
with self.assertRaises(InvalidSpec):
397+
with self.assertRaises(InvalidSpecError):
398398
load_dump(
399399
{
400400
"version": 1,

0 commit comments

Comments
 (0)