예제 #1
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)
예제 #2
0
def matches_trace_with_details(
    tree: Node[bool],
    details: Sequence[Assertion[s.LineElement]],
) -> Assertion[s.MajorBlock]:
    expected_line_elements = asrt.matches_sequence(
        [matches_header_line_element(tree)] + list(details))
    return asrt_struct.matches_major_block__w_plain_properties(
        minor_blocks=asrt.matches_singleton_sequence(
            asrt_struct.matches_minor_block(
                line_elements=expected_line_elements,
                properties=matches_node_properties(depth=0),
            )))
예제 #3
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)
예제 #4
0
def _is_single_pre_formatted_text(
        text: Assertion[str]) -> Assertion[TextRenderer]:
    return asrt_renderer.is_renderer_of_major_blocks(
        asrt.matches_sequence([
            asrt_struct.matches_major_block__w_plain_properties(
                asrt.matches_sequence([
                    asrt_struct.matches_minor_block__w_plain_properties(
                        asrt.matches_sequence([
                            asrt_struct.
                            matches_line_element__w_plain_properties(
                                asrt_struct.is_pre_formatted_string(
                                    string=text))
                        ]))
                ]))
        ]))
예제 #5
0
    def test_node_with_child_with_child(self):
        # ARRANGE #

        for root_data in [False, True]:
            for child_1_data in [False, True]:
                for child_11_data in [False, True]:
                    with self.subTest(root_data=root_data,
                                      child_1_data=child_1_data,
                                      child_11_data=child_11_data):
                        child_11 = Node('the child 11', child_11_data, (), ())
                        child_1 = Node('the child_1', child_1_data, (),
                                       [child_11])
                        root = Node('the root', root_data, [], [child_1])

                        # EXPECTATION #

                        expectation = asrt_struct.matches_major_block__w_plain_properties(
                            minor_blocks=asrt.matches_sequence([
                                asrt_struct.matches_minor_block(
                                    line_elements=asrt.
                                    matches_singleton_sequence(
                                        matches_header_line_element(root)),
                                    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_11)),
                                    properties=matches_node_properties(
                                        depth=2),
                                ),
                            ]))

                        # ACT & ASSERT #

                        _check(self, root, expectation)
예제 #6
0
    def test_node_with_just_header(self):
        # ARRANGE #
        for data in [False, True]:
            with self.subTest(data=data):
                root = Node('header', data, (), ())

                # EXPECTATION #

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

                # ACT & ASSERT #

                _check(self, root, expectation)
예제 #7
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)
예제 #8
0
    def test_header(self):
        # ARRANGE #
        for data in [False, True]:
            with self.subTest(data=data):
                root = Node('header', data, (), ())
                renderer = ConstantNodeRendererTestImpl(root)

                # 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_singleton_sequence(
                                _matches_header_line_element(root)
                            ),
                        )
                    )
                )

                # ACT & ASSERT #

                _check(self, root, expectation)
예제 #9
0
    def test_with_source(self):
        # ARRANGE #
        section_name = 'section-name'
        line_sequence_a = LineSequence(2, ['source a 1', 'source a 2'])
        file_path_a = pathlib.Path('file-a.src')

        minor_blocks_expectation = asrt.matches_sequence([
            _matches_plain_minor_block_w_single_plain_line(
                section_line(section_name)),
            _matches_plain_minor_block_w_single_plain_line(
                file_and_line_num_line(file_path_a, line_sequence_a)),
            matches_source_code_minor_block(line_sequence_a.lines),
        ])
        input_value = SourceLocationPath(location=SourceLocation(
            line_sequence_a, file_path_a),
                                         file_inclusion_chain=[])

        with self.subTest(blocks_rendering='minor blocks'):
            # ACT #
            actual_renderer = source_location.location_minor_blocks_renderer(
                input_value, section_name, None)
            actual = actual_renderer.render_sequence()
            # ASSERT #
            minor_blocks_expectation.apply_without_message(self, actual)

        with self.subTest(blocks_rendering='major blocks'):
            expected_major_blocks = asrt.matches_sequence([
                asrt_struct.matches_major_block__w_plain_properties(
                    minor_blocks=minor_blocks_expectation)
            ])
            # ACT #
            actual_renderer = source_location.location_blocks_renderer(
                input_value, section_name, None)
            actual = actual_renderer.render_sequence()
            # ASSERT #
            expected_major_blocks.apply_without_message(self, actual)
예제 #10
0
            with self.subTest(case.name, blocks_renderer='minor blocks'):
                # ACT #
                actual_renderer = source_location.location_minor_blocks_renderer(
                    None, case.input_value, None)
                actual = actual_renderer.render_sequence()
                # ASSERT #
                case.expected_value.apply_without_message(self, actual)

            with self.subTest(case.name, blocks_renderer='major blocks'):
                # ACT #
                actual_renderer = source_location.location_blocks_renderer(
                    None, case.input_value, None)
                actual = actual_renderer.render_sequence()
                # ASSERT #
                expected = asrt.matches_sequence([
                    asrt_struct.matches_major_block__w_plain_properties(
                        minor_blocks=case.expected_value, )
                ])
                expected.apply_without_message(self, actual)

    def test_with_source(self):
        # ARRANGE #
        section_name = 'section-name'
        line_sequence_a = LineSequence(2, ['source a 1', 'source a 2'])
        file_path_a = pathlib.Path('file-a.src')

        minor_blocks_expectation = asrt.matches_sequence([
            _matches_plain_minor_block_w_single_plain_line(
                section_line(section_name)),
            _matches_plain_minor_block_w_single_plain_line(
                file_and_line_num_line(file_path_a, line_sequence_a)),
            matches_source_code_minor_block(line_sequence_a.lines),