Edgewall Software
Modify

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#11284 closed enhancement (fixed)

Replace deprecated unittest method aliases

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: low Milestone: 1.0.2
Component: general Version: 1.0-stable
Severity: normal Keywords: unit tests
Cc: Branch:
Release Notes:

Replaced deprecated unit test method aliases, and refactored unit tests to utilize new methods in trac.tests.compat.

API Changes:

The trac.tests.compat module adds methods to unittest.TestCase that are available in Python 2.7, such as assertIn and assertIs. To make the methods available in a test suite module, add from trac.tests import compat.

Internal Changes:

Description

Several unittest method aliases are deprecated since Python 2.7. Although it is not necessary to make the changes now, it seems like a good step toward making the codebase more readable, and better to make all the changes at once.

Attachments (0)

Change History (16)

comment:1 by Ryan J Ollos, 11 years ago

Changes prepared in rjollos.git:t11284. I'll probably make another pass through and try to clean up some of the logic, like what was done in 237f3ea8/rjollos.git.

Last edited 11 years ago by Ryan J Ollos (previous) (diff)

comment:2 by Jun Omae, 11 years ago

Additionally, it would be good to add trac.tests.compat module rather than adding test functions in each testcase class. The module provides test functions since 2.7 for backwards-compatibility with 2.5-2.6. The changes is in [f8a7f571/jomae.git].

in reply to:  2 comment:3 by Ryan J Ollos, 11 years ago

Replying to jomae:

… The changes is in [f8a7f571/jomae.git].

That looks great! I was hoping there was a nice way to accomplish that without subclassing unittest.TestCase, but I didn't see the way until you showed me.

If you decide to push those change to the trunk soon that would work fine, otherwise I can push them after I finish refactoring some of the unit tests this coming weekend.

comment:4 by Ryan J Ollos, 11 years ago

Not sure what is going on yet, but trac.mimeview.tests.pygments can't be executed in isolation:

user@ubuntu:~/Workspace/trac-1.0-stable$ PYTHONPATH=. python trac/mimeview/tests/pygments.py
Traceback (most recent call last):
  File "trac/mimeview/tests/pygments.py", line 21, in <module>
    pygments = __import__('pygments', {}, {}, [])
  File "/home/user/Workspace/trac-1.0-stable/trac/mimeview/tests/pygments.py", line 28, in <module>
    from trac.mimeview.pygments import PygmentsRenderer
  File "/home/user/Workspace/trac-1.0-stable/trac/mimeview/pygments.py", line 35, in <module>
    get_all_lexers = pygments.lexers.get_all_lexers
AttributeError: 'module' object has no attribute 'lexers'

comment:5 by Ryan J Ollos, 11 years ago

Latest proposed changes can be found in rjollos.git:t11284.2.

in reply to:  5 comment:6 by Jun Omae, 11 years ago

Replying to rjollos:

Not sure what is going on yet, but trac.mimeview.tests.pygments can't be executed in isolation:

Try like this:

$ PYTHONPATH=. ~/venv/py25/bin/python -m trac.mimeview.tests.pygments
.....
----------------------------------------------------------------------
Ran 5 tests in 0.427s

OK

Replying to rjollos:

Latest proposed changes can be found in rjollos.git:t11284.2.

LGTM, verified with Python 2.5-2.7.

comment:7 by Ryan J Ollos, 11 years ago

API Changes: modified (diff)
Milestone: 1.0.2
Priority: normallow
Release Notes: modified (diff)
Resolution: fixed
Status: newclosed

Committed to 1.0-stable in [12070:12079] and merged to trunk in [12080].

comment:8 by Ryan J Ollos, 11 years ago

Owner: set to Ryan J Ollos

comment:9 by Ryan J Ollos, 11 years ago

API Changes: modified (diff)
Release Notes: modified (diff)

comment:10 by Jun Omae, 11 years ago

I've found missing use of trac.tests.compat in tracopt/versioncontrol/svn/tests/svn_fs.py. Fixed in [12104] and merged into trunk in [12105].

$ PYTHONPATH=. ~/venv/py25/bin/python ./tracopt/versioncontrol/svn/tests/svn_fs.py
.........................E........EE..............EE.........................E........EE..............EE..........E................E..........E.................EE....
======================================================================
ERROR: test_get_dir_content (__main__.SubversionRepositoryNormalTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./tracopt/versioncontrol/svn/tests/svn_fs.py", line 200, in test_get_dir_content
    self.assertIsNone(node.content_length)
AttributeError: 'SubversionRepositoryNormalTests' object has no attribute 'assertIsNone'
...
----------------------------------------------------------------------
Ran 166 tests in 35.618s

FAILED (errors=15)

comment:11 by Ryan J Ollos, 11 years ago

Regression from [12078] raised in #11312 has been fixed on 1.0-stable in [12115] and merged to trunk in [12116].

comment:12 by Ryan J Ollos, 11 years ago

Keywords: unit tests added

comment:13 by Ryan J Ollos, 11 years ago

Keywords: unittest removed

comment:14 by Ryan J Ollos, 11 years ago

I've ended up with a mix of the following two statements in the codebase:

[12080]:

from trac.tests import compat

[12710], [12456]:

import trac.tests.compat

The latter seems to be better in order to emphasize that we are importing a module but not using any specific functions from it. The former could be confused with the import of a function.

in reply to:  14 comment:15 by Jun Omae, 11 years ago

import trac.tests.compat

The latter seems to be better in order to emphasize that we are importing a module but not using any specific functions from it. The former could be confused with the import of a function.

Yes. I agreed.

comment:16 by Ryan J Ollos, 11 years ago

Changes to imports committed to 1.0-stable in [12747], merged to trunk in [12748].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.