def test_multiple_minor_blocks(self):
        # ARRANGE #
        string_1 = 'the 1st string'
        string_2 = 'the 2nd string'
        string_3 = 'the 3rd string'
        cases = [
            NEA(
                'multiple types, with different indent properties',
                lines_content([
                    MAJOR_BLOCK_INDENT + string_1,
                    MINOR_BLOCKS_SEPARATOR,
                    MAJOR_BLOCK_INDENT + MINOR_BLOCK_INDENT +
                    LINE_ELEMENT_INDENT + string_2,
                    MINOR_BLOCKS_SEPARATOR,
                    string_3,
                ]),
                s.MajorBlock(
                    [
                        s.MinorBlock(
                            [
                                s.LineElement(
                                    s.StringLineObject(string_1),
                                    s.ELEMENT_PROPERTIES__NEUTRAL,
                                ),
                            ],
                            s.ELEMENT_PROPERTIES__NEUTRAL,
                        ),
                        s.MinorBlock(
                            [
                                s.LineElement(
                                    s.StringLineObject(string_2),
                                    s.ELEMENT_PROPERTIES__INDENTED,
                                ),
                            ],
                            s.ELEMENT_PROPERTIES__INDENTED,
                        ),
                        s.MinorBlock(
                            [
                                s.LineElement(
                                    s.PreFormattedStringLineObject(
                                        string_3, False),
                                    s.ELEMENT_PROPERTIES__INDENTED,
                                ),
                            ],
                            s.ELEMENT_PROPERTIES__INDENTED,
                        )
                    ],
                    s.ELEMENT_PROPERTIES__INDENTED,
                ),
            ),
        ]

        for case in cases:
            with self.subTest(case.name):
                # ACT & ASSERT #
                check_major_block(
                    self,
                    case.actual,
                    case.expected,
                )
Example #2
0
def _header_and_value(header: str,
                      value: Sequence[text_struct.LineElement],
                      value_block_properties: text_struct.ElementProperties,
                      ) -> text_struct.MajorBlock:
    return text_struct.MajorBlock([
        text_struct.MinorBlock([
            text_struct.LineElement(
                text_struct.StringLineObject(header)
            )
        ]),
        text_struct.MinorBlock(
            value,
            value_block_properties,
        ),
    ])
Example #3
0
    def test_indentation_element_properties_SHOULD_be_accumulated(self):
        # ARRANGE #

        line_object = s.StringLineObject('the string')
        block_properties = ElementProperties(
            Indentation(2, '<block indent suffix>'),
            TEXT_STYLE__NEUTRAL,
        )
        line_element_properties = ElementProperties(
            Indentation(3, '<line element indent suffix>'),
            TEXT_STYLE__NEUTRAL,
        )

        # ACT & ASSERT #

        check_minor_block(
            self,
            to_render=s.MinorBlock(
                [s.LineElement(line_object, line_element_properties)],
                block_properties,
            ),
            expectation=lines_content([
                ((LAYOUT_SETTINGS.minor_block.indent *
                  block_properties.indentation.level) +
                 block_properties.indentation.suffix +
                 (LAYOUT_SETTINGS.line_element_indent *
                  line_element_properties.indentation.level) +
                 line_element_properties.indentation.suffix +
                 line_object.string)
            ]),
        )
    def test_empty_blocks_SHOULD_BE_separated_by_single_block_separator(self):
        # Have not implemented filtering of non-empty blocks.
        # Reason is that such blocks should not be constructed.
        # But implement it if it appears to be useful for making
        # construction easier.

        # ARRANGE #
        string_1 = 'the 1st string'

        empty_block = s.MajorBlock([
            s.MinorBlock(
                [],
                s.ELEMENT_PROPERTIES__NEUTRAL,
            ),
        ], s.ELEMENT_PROPERTIES__NEUTRAL)

        non_empty_block = s.MajorBlock(
            [
                single_line_minor_block_w_plain_properties(string_1),
            ],
            s.ELEMENT_PROPERTIES__NEUTRAL,
        )
        cases = [
            NEA(
                'two empty blocks',
                lines_content([
                    MAJOR_BLOCKS_SEPARATOR,
                ]),
                [
                    empty_block,
                    empty_block,
                ],
            ),
            NEA(
                'first non-empty, second empty',
                lines_content([
                    string_1,
                    MAJOR_BLOCKS_SEPARATOR,
                ]),
                [
                    non_empty_block,
                    empty_block,
                ],
            ),
            NEA(
                'first non-empty, second empty',
                lines_content([
                    string_1,
                    MAJOR_BLOCKS_SEPARATOR,
                ]),
                [
                    non_empty_block,
                    empty_block,
                ],
            ),
        ]

        for case in cases:
            check_block_sequence_and_document(self, case)
Example #5
0
def _header_only(header: str) -> text_struct.MajorBlock:
    return text_struct.MajorBlock([
        text_struct.MinorBlock([
            text_struct.LineElement(
                text_struct.StringLineObject(header)
            )
        ]),
    ])
Example #6
0
 def render(self) -> MajorBlock:
     return text_struct.MajorBlock([
         text_struct.MinorBlock([
             text_struct.LineElement(
                 text_struct.StringLineObject('program')
             )
         ])
     ])
def single_line_minor_block_w_plain_properties(
        line_contents: str) -> s.MinorBlock:
    return s.MinorBlock(
        [
            single_line_element_w_plain_properties(line_contents),
        ],
        s.ELEMENT_PROPERTIES__NEUTRAL,
    )
Example #8
0
    def test_non_empty_blocks_SHOULD_BE_separated_by_single_block_separator(
            self):
        # ARRANGE #
        string_1 = 'the 1st string'
        string_2 = 'the 2nd string'
        cases = [
            NEA(
                'two blocks, with different indent properties',
                lines_content([
                    string_1,
                    MINOR_BLOCKS_SEPARATOR,
                    MINOR_BLOCK_INDENT + LINE_ELEMENT_INDENT + string_2,
                ]),
                [
                    s.MinorBlock(
                        [
                            s.LineElement(
                                s.StringLineObject(string_1),
                                s.ELEMENT_PROPERTIES__NEUTRAL,
                            ),
                        ],
                        s.ELEMENT_PROPERTIES__NEUTRAL,
                    ),
                    s.MinorBlock(
                        [
                            s.LineElement(
                                s.StringLineObject(string_2),
                                s.ELEMENT_PROPERTIES__INDENTED,
                            ),
                        ],
                        s.ELEMENT_PROPERTIES__INDENTED,
                    ),
                ],
            ),
        ]

        for case in cases:
            with self.subTest(case.name):
                # ACT & ASSERT #
                check_minor_blocks(
                    self,
                    case.actual,
                    case.expected,
                )
Example #9
0
    def test_getters(self):
        # ARRANGE #

        parts_arg = []
        properties_arg = sut.ElementProperties(Indentation(0))
        block = sut.MinorBlock(parts_arg, properties_arg)

        # ACT && ASSERT #

        self.assertIs(parts_arg, block.parts, 'parts')
        self.assertIs(properties_arg, block.properties, 'properties_arg')
Example #10
0
    def render(self) -> MajorBlock:
        def_report_infos = map(mk_single_def_report_info, self.definitions)

        definition_lines = _get_list_lines(def_report_infos)

        return MajorBlock([
            structure.MinorBlock([
                structure.LineElement(
                    structure.StringLinesObject(definition_lines)
                )
            ])
        ])
Example #11
0
    def test_indentation_SHOULD_BE_applied_per_block(self):
        # ARRANGE #
        string_1 = 'the 1st string'
        string_2 = 'the 2nd string'
        cases = [
            NEA(
                'two blocks, with different indent properties',
                lines_content([
                    MINOR_BLOCK_INDENT + MINOR_BLOCK_INDENT + string_1,
                    MINOR_BLOCKS_SEPARATOR,
                    string_2,
                ]),
                [
                    s.MinorBlock(
                        [
                            single_line_element_w_plain_properties(string_1),
                        ],
                        s.indentation_properties(2),
                    ),
                    s.MinorBlock(
                        [
                            single_line_element_w_plain_properties(string_2),
                        ],
                        s.ELEMENT_PROPERTIES__NEUTRAL,
                    ),
                ],
            ),
        ]

        for case in cases:
            # ACT & ASSERT #
            check_minor_blocks(
                self,
                case.actual,
                case.expected,
            )
 def test_indentation_element_property_SHOULD_cause_indentation(self):
     # ARRANGE #
     line_object = s.StringLineObject('the string')
     for case in _INDENTATION_CASES:
         with self.subTest(case.name):
             # ACT & ASSERT #
             check_major_block(
                 self,
                 to_render=s.MajorBlock(
                     [
                         s.MinorBlock([s.LineElement(line_object)],
                                      s.ELEMENT_PROPERTIES__NEUTRAL)
                     ],
                     ElementProperties(case.actual, TEXT_STYLE__NEUTRAL),
                 ),
                 expectation=lines_content(
                     [case.expected + line_object.string]),
             )
    def test_non_empty_blocks_SHOULD_BE_separated_by_single_block_separator(
            self):
        # ARRANGE #
        string_1 = 'the 1st string'
        string_2 = 'the 2nd string'
        cases = [
            NEA(
                'two blocks, with different indent properties',
                lines_content([
                    string_1,
                    MAJOR_BLOCKS_SEPARATOR,
                    MAJOR_BLOCK_INDENT + MINOR_BLOCK_INDENT +
                    LINE_ELEMENT_INDENT + string_2,
                ]),
                [
                    s.MajorBlock(
                        [
                            single_line_minor_block_w_plain_properties(
                                string_1),
                        ],
                        s.ELEMENT_PROPERTIES__NEUTRAL,
                    ),
                    s.MajorBlock(
                        [
                            s.MinorBlock(
                                [
                                    s.LineElement(
                                        s.StringLineObject(string_2),
                                        s.ELEMENT_PROPERTIES__INDENTED,
                                    ),
                                ],
                                s.ELEMENT_PROPERTIES__INDENTED,
                            ),
                        ],
                        s.ELEMENT_PROPERTIES__INDENTED,
                    ),
                ],
            ),
        ]

        for case in cases:
            check_block_sequence_and_document(self, case)
Example #14
0
    def test_single_line__different_line_object_types_SHOULD_be_handled(self):
        # ARRANGE #
        single_line_string = 'the string'
        single_line_string_2 = 'the other string'

        cases = [
            NEA(
                'StringLine',
                MINOR_BLOCK_INDENT + LINE_ELEMENT_INDENT + single_line_string +
                '\n',
                s.MinorBlock(
                    [
                        s.LineElement(
                            s.StringLineObject(single_line_string),
                            s.ELEMENT_PROPERTIES__INDENTED,
                        )
                    ],
                    s.ELEMENT_PROPERTIES__INDENTED,
                ),
            ),
            NEA(
                'PreFormattedLine, without ending new-line',
                single_line_string + '\n',
                s.MinorBlock(
                    [
                        s.LineElement(
                            s.PreFormattedStringLineObject(
                                single_line_string, False),
                            s.ELEMENT_PROPERTIES__INDENTED,
                        )
                    ],
                    s.ELEMENT_PROPERTIES__INDENTED,
                ),
            ),
            NEA(
                'PreFormattedLine, with ending new-line',
                single_line_string + '\n',
                s.MinorBlock(
                    [
                        s.LineElement(
                            s.PreFormattedStringLineObject(
                                single_line_string + '\n', True),
                            s.ELEMENT_PROPERTIES__INDENTED,
                        )
                    ],
                    s.ELEMENT_PROPERTIES__INDENTED,
                ),
            ),
            NEA(
                'StringLines',
                lines_content([
                    MINOR_BLOCK_INDENT + LINE_ELEMENT_INDENT +
                    single_line_string,
                    MINOR_BLOCK_INDENT + LINE_ELEMENT_INDENT +
                    single_line_string_2,
                ]),
                s.MinorBlock(
                    [
                        s.LineElement(
                            s.StringLinesObject(
                                [single_line_string, single_line_string_2]),
                            s.ELEMENT_PROPERTIES__INDENTED,
                        )
                    ],
                    s.ELEMENT_PROPERTIES__INDENTED,
                ),
            ),
        ]

        for case in cases:
            with self.subTest(case.name):
                # ACT & ASSERT #
                check_minor_block(
                    self,
                    case.actual,
                    case.expected,
                )
Example #15
0
    def test_empty_blocks_SHOULD_BE_separated_by_single_block_separator(self):
        # Have not implemented filtering of non-empty blocks.
        # Reason is that such blocks should not be constructed.
        # But implement it if it appears to be useful for making
        # construction easier.

        # ARRANGE #
        string_1 = 'the 1st string'
        empty_block = s.MinorBlock(
            [],
            s.ELEMENT_PROPERTIES__NEUTRAL,
        )
        non_empty_block = s.MinorBlock(
            [
                s.LineElement(
                    s.StringLineObject(string_1),
                    s.ELEMENT_PROPERTIES__NEUTRAL,
                ),
            ],
            s.ELEMENT_PROPERTIES__NEUTRAL,
        )
        cases = [
            NEA(
                'two empty blocks',
                lines_content([
                    MINOR_BLOCKS_SEPARATOR,
                ]),
                [
                    empty_block,
                    empty_block,
                ],
            ),
            NEA(
                'first non-empty, second empty',
                lines_content([
                    string_1,
                    MINOR_BLOCKS_SEPARATOR,
                ]),
                [
                    non_empty_block,
                    empty_block,
                ],
            ),
            NEA(
                'first non-empty, second empty',
                lines_content([
                    string_1,
                    MINOR_BLOCKS_SEPARATOR,
                ]),
                [
                    non_empty_block,
                    empty_block,
                ],
            ),
        ]

        for case in cases:
            with self.subTest(case.name):
                # ACT & ASSERT #
                check_minor_blocks(
                    self,
                    case.actual,
                    case.expected,
                )
Example #16
0
    def test_multiple_line_elements(self):
        # ARRANGE #
        string_1 = 'the 1st string'
        string_2 = 'the 2nd string'
        string_3 = 'the 3rd string'
        string_4 = 'the 4th string'
        cases = [
            NEA(
                'multiple types, with plain block properties',
                lines_content([
                    string_1,
                    LINE_ELEMENT_INDENT + LINE_ELEMENT_INDENT + string_2,
                    LINE_ELEMENT_INDENT + string_3,
                    string_4,
                ]),
                s.MinorBlock(
                    [
                        s.LineElement(
                            s.StringLineObject(string_1),
                            s.ELEMENT_PROPERTIES__NEUTRAL,
                        ),
                        s.LineElement(
                            s.StringLineObject(string_2),
                            s.indentation_properties(2),
                        ),
                        s.LineElement(
                            s.StringLineObject(string_3),
                            s.indentation_properties(1),
                        ),
                        s.LineElement(
                            s.PreFormattedStringLineObject(string_4, False),
                            s.ELEMENT_PROPERTIES__INDENTED,
                        ),
                    ],
                    s.ELEMENT_PROPERTIES__NEUTRAL,
                ),
            ),
            NEA(
                'multiple types, with indent block properties',
                lines_content([
                    MINOR_BLOCK_INDENT + string_1,
                    MINOR_BLOCK_INDENT + LINE_ELEMENT_INDENT + string_2,
                    string_3,
                ]),
                s.MinorBlock(
                    [
                        s.LineElement(
                            s.StringLineObject(string_1),
                            s.ELEMENT_PROPERTIES__NEUTRAL,
                        ),
                        s.LineElement(
                            s.StringLineObject(string_2),
                            s.ELEMENT_PROPERTIES__INDENTED,
                        ),
                        s.LineElement(
                            s.PreFormattedStringLineObject(string_3, False),
                            s.ELEMENT_PROPERTIES__INDENTED,
                        ),
                    ],
                    s.ELEMENT_PROPERTIES__INDENTED,
                ),
            ),
        ]

        for case in cases:
            with self.subTest(case.name):
                # ACT & ASSERT #
                check_minor_block(
                    self,
                    case.actual,
                    case.expected,
                )