cu2qu_test: don't use 'random' to gen test curves for py23 compat, load from json file
`random.randint`, which is used in `cu2qu.benchmark.generate_curve` function, yields different results when run in Python 2.7 or 3, despite using the same `random.seed(1)`. For this reason, the `test_results_unchanged` and `test_results_unchanged_multiple` tests in `cu2qu_test` module fail when run under Python 2. Backward compatibility was broken with Python 3.2 `random` module, as a side effect of fixing a non-uniformity bug. For mor info see: https://groups.google.com/forum/#!topic/comp.lang.python/KwALjKjF6Y4 http://bugs.python.org/issue9025 To work around this, I dumped the result of generate_curve (running from Python 3.5.2 on OSX) to a json file, and use that to run the tests. I also stripped the white space to reduce the file size. ```python import random import json from cu2qu.benchmark import generate_curve random.seed(1) curves = [generate_curve() for i in range(1000)] with open("Lib/cu2qu/test/data/curves.json", "w") as fp: fp.write(json.dumps(curves).replace(" ", "")) ``` fixup
This commit is contained in:
parent
a5f93a06b9
commit
5e8f036edd
@ -18,10 +18,12 @@ from __future__ import print_function, division, absolute_import
|
||||
import collections
|
||||
import math
|
||||
import unittest
|
||||
import random
|
||||
import os
|
||||
import json
|
||||
|
||||
from cu2qu import curve_to_quadratic, curves_to_quadratic
|
||||
from cu2qu.benchmark import generate_curve
|
||||
from cu2qu.test import DATADIR
|
||||
|
||||
|
||||
MAX_ERR = 5
|
||||
|
||||
@ -31,9 +33,8 @@ class CurveToQuadraticTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""Do the curve conversion ahead of time, and run tests on results."""
|
||||
|
||||
random.seed(1)
|
||||
curves = [generate_curve() for i in range(1000)]
|
||||
with open(os.path.join(DATADIR, "curves.json"), "r") as fp:
|
||||
curves = json.load(fp)
|
||||
|
||||
cls.single_splines = [
|
||||
curve_to_quadratic(c, MAX_ERR) for c in curves]
|
||||
|
1
Lib/cu2qu/test/data/curves.json
Normal file
1
Lib/cu2qu/test/data/curves.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user