Commit 1075aff1 authored by Carlos Ramos Carreño's avatar Carlos Ramos Carreño Committed by Jérome Perrin

Fix CMFCategory test in Python 2.

- The warnings are compared in a set instead of a list, as we do
not care of how many times is the warning raised.
- The warning filter is added inside the context manager, as
recommended in
https://docs.python.org/2.7/library/warnings.html#testing-warnings .
- We change the `clear` method of list, using `del` instead, as the
`clear` method was added on Python 3.3.
parent a0047b4a
...@@ -1000,23 +1000,25 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -1000,23 +1000,25 @@ class TestCMFCategory(ERP5TypeTestCase):
# emitted. Because the method exists on both category and base category # emitted. Because the method exists on both category and base category
# there can be two warnings. # there can be two warnings.
with warnings.catch_warnings(record=True) as warning_list: with warnings.catch_warnings(record=True) as warning_list:
warnings.simplefilter("always")
c1.getCategoryChildValueList(local_sort_method=sort_func) c1.getCategoryChildValueList(local_sort_method=sort_func)
self.assertEqual( self.assertEqual(
[str(w.message) for w in warning_list], {str(w.message) for w in warning_list},
['`local_sort_method` argument is deprecated, use `local_sort_key` instead']) {'`local_sort_method` argument is deprecated, use `local_sort_key` instead'})
with warnings.catch_warnings(record=True) as warning_list: with warnings.catch_warnings(record=True) as warning_list:
warnings.simplefilter("always")
bc.getCategoryChildValueList(local_sort_method=sort_func) bc.getCategoryChildValueList(local_sort_method=sort_func)
self.assertEqual( self.assertEqual(
[str(w.message) for w in warning_list], {str(w.message) for w in warning_list},
['`local_sort_method` argument is deprecated, use `local_sort_key` instead'] * 2) {'`local_sort_method` argument is deprecated, use `local_sort_key` instead'})
sort_func_calls.clear() del sort_func_calls[:]
# here c1, c2, c3 are sorted by their titles # here c1, c2, c3 are sorted by their titles
self.assertEqual(list(bc.getCategoryChildValueList( self.assertEqual(list(bc.getCategoryChildValueList(
local_sort_method=sort_func)), local_sort_method=sort_func)),
[c3, c2, c1, c11, c111, c12]) [c3, c2, c1, c11, c111, c12])
self.assertTrue(sort_func_calls) self.assertTrue(sort_func_calls)
sort_func_calls.clear() del sort_func_calls[:]
# here c11 & c12 are sorted by their titles # here c11 & c12 are sorted by their titles
self.assertEqual(list(c1.getCategoryChildValueList( self.assertEqual(list(c1.getCategoryChildValueList(
local_sort_method=sort_func)), [c11, c111, c12]) local_sort_method=sort_func)), [c11, c111, c12])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment