Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#7718 closed (fixed)

sorted() is used by system tests, but isn't available on Python 2.3

Reported by: Russell Keith-Magee Owned by: Russell Keith-Magee
Component: Testing framework Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

One of the proposed patches for #7303 correctly identified that sorted() is not available under Python 2.3. sorted() is used extensively in the Django system tests as a way of removing a dependency on dict ordering.

As at [7890], the following instances exist:

tests/modeltests/basic/models.py:>>> [sorted(d.items()) for d in dicts]
tests/modeltests/or_lookups/models.py:>>> [sorted(d.items()) for d in dicts]
tests/regressiontests/admin_scripts/management/commands/app_command.py:        print 'EXECUTE:AppCommand app=%s, options=%s' % (app, sorted(options.items()))
tests/regressiontests/admin_scripts/management/commands/base_command.py:        print 'EXECUTE:BaseCommand labels=%s, options=%s' % (labels, sorted(options.items()))
tests/regressiontests/admin_scripts/management/commands/label_command.py:        print 'EXECUTE:LabelCommand label=%s, options=%s' % (label, sorted(options.items()))
tests/regressiontests/admin_scripts/management/commands/noargs_command.py:        print 'EXECUTE:NoArgsCommand options=%s' % sorted(options.items())
tests/regressiontests/defaultfilters/tests.py:>>> [sorted(dict.items()) for dict in sorted_dicts]
tests/regressiontests/defaultfilters/tests.py:>>> [sorted(dict.items()) for dict in sorted_dicts]
tests/regressiontests/model_inheritance_regress/models.py:>>> [sorted(d.items()) for d in dicts]
tests/regressiontests/model_inheritance_regress/models.py:>>> [sorted(d.items()) for d in dicts]
tests/regressiontests/model_inheritance_regress/models.py:>>> [sorted(d.items()) for d in dicts]
tests/regressiontests/model_inheritance_regress/models.py:>>> [sorted(d.items()) for d in dicts]
tests/regressiontests/model_inheritance_regress/models.py:>>> [sorted(d.items()) for d in dicts]
tests/regressiontests/model_inheritance_regress/models.py:>>> [sorted(d.items()) for d in dicts]
tests/regressiontests/model_inheritance_regress/models.py:>>> [sorted(d.items()) for d in dicts]
tests/regressiontests/queries/models.py:>>> [sorted(d.items()) for d in dicts]
tests/regressiontests/queries/models.py:>>> [sorted(d.items()) for d in dicts]
tests/regressiontests/utils/datastructures.py:>>> sorted(real_dict.values())

We could just replace the use of sorted() with sort(); a better approach (cleaner in terms of final output) would be to introduce a definition of sorted() when it is not available, much in the same way that set is imported when it is not available.

Change History (4)

comment:1 Changed 8 years ago by Russell Keith-Magee

Needs documentation: unset
Needs tests: unset
Owner: changed from nobody to Russell Keith-Magee
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by Alex Gaynor

http://dpaste.com/62777/ Here's a quick implementation, it's not tested, and I don't know where it should go, it also doesn't handle any of the other args sort() can take, I don't believe those are used in the tests though.

comment:3 Changed 8 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [7914]) Fixed #7718 -- Added a naive implementation of sorted() for Python 2.3 compatibility, and modified test cases to import the function when required.

comment:4 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top