Fix tests that depend on execution order
This commit is contained in:
@@ -34,15 +34,23 @@ class TestLazyMod(unittest.TestCase):
|
||||
|
||||
def test_simple(self):
|
||||
# Import some stdlib module that has not been imported before
|
||||
self.assertNotIn("colorsys", sys.modules)
|
||||
colorsys = LazyModule("colorsys")
|
||||
module_name = 'colorsys'
|
||||
if module_name in sys.modules:
|
||||
# May have been imported during test discovery, remove it again
|
||||
del sys.modules[module_name]
|
||||
assert module_name not in sys.modules
|
||||
colorsys = LazyModule(module_name)
|
||||
hsv = colorsys.rgb_to_hsv(.3, .4, .2)
|
||||
self.assertEqual(hsv[0], 0.25)
|
||||
|
||||
def test_dotted(self):
|
||||
# wsgiref is a module with submodules that is not already imported.
|
||||
# Any similar module would do. This test demonstrates that the module
|
||||
# is not already im
|
||||
self.assertNotIn("wsgiref.util", sys.modules)
|
||||
wsgiref_util = LazyModule("wsgiref.util")
|
||||
# is not already imported
|
||||
module_name = 'wsgiref.util'
|
||||
if module_name in sys.modules:
|
||||
# May have been imported during test discovery, remove it again
|
||||
del sys.modules[module_name]
|
||||
assert module_name not in sys.modules
|
||||
wsgiref_util = LazyModule(module_name)
|
||||
self.assertEqual(wsgiref_util.guess_scheme({}), "http")
|
||||
|
||||
@@ -7,6 +7,8 @@ import unittest
|
||||
import ddt
|
||||
import mock
|
||||
import os
|
||||
# Changes formatting of empty elements; import here to avoid test order dependence
|
||||
import xmodule.modulestore.xml # pylint: disable=unused-import
|
||||
from capa.tests.helpers import test_capa_system, new_loncapa_problem
|
||||
from lxml import etree
|
||||
from openedx.core.djangolib.markup import HTML
|
||||
@@ -303,7 +305,7 @@ class CapaHtmlRenderTest(unittest.TestCase):
|
||||
|
||||
# Render the HTML
|
||||
the_html = problem.get_html()
|
||||
self.assertRegexpMatches(the_html, r"<div>\s+</div>")
|
||||
self.assertRegexpMatches(the_html, r"<div/>")
|
||||
|
||||
def _create_test_file(self, path, content_str):
|
||||
test_fp = self.capa_system.filestore.open(path, "w")
|
||||
|
||||
@@ -5,6 +5,8 @@ i.e. those with the <multiplechoiceresponse> element
|
||||
|
||||
import unittest
|
||||
import textwrap
|
||||
# Changes formatting of empty elements; import here to avoid test order dependence
|
||||
import xmodule.modulestore.xml # pylint: disable=unused-import
|
||||
from capa.tests.helpers import test_capa_system, new_loncapa_problem, load_fixture
|
||||
|
||||
|
||||
@@ -188,14 +190,14 @@ class CapaTargetedFeedbackTest(unittest.TestCase):
|
||||
problem.done = True
|
||||
problem.student_answers = {'1_2_1': 'choice_0'}
|
||||
the_html = problem.get_html()
|
||||
self.assertRegexpMatches(the_html, r"<targetedfeedbackset>\s*</targetedfeedbackset>")
|
||||
self.assertRegexpMatches(the_html, r"<targetedfeedbackset/>")
|
||||
|
||||
# New problem with same XML -- try the correct choice.
|
||||
problem = new_loncapa_problem(xml_str)
|
||||
problem.done = True
|
||||
problem.student_answers = {'1_2_1': 'choice_2'} # correct
|
||||
the_html = problem.get_html()
|
||||
self.assertRegexpMatches(the_html, r"<targetedfeedbackset>\s*</targetedfeedbackset>")
|
||||
self.assertRegexpMatches(the_html, r"<targetedfeedbackset/>")
|
||||
|
||||
def test_targeted_feedback_no_solution_element(self):
|
||||
xml_str = textwrap.dedent("""
|
||||
@@ -579,8 +581,7 @@ class CapaTargetedFeedbackTest(unittest.TestCase):
|
||||
# Q1 and Q2 have no feedback
|
||||
self.assertRegexpMatches(
|
||||
without_new_lines,
|
||||
r'<targetedfeedbackset.*?>\s*</targetedfeedbackset>.*' +
|
||||
r'<targetedfeedbackset.*?>\s*</targetedfeedbackset>'
|
||||
r'<targetedfeedbackset.*?/>.*<targetedfeedbackset.*?/>'
|
||||
)
|
||||
|
||||
def test_targeted_feedback_multiple_answer_1(self):
|
||||
@@ -593,7 +594,7 @@ class CapaTargetedFeedbackTest(unittest.TestCase):
|
||||
self.assertRegexpMatches(
|
||||
without_new_lines,
|
||||
r'<targetedfeedbackset.*?>.*?explanation-id="feedback1".*?</targetedfeedbackset>.*' +
|
||||
r'<targetedfeedbackset.*?>\s*</targetedfeedbackset>'
|
||||
r'<targetedfeedbackset.*?/>'
|
||||
)
|
||||
|
||||
def test_targeted_feedback_multiple_answer_2(self):
|
||||
|
||||
Reference in New Issue
Block a user