annotate test/test_misc.py @ 5414:3fa026621f69

Python 3 preparation: comparisons. Python 3 no longer has the cmp function, or cmp= arguments to sorting functions / methods (key= must be used instead), and requires rich comparison methods such as __lt__ to be defined instead of using __cmp__. All of the comparison mechanisms supported in Python 3 are also supported in Python 2. This patch makes the corresponding changes in Roundup to use key functions and rich comparison methods. In the case of the JournalPassword and Permission classes, only __eq__ and __ne__ are defined as I don't see ordered comparisons as useful there (and for Permission, the old __cmp__ function didn't try to provide a valid ordering). In the case of the Date class, I kept the __cmp__ method and implemented the others in terms of it, to avoid excess repetitiveness in duplicating implementation code for all six rich comparison methods. In roundup/admin.py, help_commands_html used operator.attrgetter to produce the second argument of sorted() - which would be reasonable for a key function, but the second argument is the cmp function in Python 2, not a key function (and the key function must be a named argument not a positional argument in Python 3). That function appears to be completely unused, so I expect that code never worked. This patch adds the missing key= to that sorted() call, but it would also be reasonable to remove the unused function completely instead.
author Joseph Myers <jsm@polyomino.org.uk>
date Wed, 25 Jul 2018 00:39:37 +0000
parents e1e3531b4d9b
children 9a09719b0d8e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5155
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
1 # misc tests
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
2
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
3 import unittest
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
4 from roundup.cgi.accept_language import parse
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
5
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
6 class AcceptLanguageTest(unittest.TestCase):
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
7 def testParse(self):
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
8 self.assertEqual(parse("da, en-gb;q=0.8, en;q=0.7"),
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
9 ['da', 'en_gb', 'en'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
10 self.assertEqual(parse("en;q=0.2, fr;q=1"), ['fr', 'en'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
11 self.assertEqual(parse("zn; q = 0.2 ,pt-br;q =1"), ['pt_br', 'zn'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
12 self.assertEqual(parse("es-AR"), ['es_AR'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
13 self.assertEqual(parse("es-es-cat"), ['es_es_cat'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
14 self.assertEqual(parse(""), [])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
15 self.assertEqual(parse(None),[])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
16 self.assertEqual(parse(" "), [])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
17 self.assertEqual(parse("en,"), ['en'])

Roundup Issue Tracker: http://roundup-tracker.org/