diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-09-19 17:56:33 (GMT) |
---|---|---|
committer | Mariatta <Mariatta@users.noreply.github.com> | 2017-09-19 17:56:33 (GMT) |
commit | c6ce8fba07ea6798eac46ab2808167afecd4d90b (patch) | |
tree | adcb88010aecabc436d5a9577be7e3d67bf85cc4 /Lib/test | |
parent | 72c05e31d6127cf41bdce31bfb83fffe8d85bdd7 (diff) | |
download | cpython-c6ce8fba07ea6798eac46ab2808167afecd4d90b.zip cpython-c6ce8fba07ea6798eac46ab2808167afecd4d90b.tar.gz cpython-c6ce8fba07ea6798eac46ab2808167afecd4d90b.tar.bz2 |
[3.6] bpo-31482: Missing bytes support for random.seed() version 1 (GH-3614) (GH-3659)
(cherry picked from commit 132a7d7cdbc7cb89fa1c1f4e8192241c3d68f549)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_random.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index 03adc0a..a2d9a96 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -423,6 +423,33 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase): ['0x1.b0580f98a7dbep-1', '0x1.84129978f9c1ap-1', '0x1.aeaa51052e978p-2', '0x1.092178fb945a6p-2']) + def test_bug_31482(self): + # Verify that version 1 seeds are unaffected by hash randomization + # when the seeds are expressed as bytes rather than strings. + # The hash(b) values listed are the Python2.7 hash() values + # which were used for seeding. + + self.gen.seed(b'nofar', version=1) # hash('nofar') == 5990528763808513177 + self.assertEqual([self.gen.random().hex() for i in range(4)], + ['0x1.8645314505ad7p-1', '0x1.afb1f82e40a40p-5', + '0x1.2a59d2285e971p-1', '0x1.56977142a7880p-6']) + + self.gen.seed(b'rachel', version=1) # hash('rachel') == -9091735575445484789 + self.assertEqual([self.gen.random().hex() for i in range(4)], + ['0x1.0b294cc856fcdp-1', '0x1.2ad22d79e77b8p-3', + '0x1.3052b9c072678p-2', '0x1.578f332106574p-3']) + + self.gen.seed(b'', version=1) # hash('') == 0 + self.assertEqual([self.gen.random().hex() for i in range(4)], + ['0x1.b0580f98a7dbep-1', '0x1.84129978f9c1ap-1', + '0x1.aeaa51052e978p-2', '0x1.092178fb945a6p-2']) + + b = b'\x00\x20\x40\x60\x80\xA0\xC0\xE0\xF0' + self.gen.seed(b, version=1) # hash(b) == 5015594239749365497 + self.assertEqual([self.gen.random().hex() for i in range(4)], + ['0x1.52c2fde444d23p-1', '0x1.875174f0daea4p-2', + '0x1.9e9b2c50e5cd2p-1', '0x1.fa57768bd321cp-2']) + def test_setstate_first_arg(self): self.assertRaises(ValueError, self.gen.setstate, (1, None, None)) |