コード例 #1
0
 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)
コード例 #2
0
 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)
コード例 #3
0
ファイル: individual.py プロジェクト: emilkarlen/exactly
 def render(self) -> MajorBlock:
     return MajorBlock([
         MinorBlock([
             struct.LineElement(
                 struct.StringLineObject(self._single_line_info_str())),
         ])
     ])
コード例 #4
0
 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)
コード例 #5
0
ファイル: block_text_docs.py プロジェクト: emilkarlen/exactly
def _mk_minor_block(lines: Block) -> MinorBlock:
    return MinorBlock([
        LineElement(
            PreFormattedStringLineObject(line, False)
        )
        for line in lines
    ]
    )
コード例 #6
0
ファイル: path_rendering.py プロジェクト: emilkarlen/exactly
 def render(self) -> MinorBlock:
     return MinorBlock(
         [
             text_struct.LineElement(
                 text_struct.StringLineObject(line.render()))
             for line in self._path.renders()
         ],
         self._element_properties,
     )
コード例 #7
0
ファイル: source_location.py プロジェクト: emilkarlen/exactly
 def render_sequence(self) -> Sequence[MinorBlock]:
     if self._description is None:
         return []
     else:
         return [
             MinorBlock([
                 LineElement(
                     PreFormattedStringLineObject(
                         _description_str(self._description), False))
             ])
         ]
コード例 #8
0
 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)
コード例 #9
0
ファイル: source_location.py プロジェクト: emilkarlen/exactly
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)
コード例 #10
0
ファイル: source_location.py プロジェクト: emilkarlen/exactly
def source_lines_block(lines: Sequence[str]) -> MinorBlock:
    return MinorBlock([source_lines_element(lines)],
                      SOURCE_LINES_BLOCK_PROPERTIES)
コード例 #11
0
 def render(self) -> MinorBlock:
     return MinorBlock([
         text_struct.LineElement(
             text_struct.StringLineObject(
                 render_failing_property(self._cause)))
     ])
コード例 #12
0
ファイル: path_rendering.py プロジェクト: emilkarlen/exactly
 def render(self) -> MinorBlock:
     return MinorBlock(
         self._explanation.render_sequence(),
         text_struct.ELEMENT_PROPERTIES__INDENTED,
     )
コード例 #13
0
 def render(self) -> MinorBlock:
     header = LineElement(
         text_struct.StringLineObject(str(self._single_line_to_str)))
     return MinorBlock([header])
コード例 #14
0
 def render(self) -> MinorBlock:
     return MinorBlock(
         self._contents.render_sequence(),
         self._properties,
     )
コード例 #15
0
 def _root(self) -> MinorBlock:
     return MinorBlock(
         [self._header_line()] +
         list(self._details_renderer().render_sequence())
     )
コード例 #16
0
ファイル: render_to_str.py プロジェクト: emilkarlen/exactly
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)