Issue1998

classification
Title: test_dict.py makes incorrect assumption about dict ordering
Type: behaviour Severity: normal
Components: Versions: Jython 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: fwierzbicki Nosy List: amak, csebasha, fwierzbicki, geraint, zyasoft
Priority: normal Keywords:

Created on 2012-12-21.07:49:35 by geraint, last changed 2014-05-22.02:03:32 by zyasoft.

Messages
msg7549 (view) Author: Geraint Jones (geraint) Date: 2012-12-21.07:49:34
Test test_dict.py passed when using Java 7 - I tried Oracle's and IBM's.

However, when I use Java 8, it fails.

I believe test_dict.py is not a good test because it assumes that 2 adjacent dicts (hashes) will, if populated with the same key/value pairs in the same order, return those values in the same order.

For example, populating both dict_a and dict_b with values 3, 1, 2, 7, 6, 5, 4, and 0, using the value as the key (i.e. key=value in each tuple), it assumes that both dict_a and dict_b will both be the same.

I observed that this is the case when using Java 7 - both dicts are the same.

I also observed that using Python instead of Jython, not only are both dicts the same, but they are both ordered in ascending key sequence.

However, they are not the same with Java 8, as illustrated by one set of results I saw:

  dict_a  {3: 3, 6: 6, 0: 0, 4: 4, 1: 1, 5: 5, 2: 2, 7: 7}
  dict_b  {5: 5, 6: 6, 3: 3, 2: 2, 1: 1, 7: 7, 4: 4, 0: 0}


It is my understanding that a dict is a hash, and that the order of hashes is not specified and should not be assumed.

The fact that test_dict.py makes an assumption about the ordering means that it is not a reliable test and should be removed.
msg7649 (view) Author: Alan Kennedy (amak) Date: 2013-02-09.13:56:43
It is indeed the case that ordering of keys should not be relied on. This is the behaviour of the original cpython test, and we target getting all cpython tests to pass on jython. This ordering assumption makes the test non-portable to jython, especially when it is run on different JVMs, as you have found.

Frank Wierzbicki is in the process of fixing these in cpython, so that we don't have to have specialised versions of the tests.

Doctests in test_dictcomp depend on dict order
http://bugs.python.org/issue16886
msg7652 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-09.17:54:36
Usually this happens when there are doctests involved - as in the test that Alan pointed out. test_dict though doesn't include any doctests, and my scanning of the test doesn't have any of these popping out at me. Would you mind posting the specific tests that fail for you so I can have a better look? Also have you seen the same behavior on 2.7 (the default branch) dict_test looks like it mainly has cosmetic changes so presumably the problem would persist.
msg8550 (view) Author: Jim Baker (zyasoft) Date: 2014-05-22.02:03:32
All tests in test_dict pass on Java 8 for Jython 2.7 trunk. (Changing the version for this, I don't see us updating 2.5 for this scenario.)

We should also remove our own version of test_dict - the CPython one works fine, since it has appropriate skips.
History
Date User Action Args
2014-05-22 02:03:32zyasoftsetstatus: open -> closed
resolution: fixed
messages: + msg8550
nosy: + zyasoft
versions: + Jython 2.7, - Jython 2.5
2013-02-25 19:11:13fwierzbickisetversions: + Jython 2.5, - 2.5.2
2013-02-09 17:54:54fwierzbickisetpriority: normal
assignee: fwierzbicki
2013-02-09 17:54:36fwierzbickisetmessages: + msg7652
2013-02-09 13:56:44amaksetnosy: + amak, fwierzbicki
messages: + msg7649
2012-12-21 15:43:18csebashasetnosy: + csebasha
2012-12-21 07:49:35geraintcreate