Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#7745 closed (fixed)

admin_scripts tests use assertTrue, not there in Python 2.3

Reported by: Karen Tracey <kmtracey@…> Owned by: nobody
Component: Testing framework Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

With the fix r7921 (thanks) I got past the immediate error on trying to run tests on 2.3, but hit a few more.

First the admin_scripts tests assume unittest.TestCase has an assertTrue method, but that doesn't exist in 2.3. Looking at the source it seems failUnless, which does exist in 2.3, is the same as assertTrue. Changing assertTrue to failUnless allows all the admin_scripts tests to run successfully on Python 2.3.

Second the regressiontests/utils/datastructures.py file attempts to work around the lack of sorted in 2.3 but the import is at the end of the file, which doesn't seem to work. Moving it to the top allows that test to run.

There are a couple of more failures running on 2.3 but they are unrelated to admin_scripts or sorted and I've run out of time for now so I figured I'd get these ones submitted and fixed first.

Attachments (2)

23compat.diff (1.4 KB) - added by Karen Tracey <kmtracey@…> 7 years ago.
7745-part_b.diff (1.4 KB) - added by russellm 7 years ago.
Potential patch for part b of issue report; NOTE: intentional failure in first test

Download all attachments as: .zip

Change History (12)

Changed 7 years ago by Karen Tracey <kmtracey@…>

comment:1 Changed 7 years ago by Karen Tracey <kmtracey@…>

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by russellm

(in [7941]) Refs #7745 -- Modified use of assertTrue to failUnless, because assertTrue isn't available in Python 2.3. Thanks to Karen Tracey for the report and patch.

comment:3 follow-up: Changed 7 years ago by russellm

The second part of this patch is problematic. Yes, the tests pass if you move the import to the top of the page - that's because the datastructures test isn't running any more :-)

The current setup relies upon the fact that the datastructures module has a module docstring, which means there can't be any code preceeding the docstring. There are a few other ways to restructure this test (using imports or a test variable), but I don't have a version of Python 2.3 on hand to validate these potential fixes.

comment:4 in reply to: ↑ 3 Changed 7 years ago by Karen Tracey <kmtracey@…>

Replying to russellm:

The second part of this patch is problematic. Yes, the tests pass if you move the import to the top of the page - that's because the datastructures test isn't running any more :-)

Ha! Oops.

The current setup relies upon the fact that the datastructures module has a module docstring, which means there can't be any code preceeding the docstring. There are a few other ways to restructure this test (using imports or a test variable), but I don't have a version of Python 2.3 on hand to validate these potential fixes.

Feel free to send me potential fixes and I can test them for you, since I went and got 2.3 for one of my boxes specifically to test Django on 2.3.

Changed 7 years ago by russellm

Potential patch for part b of issue report; NOTE: intentional failure in first test

comment:5 Changed 7 years ago by russellm

I've just attached a fix that works on my install. Note that I have intentionally broken one of the datastructures tests so you can be certain that the test is running.

comment:6 Changed 7 years ago by Karen Tracey <kmtracey@…>

I don't think it works...I still get a sorted failure (plus the new intentional failure):

D:\u\kmt\django\trunk\tests>\bin\Python2.3.5\python.exe runtests.py --settings=testsettings utils
======================================================================
FAIL: Doctest: regressiontests.utils.tests.__test__.datastructures
----------------------------------------------------------------------
Traceback (most recent call last):
  File "d:\u\kmt\django\trunk\django\test\_doctest.py", line 2180, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for regressiontests.utils.tests.__test__.datastructures
  File "D:\u\kmt\django\trunk\tests\regressiontests\utils\tests.py", line unknown line number, in datastructures

----------------------------------------------------------------------
File "D:\u\kmt\django\trunk\tests\regressiontests\utils\tests.py", line ?, in regressiontests.utils.tests.__test__.datastructures
Failed example:
    d.keys()
Expected:
    [7, 1, 9xxxxxxxx]
Got:
    [7, 1, 9]
----------------------------------------------------------------------
File "D:\u\kmt\django\trunk\tests\regressiontests\utils\tests.py", line ?, in regressiontests.utils.tests.__test__.datastructures
Failed example:
    sorted(real_dict.values())
Exception raised:
    Traceback (most recent call last):
      File "d:\u\kmt\django\trunk\django\test\_doctest.py", line 1267, in __run
        compileflags, 1) in test.globs
      File "<doctest regressiontests.utils.tests.__test__.datastructures[23]>", line 1, in ?
        sorted(real_dict.values())
    NameError: name 'sorted' is not defined


----------------------------------------------------------------------
Ran 11 tests in 1.662s

FAILED (failures=1)

comment:7 Changed 7 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

I think Malcolm fixed this in [8055]. Reopen if I'm wrong.

comment:8 Changed 7 years ago by Karen Tracey <kmtracey@…>

Confirmed fixed with r8057. To avoid confusion, might want to remove the sorted import attempt in tests/regressiontests/utils/datastructures.py, since it's really the one in tests/regressiontests/utils/tests.py that does the trick?

comment:9 Changed 7 years ago by mtredinnick

Good idea.

comment:10 Changed 7 years ago by mtredinnick

(In [8059]) Removed some potentially misleading code (it isn't executed) after the changes
in [8055]. Thanks, Karen. Refs #7745.

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