django-timezone-field
django-timezone-field copied to clipboard
Sort choices to make it easier to select
The sorting is applied to both standard and GMT choices.
Close #116
Strengthen edge cases sorting in standard and proper GMT sorting (alpha sort does not result in a natural order with -xx:xx and +xx:xx). Fix testing to reflect the sorting. Issues:
- testing all the values as they're read from the backend (unordered) does not work, those two tests were dropped. I suspect they would make more sense as a separate test.
- There's still a problem with
tests.test_deconstruct:test_specifying_defaults_not_frozen()
, I don't think I impacted that test and don't understand the use case.
Hi,
Merge this pls.
thanks.
Let me refresh my memory on the code, I'll try to get this done quickly to keep the momentum.
@mfogel I found a good way to re-introduce the assert in both tests. I use sorted for speed and Counter (slower but required for non sortable elements) to validate the test.
Running the test through poetry, I found another test failing (tests/test_deconstruct.py:80
) but I don't think it was caused by my changes.
Awesome, thank you for all that @hrbonz
I fixed the codecov token issue on main
. The tests are fully passing there - even that one you noticed is still failing. Can you rebase this on the latest on main
, and then we can try to figure out what's up with that final failing test?
Hi @hrbonz, can you rebase? Thanks for your time.
@mfogel @paulocoutinhox rebased and the same test is still failing.
Here's the failing test:
___________________________________ test_specifying_defaults_not_frozen[zoneinfo] ____________________________________
use_pytz = False
to_tzobj = <bound method ZoneInfoBackend.to_tzobj of <timezone_field.backends.zoneinfo.ZoneInfoBackend object at 0x7f8343ef3a60>>
base_tzstrs = {'Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', 'Africa/Algiers', 'Africa/Asmara', 'Africa/Asmera', ...}
def test_specifying_defaults_not_frozen(use_pytz, to_tzobj, base_tzstrs):
"""
If someone's matched the default values with their kwarg args, we
shouldn't bothering freezing those
(excluding the use_pytz, which changes with your django version).
"""
field = TimeZoneField(max_length=63)
_name, _path, _args, kwargs = field.deconstruct()
assert "max_length" not in kwargs
choices = [(to_tzobj(tz), tz.replace("_", " ")) for tz in base_tzstrs]
field = TimeZoneField(choices=choices, use_pytz=use_pytz)
_name, _path, _args, kwargs = field.deconstruct()
> assert "choices" not in kwargs
E AssertionError: assert 'choices' not in {'choices': [('Pacific/Funafuti', 'Pacific/Funafuti'), ('America/Panama', 'America/Panama'), ('America/Port_of_Spain',...ersey'), ('Indian/Kerguelen', 'Indian/Kerguelen'), ('America/Goose_Bay', 'America/Goose Bay'), ...], 'use_pytz': False}
tests/test_deconstruct.py:78: AssertionError
From verbose run:
tests/test_deconstruct.py::test_specifying_defaults_not_frozen[pytz] PASSED [ 57%]
tests/test_deconstruct.py::test_specifying_defaults_not_frozen[zoneinfo] FAILED [ 57%]
I did another pass on my code and can't find a reason for my changes to break this test.
For information, here's my environment:
$ python -V
Python 3.9.2
$ pip freeze --local
asgiref==3.7.2
astroid==2.15.8
asttokens==2.4.1
attrs==23.1.0
black==23.11.0
build==1.0.3
CacheControl==0.13.1
certifi==2023.11.17
cffi==1.16.0
charset-normalizer==3.3.2
cleo==2.1.0
click==8.1.7
coverage==6.5.0
crashtest==0.4.1
cryptography==41.0.7
decorator==5.1.1
dill==0.3.7
distlib==0.3.8
Django==4.2.7
-e git+ssh://[email protected]/hrbonz/django-timezone-field.git@9bcf0ef0cee90b246fb45483b73a7aeb865bf96f#egg=django_timez
one_field
djangorestframework==3.14.0
dulwich==0.21.7
exceptiongroup==1.2.0
executing==2.0.1
fastjsonschema==2.19.1
filelock==3.13.1
flake8==5.0.4
idna==3.6
importlib-metadata==7.0.1
iniconfig==2.0.0
installer==0.7.0
ipdb==0.13.13
ipython==8.18.1
isort==5.12.0
jaraco.classes==3.3.0
jedi==0.19.1
jeepney==0.8.0
keyring==24.3.0
lazy-object-proxy==1.9.0
matplotlib-inline==0.1.6
mccabe==0.7.0
more-itertools==10.2.0
msgpack==1.0.7
mypy-extensions==1.0.0
packaging==23.2
parso==0.8.3
pathspec==0.11.2
pexpect==4.9.0
pkginfo==1.9.6
platformdirs==4.0.0
pluggy==1.3.0
poetry==1.7.1
poetry-core==1.8.1
poetry-plugin-export==1.6.0
prompt-toolkit==3.0.43
psycopg2-binary==2.9.9
ptyprocess==0.7.0
pure-eval==0.2.2
py==1.11.0
pycodestyle==2.9.1
pycparser==2.21
pyflakes==2.5.0
Pygments==2.17.2
pylint==2.17.7
pyproject_hooks==1.0.0
pytest==6.2.5
pytest-cov==3.0.0
pytest-django==4.5.2
pytest-lazy-fixture==0.6.3
pytest-pythonpath==0.7.4
pytz==2023.3.post1
rapidfuzz==3.6.1
requests==2.31.0
requests-toolbelt==1.0.0
SecretStorage==3.3.3
shellingham==1.5.4
six==1.16.0
sqlparse==0.4.4
stack-data==0.6.3
toml==0.10.2
tomli==2.0.1
tomlkit==0.12.3
traitlets==5.14.1
trove-classifiers==2024.1.8
typing_extensions==4.8.0
tzdata==2023.3
urllib3==2.1.0
virtualenv==20.25.0
wcwidth==0.2.13
wrapt==1.16.0
zipp==3.17.0
Thanks for rebasing. I should have time to dig into this this weekend.
Looks like there's still an issue with codecov
Ok, I've fixed that failing test... it was implicitly depending on the sort order of the choices
. The remaining failures are all uploads to codecov, and I'm confident they will pass once on main
(famous last words).
Thanks a bunch for the contribution @hrbonz ! Merging in now
@mfogel do we have a minor release for that fix or can we have one ? :)
Yes - please can we have a release for this.
PLS!!!
Yup sorry for the delay. I'm planning to get a new release out this weekend.
Yay, can't wait!
Ok I just released v7.0 to pypi. Please open an issue if you run across any issue upgrading to it, thanks!