TE-2525 nose.tools removal part 1/2

This commit is contained in:
Jeremy Bowman
2018-08-06 16:52:11 -04:00
committed by Jeremy Bowman
parent 70d1ca4740
commit bcaec3c5bb
26 changed files with 322 additions and 410 deletions

View File

@@ -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)