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,
                )
    def _visit_exception(self, ed: error_description.ErrorDescriptionOfException) -> Sequence[MajorBlock]:
        minor_blocks = self._message_blocks(ed)
        minor_blocks.append(
            struct.minor_block_from_lines([
                struct.StringLineObject('Exception:'),
                struct.PreFormattedStringLineObject(str(ed.exception), False),
            ])
        )

        return [MajorBlock(minor_blocks)]
Beispiel #3
0
class TestLineElementOfPreFormattedString(unittest.TestCase):
    single_line_string = 'the string'
    multi_line_string = 'the first line\nthe second line'
    cases = [
        NEA(
            'single line, no ending new line',
            single_line_string + '\n',
            s.PreFormattedStringLineObject(
                single_line_string,
                False,
            ),
        ),
        NEA(
            'single line, with ending new line',
            single_line_string + '\n',
            s.PreFormattedStringLineObject(
                single_line_string + '\n',
                True,
            ),
        ),
        NEA(
            'multiple lines, no ending new line',
            multi_line_string + '\n',
            s.PreFormattedStringLineObject(
                multi_line_string + '\n',
                True,
            ),
        ),
    ]

    def test_with_plain_element_properties(self):
        # ARRANGE #
        element_properties = s.ELEMENT_PROPERTIES__NEUTRAL

        for case in self.cases:
            with self.subTest(case.name):
                # ACT & ASSERT #
                check_line_element(
                    self,
                    s.LineElement(case.actual, element_properties),
                    case.expected,
                )
Beispiel #4
0
    def test_getters(self):
        # ARRANGE #

        string_arg = 's'
        line_ended_arg = False
        line_object = sut.PreFormattedStringLineObject(string_arg,
                                                       line_ended_arg)

        # ACT && ASSERT #

        self.assertIs(string_arg, line_object.string, 'string')

        self.assertIs(line_ended_arg, line_object.string_is_line_ended,
                      'string_is_line_ended')
    def _visit_external_process_error(self, ed: error_description.ErrorDescriptionOfExternalProcessError
                                      ) -> Sequence[MajorBlock]:
        minor_blocks = self._message_blocks(ed)
        lines = [struct.StringLineObject(misc_texts.EXIT_CODE_TITLE + ': ' +
                                         str(ed.external_process_error.exit_code))]

        if ed.external_process_error.stderr_output:
            lines.append(struct.PreFormattedStringLineObject(ed.external_process_error.stderr_output, False))

        minor_blocks.append(
            struct.minor_block_from_lines(lines)
        )

        return [MajorBlock(minor_blocks)]
Beispiel #6
0
    def test_accept_visitor(self):
        # ARRANGE #

        line_object = sut.PreFormattedStringLineObject('s', False)
        visitor = VisitorThatRegistersVisitedClassesAndReturnsTheEnv()
        env = 'PreFormattedStringLineObject'

        # ACT #

        return_value = line_object.accept(visitor, env)

        # ASSERT #

        self.assertEqual(env, return_value, 'return value')
        self.assertEqual([sut.PreFormattedStringLineObject],
                         visitor.visited_classes, 'visitor method')
Beispiel #7
0
    def _exception_blocks(self) -> List[MajorBlock]:
        if not self._failure_details.has_exception:
            return []

        ex = self._failure_details.exception

        return [
            MajorBlock([
                struct.minor_block_from_lines([
                    struct.StringLineObject('Exception'),
                ]),
                struct.minor_block_from_lines([
                    struct.PreFormattedStringLineObject(str(ex), False),
                ]),
            ])
        ]
    def render(self) -> MajorBlock:
        s = self._x.render()
        header = _type_of_x_elements_header(len(s),
                                            types.STRING_TYPE_INFO,
                                            type_system.NUMBER_OF_STRING_CHARACTERS)

        if len(s) == 0:
            return _header_only(header)
        else:
            return _header_and_value(
                header,
                [text_struct.LineElement(
                    text_struct.PreFormattedStringLineObject(s, False)
                )
                ],
                text_struct.ELEMENT_PROPERTIES__NEUTRAL,
            )
Beispiel #9
0
 def render(self) -> LineObject:
     return structure.PreFormattedStringLineObject(str(self._x), self._string_is_line_ended)
Beispiel #10
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,
                )
Beispiel #11
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,
                )
Beispiel #12
0
 def visit_pre_formatted_string(self, x: PreFormattedStringDetail) -> Sequence[LineElement]:
     return [
         LineElement(structure.PreFormattedStringLineObject(str(x.object_with_to_string),
                                                            x.string_is_line_ended),
                     self._root_element_properties)
     ]