def test_extra_attr(self): xml1 = '<root foo="bar" />' xml2 = '<root />' with assert_raises(AssertionError) as e: assert_xml_equal(xml1, xml2) assert_in('at /root@foo expected nothing, got "bar"', str(e.exception))
def test_attr_missed(self): xml1 = '<root />' xml2 = '<root foo="" />' with assert_raises(AssertionError) as e: assert_xml_equal(xml1, xml2) assert_in('at /root@foo expected "", got nothing', str(e.exception))
def test_attributes_inequal(self): xml1 = '<root foo="bar"/>' xml2 = '<root foo="qux"/>' with assert_raises(AssertionError) as e: assert_xml_equal(xml1, xml2) assert_in('at /root@foo expected "qux", got "bar"', str(e.exception))
def test_fail(self): actual = { 'foo': 'bar', 'baz': 'bee', } expected = { 'foo': 'bar', 'baz': Expectation(assert_in, ['qux', 'mew', 'pur']) } with assert_raises(AssertionError) as e: assert_equal(actual, expected) assert_in("<Failed expectation: 'bee' not found in ['qux', 'mew', 'pur']>", str(e.exception))
def test_ignore_extra_elements(self): xml1 = """ <root> <foo/> <bar/> </root> """.strip() xml2 = """ <root> <foo/> </root> """.strip() assert_xml_equal(xml1, xml2, ignore_extra_elements=True) with assert_raises(AssertionError) as e: assert_xml_equal(xml2, xml1, ignore_extra_elements=True)
def test_text_inequal(self): xml1 = """ <root> <foo>Hello</foo> </root> """.strip() xml2 = """ <root> <foo>Privet</foo> </root> """.strip() with assert_raises(AssertionError) as e: assert_xml_equal(xml1, xml2) assert_in('at /root/foo expected "Privet", got "Hello"', str(e.exception))
def test_lack_of_element(self): xml1 = """ <root> <foo/> <bar/> </root> """.strip() xml2 = """ <root> <foo/> </root> """.strip() with assert_raises(AssertionError) as e: assert_xml_equal(xml1, xml2) assert_in("at /root expected nothing, got <bar> element", str(e.exception))
def test_past(self): with assert_raises(AssertionError): assert_just_now(datetime.datetime.now() - datetime.timedelta(hours=2))
def test_primitive_inequal(self): with assert_raises(AssertionError): assert_deep_equal(123, 0)