def _do_freeze(self, put: unittest.TestCase, source: StringSource): try: source.freeze() except HardErrorException as ex: put.fail( self._message_builder.for_sub_component('freeze').apply( 'freeze raised HardErrorException: ' + str(ex)))
def matches_w_trace(self, model: StringSource) -> MatchingResult: actual = model.contents().as_str if self.expected == actual: return self._new_tb().build_result(True) else: err_msg = 'not eq to "{}": "{}"'.format(self.expected, actual) return (self._new_tb().append_details( details.String(err_msg)).build_result(False))
def transformed_string_source_from_writer(write: Callable[[StringSourceContents, TextIO], None], model: StringSource, get_transformer_structure: Callable[[], StructureRenderer], mem_buff_size: int, file_name: Optional[str] = None, ) -> StringSource: def new_structure_builder() -> StringSourceStructureBuilder: return model.new_structure_builder().with_transformed_by(get_transformer_structure()) model_contents = model.contents() return cached_frozen.StringSourceWithCachedFrozen( new_structure_builder, contents_via_write_to.ContentsViaWriteTo( model_contents.tmp_file_space, _WriterOfTransformed(write, model_contents), file_name, ), mem_buff_size, file_name, )
def _mb_force_evaluation_of_model(self, model: StringSource): if self._force_evaluation_of_model: with model.contents().as_lines: pass
def _get_contents_as_str(x: StringSource) -> str: return x.contents().as_str
def get_from(self, model: StringSource) -> str: return model.contents().as_str
def get_string_source_contents(x: StringSource) -> StringSourceContents: return x.contents()
def get_from(self, model: StringSource) -> int: ret_val = 0 with model.contents().as_lines as lines: for _ in lines: ret_val += 1 return ret_val
def get_string_matcher_model_as_single_string( model: StringSource) -> str: return model.contents().as_str
def _freeze_string_source(x: StringSource): x.freeze()
def _get_line_elements( tcds: TestCaseDs, environment: ApplicationEnvironment, string_matcher_model: StringSource ) -> ContextManager[Iterator[LineMatcherLine]]: with string_matcher_model.contents().as_lines as lines: yield model_iter_from_file_line_iter(lines)
def _apply(self, put: unittest.TestCase, value: StringSource, message_builder: MessageBuilder, ): source_checker = contents_assertions.StringSourceContentsThatThatChecksLines(put, value.contents()) self._check_lines_by_iterating_over_them(source_checker)
def _first_line(file_to_check: StringSource) -> str: with file_to_check.contents().as_lines as lines: for line in lines: return line return ''
def _model_freezer(model: StringSource) -> StringSource: model.freeze() return model
def _invoke_every_contents_method(string_source: StringSource): contents = string_source.contents() for method_case in properties_access.ALL_CASES__WO_LINES_ITER_CHECK: method_case.value(contents)
def get_structure(model: StringSource) -> NodeRenderer: return model.structure()
def _invoke_freeze(string_source: StringSource, num_times: int): for _ in range(num_times): string_source.freeze()
def matches_w_trace(self, model: StringSource) -> MatchingResult: actual = model.contents().as_str trace_builder = self._trace_builder(actual) return trace_builder.build_result(self._expected == actual)