Ejemplo n.º 1
0
def indentation_cases(indent_str: str) -> List[NEA[str, Indentation]]:
    level_cases = [
        NEA(
            'indentation level of ' + str(level),
            expected=indent_str * level,
            actual=Indentation(level, ''),
        ) for level in [0, 1, 2]
    ]

    suffix_value = '<indent suffix>'

    suffix_cases = [
        NEA(
            'indentation suffix of ' + suffix_value,
            expected=suffix_value,
            actual=Indentation(0, suffix_value),
        )
    ]
    level_value = 2

    mixed_cases = [
        NEA(
            'indentation level {} and suffix of {}'.format(
                level_value, suffix_value),
            expected=indent_str * level_value + suffix_value,
            actual=Indentation(level_value, suffix_value),
        )
    ]

    return level_cases + suffix_cases + mixed_cases
Ejemplo 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)
Ejemplo n.º 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)
            ]),
        )
Ejemplo n.º 4
0
def expected_detail_properties(
        depth: int,
        text_style: TextStyle = TEXT_STYLE__NEUTRAL) -> s.ElementProperties:
    return s.ElementProperties(
        Indentation(depth + 1, RENDERING_CONFIGURATION.detail_indent),
        text_style,
    )
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
 def test_not_matches(self):
     cases = [
         NEA(
             'level',
             expected=sut.matches_indentation(level=asrt.equals(1), ),
             actual=Indentation(0, ''),
         ),
         NEA(
             'suffix',
             expected=sut.matches_indentation(
                 suffix=asrt.equals('expected'), ),
             actual=Indentation(0, 'actual'),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             assert_that_assertion_fails(case.expected, case.actual)
Ejemplo n.º 7
0
    def test_getters(self):
        # ARRANGE #

        parts = []
        properties_arg = sut.ElementProperties(Indentation(0))
        block = sut.MajorBlock(parts, properties_arg)

        # ACT && ASSERT #

        self.assertIs(parts, block.parts, 'parts')
        self.assertIs(properties_arg, block.properties, 'properties_arg')
Ejemplo n.º 8
0
 def test_matches(self):
     cases = [
         NEA(
             'default',
             expected=sut.matches_indentation(),
             actual=Indentation(1, 'a suffix'),
         ),
         NEA(
             'level',
             expected=sut.matches_indentation(level=asrt.equals(1), ),
             actual=Indentation(1, ''),
         ),
         NEA(
             'suffix',
             expected=sut.matches_indentation(
                 suffix=asrt.equals('a suffix'), ),
             actual=Indentation(1, 'a suffix'),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             case.expected.apply_without_message(self, case.actual)
Ejemplo n.º 9
0
    def test_element_properties_SHOULD_be_ignored(self):
        # ARRANGE #
        ep_with_indent = s.ElementProperties(
            Indentation(1),
            TextStyle(color=ForegroundColor.BLUE,
                      font_style=FontStyle.UNDERLINE),
        )

        for case in self.cases:
            with self.subTest(case.name):
                # ACT & ASSERT #
                check_line_element(
                    self,
                    s.LineElement(case.actual, ep_with_indent),
                    case.expected,
                )
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
def expected_node_indentation(depth: int) -> Indentation:
    return Indentation(
        depth * RENDERING_CONFIGURATION.minor_block_indent.level,
        depth * RENDERING_CONFIGURATION.minor_block_indent.suffix)
Ejemplo n.º 12
0
    expectation.apply_with_message(put, block, 'from node-renderer')


def _get_header(node: Node[bool]) -> str:
    return ':'.join([str(node.data), node.header])


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


RENDERING_CONFIGURATION = RenderingConfiguration(
    _get_header,
    _get_header_style,
    Indentation(2, '<MINOR-BLOCK-CUSTOM-INDENT>'),
    '<DETAIL-INDENT>',
)


def matches_trace_with_just_single_detail(
    trace: Node[bool],
    detail: Assertion[s.LineElement],
) -> Assertion[s.MajorBlock]:
    return matches_trace_with_details(trace, [detail])


def matches_trace_with_details(
    tree: Node[bool],
    details: Sequence[Assertion[s.LineElement]],
) -> Assertion[s.MajorBlock]:
Ejemplo n.º 13
0
from exactly_lib.util.simple_textstruct.structure import Indentation, ElementProperties, INDENTATION__NEUTRAL, TextStyle


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,
Ejemplo n.º 14
0
def expected_detail_properties(level: int) -> s.ElementProperties:
    return s.ElementProperties(
        Indentation(level,
                    _EXPECTED_DETAIL_INDENT_SUFFIX),
        TEXT_STYLE__NEUTRAL,
    )