From e9c4c22e6a116c1ed8def1358d1c82e8d08c12d9 Mon Sep 17 00:00:00 2001 From: Ayub khan Date: Thu, 10 Oct 2019 12:36:05 +0500 Subject: [PATCH] BOM fixed remaining capa module issues BOM-898 fix test_responsetypes.py issues Updated safe_exec to use random2 library instead of random. As python3 random generates different results as compared to python2, which causes a lot of test failures and if we use python3 random and fix tests it will cause state invalidation of capa problems, So random2 was uses to make the behaviour same in python3. BOM-899 name xrange is not defined xrange is used in safe_exec and there might be old courses where this is being used in capa problems. All those tests fail in python3 as this was renamed to range. Used six.moves.xrange so that code works for python3 and if there is any old code using xrange it works too. --- common/lib/capa/capa/safe_exec/safe_exec.py | 4 +++- common/lib/capa/capa/safe_exec/tests/test_safe_exec.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/common/lib/capa/capa/safe_exec/safe_exec.py b/common/lib/capa/capa/safe_exec/safe_exec.py index 1d893f14f3..52e676e9fa 100644 --- a/common/lib/capa/capa/safe_exec/safe_exec.py +++ b/common/lib/capa/capa/safe_exec/safe_exec.py @@ -21,8 +21,10 @@ from __future__ import absolute_import, division import os os.environ["OPENBLAS_NUM_THREADS"] = "1" # See TNL-6456 -import random as random_module +import random2 as random_module import sys +from six.moves import xrange + random = random_module.Random(%r) random.Random = random_module.Random sys.modules['random'] = random diff --git a/common/lib/capa/capa/safe_exec/tests/test_safe_exec.py b/common/lib/capa/capa/safe_exec/tests/test_safe_exec.py index a53184fc3e..e845cd892b 100644 --- a/common/lib/capa/capa/safe_exec/tests/test_safe_exec.py +++ b/common/lib/capa/capa/safe_exec/tests/test_safe_exec.py @@ -5,7 +5,7 @@ from __future__ import absolute_import import hashlib import os import os.path -import random +import random2 as random import textwrap import unittest