def test_not_matches(self): cases = [ NEA( 'color - different values', expected=sut.matches_text_style(color=asrt.equals( ForegroundColor.GREEN), ), actual=TextStyle(ForegroundColor.RED, None), ), NEA( 'color - actual is None', expected=sut.matches_text_style(color=asrt.equals( ForegroundColor.GREEN), ), actual=TextStyle(None, None), ), NEA( 'font_style - different values', expected=sut.matches_text_style(font_style=asrt.equals( FontStyle.UNDERLINE), ), actual=TextStyle(None, FontStyle.BOLD), ), NEA( 'font_style - actual is None', expected=sut.matches_text_style(font_style=asrt.equals( FontStyle.UNDERLINE), ), actual=TextStyle(None, None), ), ] for case in cases: with self.subTest(case.name): assert_that_assertion_fails(case.expected, case.actual)
def test_matches(self): cases = [ NEA( 'default 1', expected=sut.matches_text_style(), actual=TextStyle(None, None), ), NEA( 'default/w color', expected=sut.matches_text_style(), actual=TextStyle(ForegroundColor.GREEN, None), ), NEA( 'default/w style', expected=sut.matches_text_style(), actual=TextStyle(None, FontStyle.BOLD), ), NEA( 'color', expected=sut.matches_text_style(color=asrt.equals( ForegroundColor.GREEN), ), actual=TextStyle(ForegroundColor.GREEN, None), ), NEA( 'font_style', expected=sut.matches_text_style(font_style=asrt.equals( FontStyle.BOLD), ), actual=TextStyle(None, FontStyle.BOLD), ), ] for case in cases: with self.subTest(case.name): case.expected.apply_without_message(self, case.actual)
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)
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, ]), )
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, )
def test_node_with_child(self): # ARRANGE # child = Node('the child', None, (), ()) tree_in_detail = Node('the contained tree root', None, (), (child, )) text_style__non_neutral = TextStyle(font_style=FontStyle.BOLD) header_text_style_cases = [ NEA( 'default text style', TEXT_STYLE__NEUTRAL, TreeDetail(tree_in_detail), ), NEA( 'custom text style', text_style__non_neutral, TreeDetail(tree_in_detail, text_style__non_neutral), ), ] for header_text_style_case in header_text_style_cases: with self.subTest(header_text_style_case.name): tree_detail = header_text_style_case.actual root = Node('the root', False, [tree_detail], ()) # EXPECTATION # expectation = matches_trace_with_details( root, [ matches_detail_line_element( tree_in_detail.header, depth=0, text_style=header_text_style_case.expected), matches_detail_line_element( child.header, depth=1, text_style=header_text_style_case.expected), ], ) # ACT & ASSERT # _check(self, root, expectation)
def test_header_and_value_detail(self): # ARRANGE # text_style__non_neutral = TextStyle(font_style=FontStyle.UNDERLINE) cases = [ NIE( 'without text style', TEXT_STYLE__NEUTRAL, TEXT_STYLE__NEUTRAL, ), NIE( 'with text style', text_style__non_neutral, text_style__non_neutral, ), ] for case in cases: with self.subTest(case.name): value_detail = StringDetail('the value detail') header_and_value_detail = HeaderAndValueDetail( 'the header', [value_detail], case.input_value) root = Node('the root', False, [header_and_value_detail], ()) # EXPECTATION # expectation = matches_trace_with_details( root, [ matches_detail_line_element( header_and_value_detail.header, depth=0, text_style=case.expected_value), matches_string_detail_line_element(value_detail, depth=1), ], ) # ACT & ASSERT # _check(self, root, expectation)
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)
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), )
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,
def _expected_header_style(node: Node[bool]) -> ElementProperties: return ElementProperties(INDENTATION__NEUTRAL, TextStyle(color=_expected_header_color(node)), )