test/gen_testdata: Retrieve object keys in predictable order independent of python version
gen_testdata.py picks up root keys randomly and shuffles extension dict keys also randomly. But even with predictable PRNG if the input to e.g. rand.choice is different, the result will be different as well. So far we were lucky: we were running gen_testdata.py only via py2 and the order of retrieved root keys was - by chance - the same each time. That's why generated testdata databases were the same after each gen_testdata.py run. But even on py2 there is no such guaranty and when runnning gen_testdata.py via py3 the order of keys is really different: $ python2 Python 2.7.18 (default, Jul 14 2021, 08:11:37) [GCC 10.2.1 20210110] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> d = {} >>> d['a'] = 1 >>> d['b'] = 2 >>> d['c'] = 3 >>> d.keys() ['a', 'c', 'b'] $ python3 Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> d = {} >>> d['a'] = 1 >>> d['b'] = 2 >>> d['c'] = 3 >>> list(d.keys()) ['a', 'b', 'c'] So let's prepare for py3 generation beforehand by making sure that keys input to PRNG is the same be it py2 or py3, thus, giving a chance for generated py2/py3 databases to be really close to each other. Since here we change the order of keys that are feed to PRNG generated test databases are shuffled a bit.
Showing
No preview for this file type
No preview for this file type
No preview for this file type
This diff is collapsed.
No preview for this file type
No preview for this file type
No preview for this file type
This diff is collapsed.
Please register or sign in to comment