Exemplo n.º 1
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)
            ]),
        )
Exemplo n.º 2
0
 def test_matches(self):
     cases = [
         NEA(
             'default',
             expected=sut.matches_element_properties(),
             actual=ElementProperties(Indentation(1, ''),
                                      TEXT_STYLE__NEUTRAL),
         ),
         NEA(
             'indentation',
             expected=sut.matches_element_properties(
                 indentation=sut.matches_indentation(
                     level=asrt.equals(69)), ),
             actual=ElementProperties(Indentation(69, ''),
                                      TEXT_STYLE__NEUTRAL),
         ),
         NEA(
             'text_style',
             expected=sut.matches_element_properties(
                 text_style=sut.matches_text_style(
                     color=asrt.equals(ForegroundColor.GREEN)), ),
             actual=ElementProperties(
                 INDENTATION__NEUTRAL, TextStyle(ForegroundColor.GREEN,
                                                 None)),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             case.expected.apply_without_message(self, case.actual)
Exemplo n.º 3
0
 def test_matches(self):
     cases = [
         NEA(
             'empty list of blocks',
             expected=sut.matches_major_block(asrt.is_empty_sequence),
             actual=MajorBlock([]),
         ),
         NEA(
             'non-empty list of blocks',
             expected=sut.matches_major_block(
                 asrt.matches_sequence([asrt.is_instance(MinorBlock)])),
             actual=MajorBlock([MinorBlock([])]),
         ),
         NEA(
             'test of element properties',
             expected=sut.matches_major_block(
                 asrt.anything_goes(),
                 properties=sut.matches_element_properties(
                     indentation=sut.matches_indentation(
                         level=asrt.equals(72))),
             ),
             actual=MajorBlock([],
                               ElementProperties(Indentation(72, ''),
                                                 TEXT_STYLE__NEUTRAL)),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             case.expected.apply_without_message(self, case.actual)
Exemplo n.º 4
0
 def test_color_and_font_style_SHOULD_cause_text_to_be_surrounded_by_color_and_style_codes(
         self):
     # ARRANGE #
     text_color = ForegroundColor.BLUE
     font_style = FontStyle.BOLD
     line_object = s.StringLineObject('line object text',
                                      string_is_line_ended=False)
     # ACT & ASSERT #
     check_line_element(
         self,
         s.LineElement(
             line_object,
             ElementProperties(
                 s.INDENTATION__NEUTRAL,
                 TextStyle(color=text_color, font_style=font_style))),
         ''.join([
             FilePrinterWithTextPropertiesForTest.font_style_string_for(
                 font_style),
             FilePrinterWithTextPropertiesForTest.color_string_for(
                 text_color),
             line_object.string,
             '\n',
             FilePrinterWithTextPropertiesForTest.UNSET_COLOR,
             FilePrinterWithTextPropertiesForTest.UNSET_FONT_STYLE,
         ]),
     )
Exemplo n.º 5
0
 def _text_styled_root_element_properties(self, text_style: Optional[TextStyle]) -> ElementProperties:
     return (
         self._root_element_properties
         if text_style is None
         else ElementProperties(
             self._root_element_properties.indentation,
             text_style,
         )
     )
Exemplo n.º 6
0
 def __init__(self,
              configuration: RenderingConfiguration,
              depth: int,
              detail: Detail,
              ):
     self._configuration = configuration
     self._depth = depth
     self._detail = detail
     self._indent_suffix = configuration.detail_indent
     self._root_element_properties = ElementProperties(
         structure.Indentation(depth + 1, self._indent_suffix)
     )
Exemplo n.º 7
0
 def test_not_matches(self):
     cases = [
         NEA(
             'indentation',
             expected=sut.matches_element_properties(
                 indentation=sut.matches_indentation(
                     level=asrt.equals(1)), ),
             actual=ElementProperties(Indentation(0, ''),
                                      TEXT_STYLE__NEUTRAL),
         ),
         NEA(
             'text_style',
             expected=sut.matches_element_properties(
                 text_style=sut.matches_text_style(
                     color=asrt.equals(ForegroundColor.GREEN)), ),
             actual=ElementProperties(INDENTATION__NEUTRAL,
                                      TextStyle(ForegroundColor.RED, None)),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             assert_that_assertion_fails(case.expected, case.actual)
Exemplo n.º 8
0
 def test_indentation_element_property_SHOULD_cause_indentation(self):
     # ARRANGE #
     for indentation_case in _INDENTATION_CASES:
         for case in self.cases:
             with self.subTest(line_object=case.name,
                               indentation=indentation_case.name):
                 # ACT & ASSERT #
                 check_line_element(
                     self,
                     s.LineElement(
                         case.actual,
                         ElementProperties(indentation_case.actual,
                                           TEXT_STYLE__NEUTRAL)),
                     indentation_case.expected + case.expected,
                 )
Exemplo n.º 9
0
def matches_detail_properties(
    depth: int,
    text_style: TextStyle = TEXT_STYLE__NEUTRAL
) -> Assertion[s.ElementProperties]:
    return asrt_struct.equals_element_properties(
        expected_detail_properties(depth, text_style))


STRING_OBJECT_CASES = [
    NameAndValue(
        'constant',
        'a string constant',
    ),
    NameAndValue(
        'must apply str',
        str_constructor.FormatPositional(
            '{}',
            'a string that is generated',
        ),
    ),
]

_HEADER_PROPERTIES_FOR_F = ElementProperties(
    INDENTATION__NEUTRAL,
    TextStyle(color=ForegroundColor.RED, font_style=FontStyle.BOLD),
)
_HEADER_PROPERTIES_FOR_T = ElementProperties(
    INDENTATION__NEUTRAL,
    TextStyle(color=ForegroundColor.GREEN),
)
Exemplo n.º 10
0

def _make_header(node: Node[bool]) -> str:
    bool_char = bool_string(node.data)

    return '({}) {}'.format(bool_char, node.header)


def bool_string(b: bool) -> str:
    return 'T' if b else 'F'


# Makes details at level 0 appear aligned with the node header
DETAILS_INDENT = ' ' * len('(B) ')
MINOR_BLOCKS_INDENT_INCREASE = Indentation(1, '  ')
_HEADER_PROPERTIES_FOR_F = ElementProperties(INDENTATION__NEUTRAL, TextStyle(color=ForegroundColor.BRIGHT_RED))
_HEADER_PROPERTIES_FOR_T = ElementProperties(INDENTATION__NEUTRAL, TextStyle(color=ForegroundColor.BRIGHT_GREEN))


def _get_header_style(node: Node[bool]) -> ElementProperties:
    return (
        _HEADER_PROPERTIES_FOR_T
        if node.data
        else
        _HEADER_PROPERTIES_FOR_F
    )


RENDERING_CONFIGURATION = RenderingConfiguration(
    _make_header,
    _get_header_style,
Exemplo n.º 11
0
def _expected_header_style(node: Node[bool]) -> ElementProperties:
    return ElementProperties(INDENTATION__NEUTRAL,
                             TextStyle(color=_expected_header_color(node)),
                             )