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 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 render(self) -> MajorBlock: the_list = self._list.render_sequence() header = _type_of_x_elements_header(len(the_list), types.LIST_TYPE_INFO, type_system.NUMBER_OF_LIST_ELEMENTS) if len(the_list) == 0: return _header_only(header) num_formatter = ( self._format_lt_10 if len(the_list) < 10 else self._format_gte_10 ) value_list = [ text_struct.LineElement( text_struct.StringLineObject( ' '.join([num_formatter(n), elem, ])) ) for n, elem in enumerate(the_list, 1) ] return _header_and_value( header, value_list, text_struct.ELEMENT_PROPERTIES__INDENTED, )
def render(self) -> MajorBlock: return MajorBlock([ MinorBlock([ struct.LineElement( struct.StringLineObject(self._single_line_info_str())), ]) ])
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 _header_only(header: str) -> text_struct.MajorBlock: return text_struct.MajorBlock([ text_struct.MinorBlock([ text_struct.LineElement( text_struct.StringLineObject(header) ) ]), ])
def render(self) -> MajorBlock: return text_struct.MajorBlock([ text_struct.MinorBlock([ text_struct.LineElement( text_struct.StringLineObject('program') ) ]) ])
def _header_line(self) -> LineElement: node = self._tree s = self._configuration.header(node) return LineElement( structure.StringLineObject(s), self._configuration.header_style(self._tree), )
def render(self) -> MinorBlock: return MinorBlock( [ text_struct.LineElement( text_struct.StringLineObject(line.render())) for line in self._path.renders() ], self._element_properties, )
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, )
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)]
class TestLineElementOfStringLine(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.StringLineObject( single_line_string, False, ), ), NEA( 'single line, with ending new line', single_line_string + '\n', s.StringLineObject( single_line_string + '\n', True, ), ), NEA( 'multiple lines, no ending new line', multi_line_string + '\n', s.StringLineObject( 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, )
def test_getters(self): # ARRANGE # string_arg = 's' line_ended_arg = False line_object = sut.StringLineObject(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_header_and_value(self, x: HeaderAndValueDetail) -> Sequence[LineElement]: value_elements_renderer = rend_comb.ConcatenationR([ self._renderer_for_next_depth(value) for value in x.values ]) ret_val = [ LineElement(structure.StringLineObject(str(x.header)), self._text_styled_root_element_properties(x.header_text_style)) ] ret_val += value_elements_renderer.render_sequence() return ret_val
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)]
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, ), ])
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_minor_block( self, to_render=s.MinorBlock( [s.LineElement(line_object)], ElementProperties(case.actual, TEXT_STYLE__NEUTRAL), ), expectation=lines_content( [case.expected + line_object.string]), )
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 test_accept_visitor(self): # ARRANGE # line_object = sut.StringLineObject('s', False) visitor = VisitorThatRegistersVisitedClassesAndReturnsTheEnv() env = 'StringLineObject' # ACT # return_value = line_object.accept(visitor, env) # ASSERT # self.assertEqual(env, return_value, 'return value') self.assertEqual([sut.StringLineObject], visitor.visited_classes, 'visitor method')
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)
def visit_tree(self, x: TreeDetail) -> Sequence[LineElement]: tree = x.tree details_renderer = rend_comb.ConcatenationR([ self._renderer_for_next_depth(detail) for detail in tree.details ]) children_renderer = rend_comb.ConcatenationR([ self._renderer_for_next_depth(TreeDetail(child, x.header_text_style)) for child in tree.children ]) ret_val = [ LineElement(structure.StringLineObject(str(tree.header)), self._text_styled_root_element_properties(x.header_text_style)) ] ret_val += details_renderer.render_sequence() ret_val += children_renderer.render_sequence() return ret_val
def render(self) -> LineObject: return structure.StringLineObject( self._line + ':', False, )
def __error_message(self) -> MinorTextRenderer: return blocks.MinorBlocksOfSingleLineObject( comb.ConstantR(structure.StringLineObject( 'Error from preprocessing by: ' + str(self.external_program)) ) )
def single_line_element_w_plain_properties(line_contents): return s.LineElement( s.StringLineObject(line_contents), s.ELEMENT_PROPERTIES__NEUTRAL, )
def render(self) -> MinorBlock: return MinorBlock([ text_struct.LineElement( text_struct.StringLineObject( render_failing_property(self._cause))) ])
def render_sequence(self) -> Sequence[LineElement]: return [ LineElement(text_struct.StringLineObject( 'Mode is ' + stat.filemode(self._st_mode)) ), ]
def render(self) -> MinorBlock: header = LineElement( text_struct.StringLineObject(str(self._single_line_to_str))) return MinorBlock([header])
def plain_line_elements_of_string_lines( lines: Sequence[str]) -> SequenceRenderer[LineElement]: return rend_comb.ConstantSequenceR( [LineElement(text_struct.StringLineObject(line)) for line in lines])
return helper.apply(sdv, model) def _file_matcher_for_expectation_type(self) -> FileMatcherSdv: return (self.file_matcher if self._is_positive_check() else combinator_sdvs.Negation(self.file_matcher)) def _is_positive_check(self) -> bool: return self.expectation_type is ExpectationType.POSITIVE _ERROR_MESSAGE_HEADER = 'Failure for path:' _FILE_EXISTS_BUT_INVALID_PROPERTIES_ERR_MSG_HEADER = rend_comb.SingletonSequenceR( rend_comb.ConstantR( text_struct.LineElement( text_struct.StringLineObject('File exists, but:')))) _EXISTING_PATH_FAILURE_FORMAT_MAP = { 'PATH': syntax_elements.PATH_SYNTAX_ELEMENT.singular_name, 'FILE_MATCHER': syntax_elements.FILE_MATCHER_SYNTAX_ELEMENT.singular_name, } _PROPERTIES_DESCRIPTION = """\ Applies a {FILE_MATCHER} on {PATH}, if it exists. """ _NOTES = """\ Symbolic links are not followed in the test of existence (so a broken symbolic link is considered to exist). """
def render(self) -> LineObject: return structure.StringLineObject(str(self.x), False)