def test_matches(self): cases = [ NEA( 'empty list of line elements', expected=sut.matches_minor_block(asrt.is_empty_sequence), actual=MinorBlock([]), ), NEA( 'non-empty list of line elements', expected=sut.matches_minor_block( asrt.matches_sequence([asrt.is_instance(LineElement)])), actual=MinorBlock( [LineElement(StringLineObject('the string'))]), ), NEA( 'test of element properties', expected=sut.matches_minor_block( asrt.anything_goes(), properties=sut.matches_element_properties( indentation=sut.matches_indentation( level=asrt.equals(72))), ), actual=MinorBlock([], ElementProperties(Indentation(72, ''), TEXT_STYLE__NEUTRAL)), ), ] for case in cases: with self.subTest(case.name): case.expected.apply_without_message(self, case.actual)
def test_not_matches(self): cases = [ NEA( 'actual is empty list of line elements', expected=sut.matches_major_block( asrt.not_(asrt.is_empty_sequence)), actual=MajorBlock([]), ), NEA( 'actual element is unexpected', expected=sut.matches_major_block( asrt.matches_sequence( [asrt.not_(asrt.is_instance(MinorBlock))])), actual=MajorBlock([MinorBlock([])]), ), NEA( 'unexpected element properties', expected=sut.matches_major_block( asrt.anything_goes(), properties=asrt.not_(asrt.is_instance(ElementProperties))), actual=MajorBlock( [MinorBlock([], ELEMENT_PROPERTIES__NEUTRAL)]), ), ] for case in cases: with self.subTest(case.name): assert_that_assertion_fails(case.expected, case.actual)
def render(self) -> MajorBlock: return MajorBlock([ MinorBlock([ struct.LineElement( struct.StringLineObject(self._single_line_info_str())), ]) ])
def test_not_matches(self): cases = [ NIE( 'default assertion/not a renderer', input_value=MajorBlock([]), expected_value=sut.is_renderer_of_major_blocks(), ), NIE( 'default assertion/not a sequence', input_value=rend_comb.ConstantR(MajorBlock([])), expected_value=sut.is_renderer_of_major_blocks(), ), NIE( 'default assertion/not a major block', input_value=rend_comb.ConstantSequenceR([MinorBlock([])]), expected_value=sut.is_renderer_of_major_blocks(), ), NIE( 'default assertion/invalid contents of block', input_value=rend_comb.ConstantSequenceR( [MajorBlock(['not a minor block'])]), expected_value=sut.is_renderer_of_major_blocks(), ), NIE( 'custom assertion/unexpected number of blocks', input_value=rend_comb.ConstantSequenceR([]), expected_value=sut.is_renderer_of_major_blocks( asrt.len_equals(1)), ), ] for case in cases: with self.subTest(case.name): assert_that_assertion_fails(case.expected_value, case.input_value)
def _mk_minor_block(lines: Block) -> MinorBlock: return MinorBlock([ LineElement( PreFormattedStringLineObject(line, False) ) for line in lines ] )
def render(self) -> MinorBlock: return MinorBlock( [ text_struct.LineElement( text_struct.StringLineObject(line.render())) for line in self._path.renders() ], self._element_properties, )
def render_sequence(self) -> Sequence[MinorBlock]: if self._description is None: return [] else: return [ MinorBlock([ LineElement( PreFormattedStringLineObject( _description_str(self._description), False)) ]) ]
def test_matches(self): cases = [ NIE( 'default assertion/empty list of blocks', input_value=rend_comb.ConstantSequenceR([]), expected_value=sut.is_renderer_of_minor_blocks(), ), NIE( 'default assertion/non-empty list of blocks', input_value=rend_comb.ConstantSequenceR([MinorBlock([])]), expected_value=sut.is_renderer_of_minor_blocks(), ), NIE( 'custom assertion', input_value=rend_comb.ConstantSequenceR([MinorBlock([])]), expected_value=sut.is_renderer_of_minor_blocks( asrt.len_equals(1)), ), ] for case in cases: with self.subTest(case.name): case.expected_value.apply_without_message( self, case.input_value)
def _files_and_source_path_leading_to_final_source( referrer_location: Path, the_file_inclusion_chain: Sequence[SourceLocation], final_source_line_number: Optional[int], final_file_path_rel_referrer: Optional[Path], ) -> MinorBlock: lines, referrer_location = file_inclusion_chain(referrer_location, the_file_inclusion_chain) if final_source_line_number is not None: lines += [ _line_in_optional_file(referrer_location, final_file_path_rel_referrer, final_source_line_number) ] return MinorBlock(lines)
def source_lines_block(lines: Sequence[str]) -> MinorBlock: return MinorBlock([source_lines_element(lines)], SOURCE_LINES_BLOCK_PROPERTIES)
def render(self) -> MinorBlock: return MinorBlock([ text_struct.LineElement( text_struct.StringLineObject( render_failing_property(self._cause))) ])
def render(self) -> MinorBlock: return MinorBlock( self._explanation.render_sequence(), text_struct.ELEMENT_PROPERTIES__INDENTED, )
def render(self) -> MinorBlock: header = LineElement( text_struct.StringLineObject(str(self._single_line_to_str))) return MinorBlock([header])
def render(self) -> MinorBlock: return MinorBlock( self._contents.render_sequence(), self._properties, )
def _root(self) -> MinorBlock: return MinorBlock( [self._header_line()] + list(self._details_renderer().render_sequence()) )
def print_line_elements(line_element: Sequence[LineElement]) -> str: block = MinorBlock(line_element, ELEMENT_PROPERTIES__NEUTRAL) printable = PrintablesFactory(LAYOUT).minor_block(block) return print_to_str(printable)