summaryrefslogtreecommitdiff
path: root/tests/model_enums/tests.py
AgeCommit message (Collapse)Author
2025-01-20Fixed #36005 -- Dropped support for Python 3.10 and 3.11.Mariusz Felisiak
2025-01-15Removed ChoicesMeta per deprecation timeline.Sarah Boyce
2024-08-28Fixed #35666 -- Documented stacklevel usage and testing, and adjusted test ↵Simon Charette
suite accordingly. Over the years we've had multiple instances of hit and misses when emitting warnings: either setting the wrong stacklevel or not setting it at all. This work adds assertions for the existing warnings that were declaring the correct stacklevel, but were lacking tests for it.
2023-11-29Refs #34986 -- Removed redundant CustomChoicesTests.test_timezone_unsupported().Nick Pope
This test relied on the behavior of subclassing `datetime.timezone` which is not permitted by the C-extension version of CPython's `datetime` module. This restriction isn't enforced by the pure Python version, nor by PyPy. See https://github.com/python/cpython/issues/112451 It's not critical, and doesn't test any Django behavior, so just remove it.
2023-09-13Modernized enumeration helpers on Python 3.11+.Nick Pope
- use @enum.property https://docs.python.org/3/library/enum.html#enum.property - use @enum.nonmember Using @property on an enum class does not yield the expected result. do_not_call_in_templates attribute works because a @property instance is truthy. We can make this a literal True value as expected by using @enum.nonmember in Python 3.11+. https://docs.python.org/3/library/enum.html#enum.nonmember - used enum.IntEnum/StrEnum Python 3.11+ has ReprEnum which uses int.__str__() and str.__str__() for __str__() in the `IntEnum` and `StrEnum` subclasses. We can emulate that for Python < 3.11. https://docs.python.org/3/library/enum.html#enum.ReprEnum https://docs.python.org/3/library/enum.html#enum.IntEnum https://docs.python.org/3/library/enum.html#enum.StrEnum
2023-09-12Renamed ChoicesMeta to ChoicesType.Nick Pope
This also uses enum.EnumType for Python 3.11+ as Python 3.11 renamed EnumMeta to EnumType. While the former is still available as an alias of the latter for now, let's prefer the canonical name for this. Check out https://docs.python.org/3/library/enum.html#enum.EnumType
2023-04-07Refs #34118 -- Fixed CustomChoicesTests.test_uuid_unsupported on Python 3.11.4+.Mariusz Felisiak
https://github.com/python/cpython/commit/5342f5e713e0cc45b6f226d2d053a8cde1b4d68e Follow up to 38e63c9e61152682f3ff982c85a73793ab6d3267.
2023-04-05Refs #34118 -- Fixed CustomChoicesTests.test_uuid_unsupported on Python 3.12+.Mariusz Felisiak
https://github.com/python/cpython/commit/2a4d8c0a9e88f45047da640ce5a92b304d2d39b1
2022-02-07Refs #33476 -- Reformatted code with Black.django-bot
2021-04-07Refs #32074 -- Backported Enum.__repr__() from Python 3.10.Mariusz Felisiak
Enum.__repr__() was changed in [1], we should use the same format in Python < 3.10. [1] https://bugs.python.org/issue40066
2021-03-24Fixed #32460 -- Allowed "label"/"do_not_call_in_templates" members in model ↵Nick Pope
choice enums.
2021-03-24Refs #32460 -- Doc'd and tested that property names of model choice enums ↵Nick Pope
cannot be used as members.
2020-01-10Fixed #31154 -- Added support for using enumeration types in templates.Adam Johnson
Enumeration helpers are callables, so the template system tried to call them with no arguments. Thanks Rupert Baker for helping discover this.
2019-10-29Used more specific unittest assertions in tests.Nick Pope
* assertIsNone()/assertIsNotNone() instead of comparing to None. * assertLess() for < comparisons. * assertIs() for 'is' expressions. * assertIsInstance() for isinstance() expressions. * rounding of assertAlmostEqual() for round() expressions. * assertIs(..., True/False) instead of comparing to True/False. * assertIs()/assertIsNot() for ==/!= comparisons. * assertNotEqual() for == comparisons. * assertTrue()/assertFalse() instead of comparing to True/False.
2019-10-25Fixed #30902 -- Added __str__() for model choice enums.Carlton Gibson
Allows expected behavior when cast to str, also matching behaviour of created instances with those fetched from the DB. Thanks to Simon Charette, Nick Pope, and Shai Berger for reviews.
2019-09-04Fixed #27910 -- Added enumeration helpers for use in Field.choices.Shai Berger
These classes can serve as a base class for user enums, supporting translatable human-readable names, or names automatically inferred from the enum member name. Additional properties make it easy to access the list of names, values and display labels. Thanks to the following for ideas and reviews: Carlton Gibson, Fran Hrženjak, Ian Foote, Mariusz Felisiak, Shai Berger. Co-authored-by: Shai Berger <shai@platonix.com> Co-authored-by: Nick Pope <nick.pope@flightdataservices.com> Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>