Commit 153c3193 authored by Stefan Behnel's avatar Stefan Behnel

fix test behaviour that varies depending on CPython version and py_debug setting

parent f00fd1de
...@@ -204,7 +204,6 @@ VER_DEP_MODULES = { ...@@ -204,7 +204,6 @@ VER_DEP_MODULES = {
'run.relativeimport_star_T542', 'run.relativeimport_star_T542',
'run.initial_file_path', # relative import 'run.initial_file_path', # relative import
'run.pynumber_subtype_conversion', # bug in Py2.4 'run.pynumber_subtype_conversion', # bug in Py2.4
'run.dict_setdefault',
]), ]),
(2,6) : (operator.lt, lambda x: x in ['run.print_function', (2,6) : (operator.lt, lambda x: x in ['run.print_function',
'run.language_level', # print function 'run.language_level', # print function
......
...@@ -48,16 +48,22 @@ def setdefault1(d, key): ...@@ -48,16 +48,22 @@ def setdefault1(d, key):
2 2
>>> d[Hashable()] >>> d[Hashable()]
>>> hashed1 = CountedHashable() # CPython's behaviour depends on version and py_debug setting, so just compare to it
>>> y = {hashed1: 5} >>> py_hashed1 = CountedHashable()
>>> hashed2 = CountedHashable() >>> y = {py_hashed1: 5}
>>> setdefault1(y, hashed2) >>> py_hashed2 = CountedHashable()
>>> hashed1.hash_count >>> y.setdefault(py_hashed2)
1
>>> hashed2.hash_count >>> cy_hashed1 = CountedHashable()
1 >>> y = {cy_hashed1: 5}
>>> hashed1.eq_count + hashed2.eq_count >>> cy_hashed2 = CountedHashable()
1 >>> setdefault1(y, cy_hashed2)
>>> py_hashed1.hash_count - cy_hashed1.hash_count
0
>>> py_hashed2.hash_count - cy_hashed2.hash_count
0
>>> (py_hashed1.eq_count + py_hashed2.eq_count) - (cy_hashed1.eq_count + cy_hashed2.eq_count)
0
""" """
return d.setdefault(key) return d.setdefault(key)
...@@ -95,16 +101,23 @@ def setdefault2(d, key, value): ...@@ -95,16 +101,23 @@ def setdefault2(d, key, value):
>>> d[Hashable()] >>> d[Hashable()]
55 55
>>> hashed1 = CountedHashable() # CPython's behaviour depends on version and py_debug setting, so just compare to it
>>> y = {hashed1: 5} >>> py_hashed1 = CountedHashable()
>>> hashed2 = CountedHashable() >>> y = {py_hashed1: 5}
>>> setdefault2(y, hashed2, []) >>> py_hashed2 = CountedHashable()
>>> y.setdefault(py_hashed2, [])
[] []
>>> hashed1.hash_count
1 >>> cy_hashed1 = CountedHashable()
>>> hashed2.hash_count >>> y = {cy_hashed1: 5}
1 >>> cy_hashed2 = CountedHashable()
>>> hashed1.eq_count + hashed2.eq_count >>> setdefault2(y, cy_hashed2, [])
1 []
>>> py_hashed1.hash_count - cy_hashed1.hash_count
0
>>> py_hashed2.hash_count - cy_hashed2.hash_count
0
>>> (py_hashed1.eq_count + py_hashed2.eq_count) - (cy_hashed1.eq_count + cy_hashed2.eq_count)
0
""" """
return d.setdefault(key, value) return d.setdefault(key, value)
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