def check( put: unittest.TestCase, mk_transformer: Callable[[StringSource], StringSource], source_may_depend_on_external_resources: bool, num_initial_freeze_invocations: int, tmp_file_space: DirFileSpace, source_model_method_invocations: Assertion[Sequence[StringSourceMethod]], message_builder: asrt.MessageBuilder = asrt.new_message_builder(), source_model_contents: str = '1\n2\n3\n', ): source_model_invocations_recorder = _new_recording_media() source_model = string_sources.of_string( source_model_contents, tmp_file_space, source_may_depend_on_external_resources) source_model_w_invocations_recording = string_sources.StringSourceThatRecordsMethodInvocations( source_model, source_model_invocations_recorder, ) checked_string_source = mk_transformer( source_model_w_invocations_recording) # ACT # _invoke_freeze(checked_string_source, num_initial_freeze_invocations) _invoke_every_contents_method(checked_string_source) # ASSERT # source_model_method_invocations.apply( put, source_model_invocations_recorder.recordings, message_builder.for_sub_component( 'invoked methods of the source model'))
def construct(self, environment: FullResolvingEnvironment) -> StringSource: return StringSourceThatThatChecksLines( self.put, string_sources.of_string( self.contents, environment.application_environment.tmp_files_space, self.may_depend_on_external_resources, ))
def test_dependence_on_external_resources_should_be_constant_false(self): # ARRANGE # tmp_file_space = DirFileSpaceThatMustNoBeUsed() for source_may_depend_on_external_resources in [False, True]: with self.subTest(source_may_depend_on_external_resources= source_may_depend_on_external_resources): source_model = string_sources.of_string( 'the contents', tmp_file_space, source_may_depend_on_external_resources) # ACT # string_source = sut.empty(source_model, _transformer_description) # ASSERT # self.assertEqual( string_source.contents().may_depend_on_external_resources, False)
def test_reference(self): # ARRANGE # defined_name = symbol_syntax.A_VALID_SYMBOL_NAME create_file = fs.File('created-file.txt', 'contents of created file') referenced_symbol = FilesSourceSymbolContext.of_primitive( 'referenced_name', file_list.Primitive([ file_list.FileSpecification( create_file.name, RegularFileMaker( ModificationType.CREATE, string_sources.of_string(create_file.contents), None, ), ), ]), ) instruction_syntax = _syntax_of( referenced_symbol.abstract_syntax, defined_name, ) arrangement = Arrangement.phase_agnostic() # EXPECTATION # expectation = _expect_definition_of( defined_name, referenced_symbol.symbol_table, (), referenced_symbol.references_assertion, asrt_fs.dir_contains_exactly_2([create_file]) ) # ACT & ASSERT # INSTRUCTION_CHECKER.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, arrangement, expectation, )
def test_dependence_on_external_resources_should_be_that_of_source_model( self): # ARRANGE # tmp_file_space = DirFileSpaceThatMustNoBeUsed() for transformer_case in multiple_ranges_w_negative_values_cases(): for source_may_depend_on_external_resources in [False, True]: with self.subTest(transformer=transformer_case.name, source_may_depend_on_external_resources= source_may_depend_on_external_resources): source_model = string_sources.of_string( 'the contents', tmp_file_space, source_may_depend_on_external_resources) # ACT # string_source = transformer_case.transformer(source_model) # ASSERT # self.assertEqual( string_source.contents( ).may_depend_on_external_resources, source_may_depend_on_external_resources)
def _transform_string_to_string(tcds: TestCaseDs, string_input: str) -> str: transformer = sut.TcdsPathsReplacementStringTransformer( 'arbitrary custom', tcds) model = string_sources.of_string(string_input) output = transformer.transform(model) return output.contents().as_str