From 8b8ac6c9feef6826b239a80217d2a29cf7791b7e Mon Sep 17 00:00:00 2001 From: Andrew Port Date: Thu, 23 Sep 2021 03:52:16 -0700 Subject: [PATCH] fix issue with test failing due to hash builtin changing in python 3.2 then again in 3.8 --- setup.py | 2 +- test/test_path.py | 33 +++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index 6b2d7a8..3375d4c 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import codecs import os -VERSION = '1.4.2' +VERSION = '1.4.1' AUTHOR_NAME = 'Andy Port' AUTHOR_EMAIL = 'AndyAPort@gmail.com' GITHUB = 'https://github.com/mathandy/svgpathtools' diff --git a/test/test_path.py b/test/test_path.py index e914224..b738292 100644 --- a/test/test_path.py +++ b/test/test_path.py @@ -1,6 +1,6 @@ # External dependencies from __future__ import division, absolute_import, print_function - +import os import sys import unittest from math import sqrt, pi @@ -741,24 +741,37 @@ class TestPath(unittest.TestCase): apath, line1, arc1, arc2, cub1, cub2, quad3, linez] # this is necessary due to changes to the builtin `hash` function - if sys.version_info.major + sys.version_info.minor < 3.8: - expected_hashes = [ - -5762846476463470127, -138736730317965290, -2005041722222729058, - 8448700906794235291, -5178990533869800243, -4003140762934044601, - 8575549467429100514, 5166859065265868968, 1373103287265872323, - -1022491904150314631, 4188352014604112779, -5090374009174854814, - -7093907105533857815, 2036243740727202243, -8108488067585685407] - else: + python_version = sys.version_info.major + 0.1*sys.version_info.minor + user_hash_seed = os.environ.get("PYTHONHASHSEED", "") + os.environ["PYTHONHASHSEED"] = "314" + if 3.8 <= python_version: expected_hashes = [ -6073024107272494569, -2519772625496438197, 8726412907710383506, 2132930052750006195, 3112548573593977871, 991446120749438306, -5589397644574569777, -4438808571483114580, -3125333407400456536, -4418099728831808951, 702646573139378041, -6331016786776229094, - 5053050772929443013, 6102272282813527681, -5385294438006156225, + 5053050772929443013, 6102272282813527681, -5385294438006156225 + ] + elif 3.2 <= python_version < 3.8: + expected_hashes = [ + -5662973462929734898, 5166874115671195563, 5223434942701471389, + -7224979960884350294, -5178990533869800243, -4003140762934044601, + 8575549467429100514, -6692132994808317852, 1594848578230132678, + -6374833902132909499, 4188352014604112779, -5090374009174854814, + -7093907105533857815, 2036243740727202243, -8108488067585685407 + ] + else: + expected_hashes = [ + -5762846476463470127, -138736730317965290, -2005041722222729058, + 8448700906794235291, -5178990533869800243, -4003140762934044601, + 8575549467429100514, 5166859065265868968, 1373103287265872323, + -1022491904150314631, 4188352014604112779, -5090374009174854814, + -7093907105533857815, 2036243740727202243, -8108488067585685407 ] for c, h in zip(test_curves, expected_hashes): self.assertTrue(hash(c) == h, msg="hash {} was expected for curve = {}".format(h, c)) + os.environ["PYTHONHASHSEED"] = user_hash_seed # restore user's hash seed def test_circle(self): arc1 = Arc(0j, 100 + 100j, 0, 0, 0, 200 + 0j)