@@ -415,6 +415,21 @@ def test_elements_equal_without_children_whitespace_matches():
415
415
assert xml_utils .elements_equal (e1 , e2 )
416
416
417
417
418
+ def test_elements_equal_str_num_and_int ():
419
+ """
420
+ Test that elements_equal function considers a string number equal to an integer number
421
+
422
+ eg:
423
+ <test/> == <test> </test>
424
+ """
425
+ e1 = Element ("test" )
426
+ e1 .text = 1
427
+ e2 = Element ("test" )
428
+ e2 .text = "1"
429
+
430
+ assert xml_utils .elements_equal (e1 , e2 )
431
+
432
+
418
433
def test_elements_equal_without_children_none_and_1 ():
419
434
"""
420
435
Tests elements_equal function matches a boolean flag "1" the same as an empty element.
@@ -433,17 +448,42 @@ def test_elements_equal_without_children_none_and_1():
433
448
def test_elements_equal_with_children ():
434
449
"""
435
450
Tests elements_equal function matches recursively equal elements.
451
+ Elements having children with the same content should be equal.
436
452
"""
437
453
e1 = Element ("test" )
438
454
e1c1 = Element ("child_1" )
439
455
e1c1 .text = "some_text"
440
456
e1c2 = Element ("child_2" )
441
457
e1c2 .text = "some_text_as_well"
442
458
e1 .extend ([e1c1 , e1c2 ])
459
+
443
460
e2 = Element ("test" )
444
461
e2c1 = Element ("child_1" )
445
462
e2c1 .text = "some_text \n "
446
463
e2c2 = Element ("child_2" )
447
- e2c2 .text = "\n some_text \n "
464
+ e2c2 .text = "\n some_text_as_well \n "
448
465
e2 .extend ([e2c1 , e2c2 ])
466
+
449
467
assert xml_utils .elements_equal (e1 , e2 )
468
+
469
+
470
+ def test_elements_not_equal_with_children ():
471
+ """
472
+ Tests elements_equal function checks elements recursively.
473
+ Elements having children with different content should not be equal.
474
+ """
475
+ e1 = Element ("test" )
476
+ e1c1 = Element ("child_1" )
477
+ e1c1 .text = "some_text"
478
+ e1c2 = Element ("child_2" )
479
+ e1c2 .text = "some_text_as_well"
480
+ e1 .extend ([e1c1 , e1c2 ])
481
+
482
+ e2 = Element ("test" )
483
+ e2c1 = Element ("child_1" )
484
+ e2c1 .text = "some_text \n "
485
+ e2c2 = Element ("child_2" )
486
+ e2c2 .text = "\n wrong_text \n "
487
+ e2 .extend ([e2c1 , e2c2 ])
488
+
489
+ assert not xml_utils .elements_equal (e1 , e2 )
0 commit comments