def test_success_WHEN_actual_is_valid_node(self):
     # ARRANGE #
     assertion = sut.matches_node()
     cases = [
         NameAndValue('no details and no children',
                      sut.Node('header',
                               None,
                               [],
                               [])
                      ),
         NameAndValue('single valid detail',
                      sut.Node('header',
                               None,
                               [StringDetail('the string')],
                               [])
                      ),
         NameAndValue('single valid child',
                      sut.Node('header',
                               None,
                               [],
                               [sut.Node('child node', None, [], [])])
                      ),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ACT & ASSERT #
             assertion.apply_without_message(self, case.value)
 def test_equals(self):
     cases = [
         NameAndValue('empty tree',
                      sut.Node.empty(HEADER_e, None)
                      ),
         NameAndValue('tree with data',
                      sut.Node.empty(HEADER_e, 'some data')
                      ),
         NameAndValue('tree with details',
                      sut.Node.leaf(HEADER_e, None, [STRING_DETAIL_e])
                      ),
         NameAndValue('tree with children',
                      sut.Node(HEADER_e, 'root data', [], [sut.Node.empty(HEADER_e, 'child data')])
                      ),
         NameAndValue('tree with details and children',
                      sut.Node(HEADER_e, 'root data',
                               [STRING_DETAIL_e],
                               [sut.Node.empty(HEADER_e, 'child data')])
                      ),
     ]
     for case in cases:
         with self.subTest(case.name):
             assertion = sut.equals_node(case.value)
             actual = copy.deepcopy(case.value)
             assertion.apply_without_message(self, actual)
 def test_fail_WHEN_invalid_components_of_invalid_type(self):
     # ARRANGE #
     assertion = sut.matches_node()
     cases = [
         NameAndValue('invalid type of header',
                      sut.Node(None,
                               None,
                               [],
                               [])
                      ),
         NameAndValue('invalid type of detail',
                      sut.Node('header',
                               None,
                               ['not a Detail'],
                               [])
                      ),
         NameAndValue('invalid type of child',
                      sut.Node('header',
                               None,
                               [],
                               ['not a Node'])
                      ),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ACT & ASSERT #
             assert_that_assertion_fails(assertion, case.value)
 def test_matches(self):
     cases = [
         sut.StringDetail('s'),
         sut.PreFormattedStringDetail('pre-formatted', True),
         sut.HeaderAndValueDetail('header', ()),
         sut.TreeDetail(sut.Node('header', None, (), ())),
     ]
     for line_object in cases:
         with self.subTest(str(type(line_object))):
             sut.is_any_detail().apply_without_message(self, line_object)
    def test_matches(self):
        # ARRANGE #

        node = sut.Node('node header', None, (), ())
        tree_detail = sut.TreeDetail(node)

        satisfied_assertion = asrt.sub_component('header',
                                                 lambda tree: tree.header,
                                                 asrt.equals(node.header))
        # ACT #

        sut.is_tree_detail(satisfied_assertion).apply_without_message(self, tree_detail)
    def test_not_matches(self):
        # ARRANGE #

        node = sut.Node('actual header', None, (), ())
        tree_detail = sut.TreeDetail(node)

        unsatisfied_assertion = asrt.sub_component('header',
                                                   lambda tree: tree.header,
                                                   asrt.equals(node.header + ' with extra'))

        # ACT #

        assert_that_assertion_fails(sut.is_tree_detail(unsatisfied_assertion), tree_detail)
 def test_matches(self):
     # ARRANGE #
     cases = [
         NameAndValue(
             'empty',
             sut.Node('the header', 'the data', (), ()),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             assertion = sut.header_data_and_children_equal_as(case.value)
             # ACT & ASSERT #
             assertion.apply_without_message(self, case.value)
 def test_not_equals(self):
     child_e = sut.Node.empty(HEADER_e, DATA_e)
     child_ue = sut.Node.empty(HEADER_ue, DATA_e)
     cases = [
         _EqNodeCase(
             'empty tree',
             sut.Node.empty(HEADER_e, DATA_e),
             [
                 NameAndValue('unexpected header',
                              sut.Node.empty(HEADER_ue, DATA_e)
                              ),
                 NameAndValue('unexpected data',
                              sut.Node.empty(HEADER_e, DATA_ue)
                              ),
             ]
         ),
         _EqNodeCase(
             'tree with detail',
             sut.Node.leaf(HEADER_e, DATA_e, [STRING_DETAIL_e]),
             [
                 NameAndValue('no details',
                              sut.Node.empty(HEADER_e, DATA_e)
                              ),
                 NameAndValue('too many no details',
                              sut.Node.leaf(HEADER_e, DATA_e, [STRING_DETAIL_e, STRING_DETAIL_e])
                              ),
                 NameAndValue('unequal detail',
                              sut.Node.leaf(HEADER_e, DATA_e, [STRING_DETAIL_ue])
                              ),
             ]
         ),
         _EqNodeCase(
             'tree with multiple details',
             sut.Node.leaf(HEADER_e, DATA_e,
                           [STRING_DETAIL_e, STRING_DETAIL_e]),
             [
                 NameAndValue('unequal detail',
                              sut.Node.leaf(HEADER_e, DATA_e,
                                            [STRING_DETAIL_e, STRING_DETAIL_ue])
                              ),
             ]
         ),
         _EqNodeCase(
             'tree with child',
             sut.Node(HEADER_e, DATA_e, [], [child_e]),
             [
                 NameAndValue('no children',
                              sut.Node.empty(HEADER_e, DATA_e)
                              ),
                 NameAndValue('too many no children',
                              sut.Node(HEADER_e, DATA_e, [], [child_e, child_e])
                              ),
                 NameAndValue('unequal child',
                              sut.Node(HEADER_e, DATA_e, [], [child_ue])
                              ),
             ]
         ),
         _EqNodeCase(
             'tree with multiple children',
             sut.Node(HEADER_e, DATA_e, (),
                      [child_e, child_e]),
             [
                 NameAndValue('unequal child',
                              sut.Node(HEADER_e, DATA_e, (),
                                       [child_e, child_ue])
                              ),
             ]
         ),
         _EqNodeCase(
             'tree with details and children',
             sut.Node(HEADER_e, DATA_e, [STRING_DETAIL_e], [child_e]),
             [
                 NameAndValue('unequal detail',
                              sut.Node(HEADER_e, DATA_e, [STRING_DETAIL_ue], [child_e])
                              ),
                 NameAndValue('unequal child',
                              sut.Node(HEADER_e, DATA_e, [STRING_DETAIL_e], [child_ue])
                              ),
             ]
         ),
     ]
     for case in cases:
         assertion = sut.equals_node(case.expected)
         for unexpected in case.unexpected:
             with self.subTest(expected=case.name,
                               unexpected=unexpected.name):
                 # ACT & ASSERT #
                 assert_that_assertion_fails(assertion, unexpected.value)
 def test_not_matches(self):
     # ARRANGE #
     cases = [
         NEA(
             'different header',
             expected=sut.Node('the expected header', None, (), ()),
             actual=sut.Node('the actual header', None, (), ()),
         ),
         NEA(
             'different data',
             expected=sut.Node('', 'expected', (), ()),
             actual=sut.Node('', 'actual', (), ()),
         ),
         NEA(
             'different number of children',
             expected=sut.Node('', None, (), (sut.Node('child', None, (), ()),)),
             actual=sut.Node('', None, (), ()),
         ),
         NEA(
             'different child',
             expected=
             sut.Node('', None, (), (sut.Node('expected child', None, (), ()),)),
             actual=
             sut.Node('', None, (), (sut.Node('actual child', None, (), ()),)),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             assertion = sut.header_data_and_children_equal_as(case.expected)
             # ACT & ASSERT #
             assert_that_assertion_fails(assertion, case.actual)
class TestEqualsDetail(unittest.TestCase):
    DETAILS = [
        _EqDetailCase(
            sut.StringDetail(S_e),
            [
                NameAndValue('unexpected type',
                             sut.PreFormattedStringDetail(S_e)
                             ),
                NameAndValue('unexpected value',
                             sut.StringDetail(S_ue)
                             ),
            ]
        ),
        _EqDetailCase(
            sut.PreFormattedStringDetail(S_e),
            [
                NameAndValue('unexpected type',
                             sut.StringDetail(S_e)
                             ),
                NameAndValue('unexpected value',
                             sut.PreFormattedStringDetail('unexpected')
                             ),
            ]
        ),
        _EqDetailCase(
            sut.HeaderAndValueDetail(HEADER_e, ()),
            [
                NameAndValue('unexpected type',
                             sut.StringDetail(HEADER_e)
                             ),
                NameAndValue('unexpected header',
                             sut.HeaderAndValueDetail(HEADER_ue, ())
                             ),
                NameAndValue('unexpected details',
                             sut.HeaderAndValueDetail(HEADER_e, [sut.StringDetail(S_e)])
                             ),
            ]
        ),
        _EqDetailCase(
            sut.IndentedDetail([sut.StringDetail(S_e)]),
            [
                NameAndValue('unexpected type',
                             sut.StringDetail(HEADER_e)
                             ),
                NameAndValue('unexpected number of children',
                             sut.IndentedDetail([])
                             ),
                NameAndValue('unexpected child',
                             sut.IndentedDetail([sut.StringDetail(S_ue)])
                             ),
            ]
        ),
        _EqDetailCase(
            sut.TreeDetail(sut.Node(HEADER_e, None, [STRING_DETAIL_e], [])),
            [
                NameAndValue('unexpected type',
                             sut.StringDetail(HEADER_e)
                             ),
                NameAndValue('unexpected header',
                             sut.TreeDetail(sut.Node(HEADER_ue, None, [STRING_DETAIL_e], []))
                             ),
                NameAndValue('unexpected number of details',
                             sut.TreeDetail(sut.Node(HEADER_e, None, [], []))
                             ),
                NameAndValue('unexpected child detail',
                             sut.TreeDetail(sut.Node(HEADER_e, None, [STRING_DETAIL_ue], []))
                             ),
            ]
        ),
    ]

    def test_not_equals(self):
        for case in self.DETAILS:
            assertion = sut.equals_detail(case.expected)
            for unexpected in case.unexpected:
                with self.subTest(type=type(case.expected),
                                  unexpected=unexpected.name):
                    assert_that_assertion_fails(assertion, unexpected.value)
    def test_succeed(self):
        assertion = sut.matches_node(children=asrt.len_equals(0))

        assertion.apply_without_message(self,
                                        sut.Node('header', None, [], []))
    def test_fail(self):
        assertion = sut.matches_node(children=asrt.len_equals(1))

        assert_that_assertion_fails(assertion,
                                    sut.Node('header', None, [], []))
    def test_succeed(self):
        assertion = sut.matches_node(data=asrt.equals('expected data'))

        assertion.apply_without_message(self,
                                        sut.Node('header', 'expected data', [], []))
    def test_fail(self):
        assertion = sut.matches_node(data=asrt.equals('expected data'))

        assert_that_assertion_fails(assertion,
                                    sut.Node('header', 'actual data', [], []))
    def test_succeed(self):
        assertion = sut.matches_node(header=asrt.equals('expected header'))

        assertion.apply_without_message(self,
                                        sut.Node('expected header', None, [], []))
    def test_fail(self):
        assertion = sut.matches_node(header=asrt.equals('expected header'))

        assert_that_assertion_fails(assertion,
                                    sut.Node('actual header', None, [], []))