Ejemplo n.º 1
0
    def test_complex(self):
        # ARRANGE #

        child_11_detail = StringDetail('string detail 11')
        child_11 = Node('the child 11', None, (child_11_detail, ), ())
        child_1_detail_1 = StringDetail('string detail 1-1')
        child_1_detail_2 = StringDetail('string detail 1-2')
        child_1 = Node('the child 1', None,
                       (child_1_detail_1, child_1_detail_2), (child_11, ))
        child_2 = Node('the child 2', None, (), ())
        tree_in_detail = Node('the contained tree root', None, (),
                              (child_1, child_2))

        tree_detail = TreeDetail(tree_in_detail)

        root = Node('the root', False, [tree_detail], ())

        # EXPECTATION #

        expectation = matches_trace_with_details(
            root,
            [
                matches_detail_line_element(tree_in_detail.header, depth=0),
                matches_detail_line_element(child_1.header, depth=1),
                matches_string_detail_line_element(child_1_detail_1, depth=2),
                matches_string_detail_line_element(child_1_detail_2, depth=2),
                matches_detail_line_element(child_11.header, depth=2),
                matches_string_detail_line_element(child_11_detail, depth=3),
                matches_detail_line_element(child_2.header, depth=1),
            ],
        )

        # ACT & ASSERT #

        _check(self, root, expectation)
Ejemplo n.º 2
0
    def test_node_with_2_details_and_2_children(self):
        for root_data in [False, True]:
            for child_1_data in [False, True]:
                for child_2_data in [False, True]:
                    with self.subTest(root_data=root_data,
                                      child_1_data=child_1_data,
                                      child_11_data=child_2_data):
                        child_1 = Node('the child 1', child_1_data, (), ())
                        child_2 = Node('the child 2', child_2_data, (), ())
                        children = [child_1, child_2]

                        detail_1 = StringDetail('the detail 1')
                        detail_2 = StringDetail('the detail 2')
                        details = [detail_1, detail_2]

                        root = Node('the root', root_data, details, children)

                        # EXPECTATION #

                        expectation = asrt_struct.matches_major_block__w_plain_properties(
                            minor_blocks=asrt.matches_sequence([
                                asrt_struct.matches_minor_block(
                                    line_elements=asrt.matches_sequence([
                                        matches_header_line_element(root),
                                        matches_string_detail_line_element(
                                            detail_1, depth=0),
                                        matches_string_detail_line_element(
                                            detail_2, depth=0),
                                    ]),
                                    properties=matches_node_properties(
                                        depth=0),
                                ),
                                asrt_struct.matches_minor_block(
                                    line_elements=asrt.
                                    matches_singleton_sequence(
                                        matches_header_line_element(child_1)),
                                    properties=matches_node_properties(
                                        depth=1),
                                ),
                                asrt_struct.matches_minor_block(
                                    line_elements=asrt.
                                    matches_singleton_sequence(
                                        matches_header_line_element(child_2)),
                                    properties=matches_node_properties(
                                        depth=1),
                                ),
                            ]))

                        # ACT & ASSERT #

                        _check(self, root, expectation)
Ejemplo n.º 3
0
    def test_node_with_detail_and_child(self):
        # ARRANGE #

        for child_data in [False, True]:
            with self.subTest(data=child_data):
                child = Node('the child', child_data, (), ())
                detail = StringDetail('the detail')
                root = Node('the root', False, [detail], [child])

                # EXPECTATION #

                expectation = asrt_struct.matches_major_block__w_plain_properties(
                    minor_blocks=asrt.matches_sequence([
                        asrt_struct.matches_minor_block(
                            line_elements=asrt.matches_sequence([
                                matches_header_line_element(root),
                                matches_string_detail_line_element(detail,
                                                                   depth=0),
                            ]),
                            properties=matches_node_properties(depth=0),
                        ),
                        asrt_struct.matches_minor_block(
                            line_elements=asrt.matches_singleton_sequence(
                                matches_header_line_element(child)),
                            properties=matches_node_properties(depth=1),
                        ),
                    ]))

                # ACT & ASSERT #

                _check(self, root, expectation)
Ejemplo n.º 4
0
    def test_node_with_detail_and_child(self):
        # ARRANGE #

        child = Node('the child', None, (), ())
        string_detail = StringDetail('the string detail')
        tree_in_detail = Node('the contained tree root', None,
                              (string_detail, ), (child, ))

        tree_detail = TreeDetail(tree_in_detail)

        root = Node('the root', False, [tree_detail], ())

        # EXPECTATION #

        expectation = matches_trace_with_details(
            root,
            [
                matches_detail_line_element(tree_in_detail.header, depth=0),
                matches_string_detail_line_element(string_detail, depth=1),
                matches_detail_line_element(child.header, depth=1),
            ],
        )

        # ACT & ASSERT #

        _check(self, root, expectation)
 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_matches(self):
     # ARRANGE #
     expected_detail = StringDetail('the string detail')
     actual = sut.IndentedDetail([expected_detail])
     # EXPECTATION #
     assertion = sut.is_indented_detail(
         details=asrt.matches_singleton_sequence(asrt.is_(expected_detail))
     )
     # ACT & ASSERT #
     assertion.apply_without_message(self, actual)
Ejemplo n.º 7
0
    def test_indented_detail(self):
        # ARRANGE #
        details_1 = StringDetail('indented detail 1')
        details_2 = StringDetail('indented detail 2')
        indented_detail = IndentedDetail([details_1, details_2])
        root = Node('the root', False, [indented_detail], ())

        # EXPECTATION #

        expectation = matches_trace_with_details(
            root,
            [
                matches_string_detail_line_element(details_1, depth=1),
                matches_string_detail_line_element(details_2, depth=1),
            ],
        )

        # ACT & ASSERT #

        _check(self, root, expectation)
Ejemplo n.º 8
0
    def test_string_detail(self):
        # ARRANGE #
        for string_object_case in STRING_OBJECT_CASES:
            with self.subTest(string_object_case.name):
                detail = StringDetail(string_object_case.value)
                root = Node('the root', False, [detail], ())

                # EXPECTATION #

                expectation = matches_trace_with_just_single_detail(
                    root,
                    matches_string_detail_line_element(detail, depth=0),
                )

                # ACT & ASSERT #

                _check(self, root, expectation)
 def test_not_matches(self):
     cases = [
         NEA('unexpected object type',
             expected=
             sut.is_indented_detail(),
             actual=
             sut.PreFormattedStringDetail('s'),
             ),
         NEA('details',
             expected=
             sut.is_indented_detail(details=asrt.is_empty_sequence),
             actual=
             sut.IndentedDetail((StringDetail('a value'),)),
             ),
     ]
     for case in cases:
         with self.subTest(case.name):
             assert_that_assertion_fails(case.expected, case.actual)
Ejemplo n.º 10
0
    def test_header_and_value_detail(self):
        # ARRANGE #
        text_style__non_neutral = TextStyle(font_style=FontStyle.UNDERLINE)
        cases = [
            NIE(
                'without text style',
                TEXT_STYLE__NEUTRAL,
                TEXT_STYLE__NEUTRAL,
            ),
            NIE(
                'with text style',
                text_style__non_neutral,
                text_style__non_neutral,
            ),
        ]
        for case in cases:
            with self.subTest(case.name):
                value_detail = StringDetail('the value detail')
                header_and_value_detail = HeaderAndValueDetail(
                    'the header', [value_detail], case.input_value)
                root = Node('the root', False, [header_and_value_detail], ())

                # EXPECTATION #

                expectation = matches_trace_with_details(
                    root,
                    [
                        matches_detail_line_element(
                            header_and_value_detail.header,
                            depth=0,
                            text_style=case.expected_value),
                        matches_string_detail_line_element(value_detail,
                                                           depth=1),
                    ],
                )

                # ACT & ASSERT #

                _check(self, root, expectation)
Ejemplo n.º 11
0
 def test_matches(self):
     header = 'the header'
     value = StringDetail('the string detail')
     cases = [
         NEA('header',
             expected=
             sut.is_header_and_value_detail(header=asrt.equals(header)),
             actual=
             sut.HeaderAndValueDetail(header, ()),
             ),
         NEA('values',
             expected=
             sut.is_header_and_value_detail(
                 values=asrt.matches_singleton_sequence(asrt.is_(value))
             ),
             actual=
             sut.HeaderAndValueDetail(header, (value,))
             ),
     ]
     for case in cases:
         with self.subTest(case.name):
             case.expected.apply_without_message(self, case.actual)
Ejemplo n.º 12
0
    def test_detail(self):
        # ARRANGE #

        for child_data in [False, True]:
            with self.subTest(data=child_data):
                detail = StringDetail('the detail')
                root = Node('the root', False, [detail], [])

                # EXPECTATION #

                expectation = asrt_struct.matches_major_block__w_plain_properties(
                    minor_blocks=asrt.matches_singleton_sequence(asrt_struct.matches_minor_block__w_plain_properties(
                        line_elements=asrt.matches_sequence([
                            _matches_header_line_element(root),
                            _matches_string_detail_line_element(detail, depth=0),
                        ]),
                    ))
                )

                # ACT & ASSERT #

                _check(self, root, expectation)
Ejemplo n.º 13
0
 def test_not_matches(self):
     cases = [
         NEA('unexpected object type',
             expected=
             sut.is_header_and_value_detail(),
             actual=
             sut.PreFormattedStringDetail('s'),
             ),
         NEA('header',
             expected=
             sut.is_header_and_value_detail(header=asrt.equals('expected header')),
             actual=
             sut.HeaderAndValueDetail('actual header', ()),
             ),
         NEA('values',
             expected=
             sut.is_header_and_value_detail(values=asrt.is_empty_sequence),
             actual=
             sut.HeaderAndValueDetail('header', (StringDetail('a value'),)),
             ),
     ]
     for case in cases:
         with self.subTest(case.name):
             assert_that_assertion_fails(case.expected, case.actual)