TE-2525 nose.tools removal part 1/2
This commit is contained in:
committed by
Jeremy Bowman
parent
70d1ca4740
commit
bcaec3c5bb
@@ -1,22 +1,22 @@
|
||||
"""
|
||||
Tests stringify functions used in xmodule html
|
||||
"""
|
||||
from nose.tools import assert_equals # pylint: disable=no-name-in-module
|
||||
from lxml import etree
|
||||
from openedx.core.lib.tests import attr
|
||||
from xmodule.stringify import stringify_children
|
||||
|
||||
|
||||
@attr(shard=1)
|
||||
def test_stringify():
|
||||
shard = 1
|
||||
text = 'Hi <div x="foo">there <span>Bruce</span><b>!</b></div>'
|
||||
html = '''<html a="b" foo="bar">{0}</html>'''.format(text)
|
||||
xml = etree.fromstring(html)
|
||||
out = stringify_children(xml)
|
||||
assert_equals(out, text)
|
||||
assert out == text
|
||||
|
||||
|
||||
@attr(shard=1)
|
||||
def test_stringify_again():
|
||||
shard = 1
|
||||
html = r"""<html name="Voltage Source Answer" >A voltage source is non-linear!
|
||||
<div align="center">
|
||||
<img src="/static/images/circuits/voltage-source.png"/>
|
||||
@@ -43,4 +43,4 @@ def test_stringify_again():
|
||||
|
||||
# Tracking strange content repeating bug
|
||||
# Should appear once
|
||||
assert_equals(out.count("But it is "), 1)
|
||||
assert out.count("But it is ") == 1
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"""Tests for methods defined in util/django.py"""
|
||||
from xmodule.util.xmodule_django import get_current_request, get_current_request_hostname
|
||||
from nose.tools import assert_is_none
|
||||
from unittest import TestCase
|
||||
|
||||
|
||||
@@ -14,10 +13,10 @@ class UtilDjangoTests(TestCase):
|
||||
"""
|
||||
Since we are running outside of Django assert that get_current_request returns None
|
||||
"""
|
||||
assert_is_none(get_current_request())
|
||||
assert get_current_request() is None
|
||||
|
||||
def test_get_current_request_hostname(self):
|
||||
"""
|
||||
Since we are running outside of Django assert that get_current_request_hostname returns None
|
||||
"""
|
||||
assert_is_none(get_current_request_hostname())
|
||||
assert get_current_request_hostname() is None
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import unittest
|
||||
|
||||
from mock import Mock
|
||||
from nose.tools import assert_equals, assert_not_equals, assert_true, assert_false, assert_in, assert_not_in # pylint: disable=no-name-in-module
|
||||
from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
|
||||
|
||||
from xblock.field_data import DictFieldData
|
||||
@@ -376,21 +375,20 @@ class TestSerialize(unittest.TestCase):
|
||||
shard = 1
|
||||
|
||||
def test_serialize(self):
|
||||
assert_equals('null', serialize_field(None))
|
||||
assert_equals('-2', serialize_field(-2))
|
||||
assert_equals('2', serialize_field('2'))
|
||||
assert_equals('-3.41', serialize_field(-3.41))
|
||||
assert_equals('2.589', serialize_field('2.589'))
|
||||
assert_equals('false', serialize_field(False))
|
||||
assert_equals('false', serialize_field('false'))
|
||||
assert_equals('fAlse', serialize_field('fAlse'))
|
||||
assert_equals('hat box', serialize_field('hat box'))
|
||||
assert_equals('{"bar": "hat", "frog": "green"}', serialize_field({'bar': 'hat', 'frog': 'green'}))
|
||||
assert_equals('[3.5, 5.6]', serialize_field([3.5, 5.6]))
|
||||
assert_equals('["foo", "bar"]', serialize_field(['foo', 'bar']))
|
||||
assert_equals('2012-12-31T23:59:59Z', serialize_field("2012-12-31T23:59:59Z"))
|
||||
assert_equals('1 day 12 hours 59 minutes 59 seconds',
|
||||
serialize_field("1 day 12 hours 59 minutes 59 seconds"))
|
||||
assert serialize_field(None) == 'null'
|
||||
assert serialize_field(-2) == '-2'
|
||||
assert serialize_field('2') == '2'
|
||||
assert serialize_field(-3.41) == '-3.41'
|
||||
assert serialize_field('2.589') == '2.589'
|
||||
assert serialize_field(False) == 'false'
|
||||
assert serialize_field('false') == 'false'
|
||||
assert serialize_field('fAlse') == 'fAlse'
|
||||
assert serialize_field('hat box') == 'hat box'
|
||||
assert serialize_field({'bar': 'hat', 'frog': 'green'}) == '{"bar": "hat", "frog": "green"}'
|
||||
assert serialize_field([3.5, 5.6]) == '[3.5, 5.6]'
|
||||
assert serialize_field(['foo', 'bar']) == '["foo", "bar"]'
|
||||
assert serialize_field("2012-12-31T23:59:59Z") == '2012-12-31T23:59:59Z'
|
||||
assert serialize_field("1 day 12 hours 59 minutes 59 seconds") == '1 day 12 hours 59 minutes 59 seconds'
|
||||
|
||||
|
||||
class TestDeserialize(unittest.TestCase):
|
||||
@@ -400,7 +398,7 @@ class TestDeserialize(unittest.TestCase):
|
||||
"""
|
||||
Asserts the result of deserialize_field.
|
||||
"""
|
||||
assert_equals(expected, deserialize_field(self.field_type(), arg))
|
||||
assert deserialize_field(self.field_type(), arg) == expected
|
||||
|
||||
def assertDeserializeNonString(self):
|
||||
"""
|
||||
@@ -603,20 +601,20 @@ class TestXmlAttributes(XModuleXmlImportTest):
|
||||
shard = 1
|
||||
|
||||
def test_unknown_attribute(self):
|
||||
assert_false(hasattr(CourseDescriptor, 'unknown_attr'))
|
||||
assert not hasattr(CourseDescriptor, 'unknown_attr')
|
||||
course = self.process_xml(CourseFactory.build(unknown_attr='value'))
|
||||
assert_false(hasattr(course, 'unknown_attr'))
|
||||
assert_equals('value', course.xml_attributes['unknown_attr'])
|
||||
assert not hasattr(course, 'unknown_attr')
|
||||
assert course.xml_attributes['unknown_attr'] == 'value'
|
||||
|
||||
def test_known_attribute(self):
|
||||
assert_true(hasattr(CourseDescriptor, 'show_calculator'))
|
||||
assert hasattr(CourseDescriptor, 'show_calculator')
|
||||
course = self.process_xml(CourseFactory.build(show_calculator='true'))
|
||||
assert_true(course.show_calculator)
|
||||
assert_not_in('show_calculator', course.xml_attributes)
|
||||
assert course.show_calculator
|
||||
assert 'show_calculator' not in course.xml_attributes
|
||||
|
||||
def test_rerandomize_in_policy(self):
|
||||
# Rerandomize isn't a basic attribute of Sequence
|
||||
assert_false(hasattr(SequenceDescriptor, 'rerandomize'))
|
||||
assert not hasattr(SequenceDescriptor, 'rerandomize')
|
||||
|
||||
root = SequenceFactory.build(policy={'rerandomize': 'never'})
|
||||
ProblemFactory.build(parent=root)
|
||||
@@ -624,15 +622,15 @@ class TestXmlAttributes(XModuleXmlImportTest):
|
||||
seq = self.process_xml(root)
|
||||
|
||||
# Rerandomize is added to the constructed sequence via the InheritanceMixin
|
||||
assert_equals('never', seq.rerandomize)
|
||||
assert seq.rerandomize == 'never'
|
||||
|
||||
# Rerandomize is a known value coming from policy, and shouldn't appear
|
||||
# in xml_attributes
|
||||
assert_not_in('rerandomize', seq.xml_attributes)
|
||||
assert 'rerandomize' not in seq.xml_attributes
|
||||
|
||||
def test_attempts_in_policy(self):
|
||||
# attempts isn't a basic attribute of Sequence
|
||||
assert_false(hasattr(SequenceDescriptor, 'attempts'))
|
||||
assert not hasattr(SequenceDescriptor, 'attempts')
|
||||
|
||||
root = SequenceFactory.build(policy={'attempts': '1'})
|
||||
ProblemFactory.build(parent=root)
|
||||
@@ -641,38 +639,38 @@ class TestXmlAttributes(XModuleXmlImportTest):
|
||||
|
||||
# attempts isn't added to the constructed sequence, because
|
||||
# it's not in the InheritanceMixin
|
||||
assert_false(hasattr(seq, 'attempts'))
|
||||
assert not hasattr(seq, 'attempts')
|
||||
|
||||
# attempts is an unknown attribute, so we should include it
|
||||
# in xml_attributes so that it gets written out (despite the misleading
|
||||
# name)
|
||||
assert_in('attempts', seq.xml_attributes)
|
||||
assert 'attempts' in seq.xml_attributes
|
||||
|
||||
def check_inheritable_attribute(self, attribute, value):
|
||||
# `attribute` isn't a basic attribute of Sequence
|
||||
assert_false(hasattr(SequenceDescriptor, attribute))
|
||||
assert not hasattr(SequenceDescriptor, attribute)
|
||||
|
||||
# `attribute` is added by InheritanceMixin
|
||||
assert_true(hasattr(InheritanceMixin, attribute))
|
||||
assert hasattr(InheritanceMixin, attribute)
|
||||
|
||||
root = SequenceFactory.build(policy={attribute: str(value)})
|
||||
ProblemFactory.build(parent=root)
|
||||
|
||||
# InheritanceMixin will be used when processing the XML
|
||||
assert_in(InheritanceMixin, root.xblock_mixins)
|
||||
assert InheritanceMixin in root.xblock_mixins
|
||||
|
||||
seq = self.process_xml(root)
|
||||
|
||||
assert_equals(seq.unmixed_class, SequenceDescriptor)
|
||||
assert_not_equals(type(seq), SequenceDescriptor)
|
||||
assert seq.unmixed_class == SequenceDescriptor
|
||||
assert type(seq) != SequenceDescriptor
|
||||
|
||||
# `attribute` is added to the constructed sequence, because
|
||||
# it's in the InheritanceMixin
|
||||
assert_equals(value, getattr(seq, attribute))
|
||||
assert getattr(seq, attribute) == value
|
||||
|
||||
# `attribute` is a known attribute, so we shouldn't include it
|
||||
# in xml_attributes
|
||||
assert_not_in(attribute, seq.xml_attributes)
|
||||
assert attribute not in seq.xml_attributes
|
||||
|
||||
def test_inheritable_attributes(self):
|
||||
self.check_inheritable_attribute('days_early_for_beta', 2)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
"""
|
||||
Test that inherited fields work correctly when parsing XML
|
||||
"""
|
||||
from nose.tools import assert_equals, assert_in # pylint: disable=no-name-in-module
|
||||
|
||||
from xmodule.tests.xml import XModuleXmlImportTest
|
||||
from xmodule.tests.xml.factories import CourseFactory, SequenceFactory, ProblemFactory, XmlImportFactory
|
||||
|
||||
@@ -22,13 +20,13 @@ class TestInheritedFieldParsing(XModuleXmlImportTest):
|
||||
ProblemFactory.build(parent=sequence)
|
||||
|
||||
course = self.process_xml(root)
|
||||
assert_equals(None, course.days_early_for_beta)
|
||||
assert course.days_early_for_beta is None
|
||||
|
||||
sequence = course.get_children()[0]
|
||||
assert_equals(None, sequence.days_early_for_beta)
|
||||
assert sequence.days_early_for_beta is None
|
||||
|
||||
problem = sequence.get_children()[0]
|
||||
assert_equals(None, problem.days_early_for_beta)
|
||||
assert problem.days_early_for_beta is None
|
||||
|
||||
def test_video_attr(self):
|
||||
"""
|
||||
@@ -46,4 +44,4 @@ class TestInheritedFieldParsing(XModuleXmlImportTest):
|
||||
}
|
||||
)
|
||||
video_block = self.process_xml(video)
|
||||
assert_in('garbage', video_block.xml_attributes)
|
||||
assert 'garbage' in video_block.xml_attributes
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Tests that policy json files import correctly when loading XML
|
||||
"""
|
||||
|
||||
from nose.tools import assert_equals, assert_raises # pylint: disable=no-name-in-module
|
||||
import pytest
|
||||
|
||||
from xmodule.tests.xml.factories import CourseFactory
|
||||
from xmodule.tests.xml import XModuleXmlImportTest
|
||||
@@ -18,7 +18,7 @@ class TestPolicy(XModuleXmlImportTest):
|
||||
# Policy files are json, and thus the values aren't passed through 'deserialize_field'
|
||||
# Therefor, the string 'null' is passed unchanged to the Float field, which will trigger
|
||||
# a ValueError
|
||||
with assert_raises(ValueError):
|
||||
with pytest.raises(ValueError):
|
||||
course = self.process_xml(CourseFactory.build(policy={'days_early_for_beta': 'null'}))
|
||||
|
||||
# Trigger the exception by looking at the imported data
|
||||
@@ -26,7 +26,7 @@ class TestPolicy(XModuleXmlImportTest):
|
||||
|
||||
def test_course_policy(self):
|
||||
course = self.process_xml(CourseFactory.build(policy={'days_early_for_beta': None}))
|
||||
assert_equals(None, course.days_early_for_beta)
|
||||
assert course.days_early_for_beta is None
|
||||
|
||||
course = self.process_xml(CourseFactory.build(policy={'days_early_for_beta': 9}))
|
||||
assert_equals(9, course.days_early_for_beta)
|
||||
assert course.days_early_for_beta == 9
|
||||
|
||||
Reference in New Issue
Block a user