From bb242c4b224977b5f2b397ebb253ee184555b49a Mon Sep 17 00:00:00 2001 From: Ayub khan Date: Fri, 4 Oct 2019 14:56:24 +0500 Subject: [PATCH] BOM Project Capa Module Python3 Compatibility Python3 RNG produces different results as compared to python2 In capa problems we save seed value and generate random state using the seed. Python3 random generates a different state as compared to python2. Thats why using random2 library to make state genration consistent in both python versions. --- common/lib/capa/capa/responsetypes.py | 2 +- common/lib/capa/capa/tests/test_responsetypes.py | 2 +- common/lib/capa/capa/tests/test_shuffle.py | 6 +----- requirements/edx/base.in | 1 + requirements/edx/base.txt | 1 + requirements/edx/development.txt | 1 + requirements/edx/testing.txt | 1 + 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index b0c5829d01..cd2b81fc1c 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -19,7 +19,7 @@ import inspect import json import logging import numbers -import random +import random2 as random import re import sys import textwrap diff --git a/common/lib/capa/capa/tests/test_responsetypes.py b/common/lib/capa/capa/tests/test_responsetypes.py index be9c88c13f..caeca6f07b 100644 --- a/common/lib/capa/capa/tests/test_responsetypes.py +++ b/common/lib/capa/capa/tests/test_responsetypes.py @@ -8,7 +8,7 @@ from __future__ import absolute_import import io import json import os -import random +import random2 as random import textwrap import unittest import zipfile diff --git a/common/lib/capa/capa/tests/test_shuffle.py b/common/lib/capa/capa/tests/test_shuffle.py index 42109642ca..11f8445b42 100644 --- a/common/lib/capa/capa/tests/test_shuffle.py +++ b/common/lib/capa/capa/tests/test_shuffle.py @@ -3,7 +3,6 @@ from __future__ import absolute_import, print_function import textwrap import unittest -import six from capa.responsetypes import LoncapaProblemError from capa.tests.helpers import new_loncapa_problem, test_capa_system @@ -59,10 +58,7 @@ class CapaShuffleTest(unittest.TestCase): response = list(problem.responders.values())[0] self.assertFalse(response.has_mask()) self.assertTrue(response.has_shuffle()) - if six.PY2: - self.assertEqual(response.unmask_order(), ['choice_0', 'choice_aaa', 'choice_1', 'choice_ddd']) - else: - self.assertEqual(response.unmask_order(), ['choice_1', 'choice_aaa', 'choice_0', 'choice_ddd']) + self.assertEqual(response.unmask_order(), ['choice_0', 'choice_aaa', 'choice_1', 'choice_ddd']) def test_shuffle_different_seed(self): xml_str = textwrap.dedent(""" diff --git a/requirements/edx/base.in b/requirements/edx/base.in index f5f246f617..9d53532d7f 100644 --- a/requirements/edx/base.in +++ b/requirements/edx/base.in @@ -138,6 +138,7 @@ pytz # Time zone information database PyYAML # Used to parse XModule resource templates redis==2.10.6 # celery task broker requests-oauthlib # Simplifies use of OAuth via the requests library, used for CCX and LTI +random2 rules # Django extension for rules-based authorization checks sailthru-client==2.2.3 # For Sailthru integration Shapely # Geometry library, used for image click regions in capa diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index 90ecca9ef6..6023187359 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -207,6 +207,7 @@ python3-saml==1.5.0 pytz==2019.2 pyuca==1.1 pyyaml==5.1.2 +random2==1.0.1 recommender-xblock==1.4.4 redis==2.10.6 requests-oauthlib==1.1.0 diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 339396305b..aa701d1b95 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -279,6 +279,7 @@ pytz==2019.2 pyuca==1.1 pyyaml==5.1.2 radon==4.0.0 +random2==1.0.1 recommender-xblock==1.4.4 recommonmark==0.6.0 redis==2.10.6 diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index bfe1c1ee5d..4c1220eb59 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -270,6 +270,7 @@ pytz==2019.2 pyuca==1.1 pyyaml==5.1.2 radon==4.0.0 +random2==1.0.1 recommender-xblock==1.4.4 redis==2.10.6 requests-oauthlib==1.1.0