def __init__(self, pre_contents_population_action: TcdsAction = TcdsAction(), hds_contents: hds_populators.HdsPopulator = hds_populators.empty(), sds_contents: sds_populator.SdsPopulator = sds_populator.empty(), non_hds_contents: non_hds_populator.NonHdsPopulator = non_hds_populator.empty(), tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(), os_services: OsServices = os_services_access.new_for_current_os(), process_execution_settings: ProcessExecutionSettings = proc_exe_env_for_test(), default_environ_getter: DefaultEnvironGetter = get_empty_environ, post_sds_population_action: TcdsAction = TcdsAction(), symbols: SymbolTable = None, fs_location_info: FileSystemLocationInfo = ARBITRARY_FS_LOCATION_INFO, ): super().__init__(hds_contents=hds_contents, process_execution_settings=process_execution_settings, default_environ_getter=default_environ_getter) self.pre_contents_population_action = pre_contents_population_action self.sds_contents = sds_contents self.non_hds_contents = non_hds_contents self.tcds_contents = tcds_contents self.post_sds_population_action = post_sds_population_action self.os_services = os_services self.process_execution_settings = process_execution_settings self.symbols = symbol_table_from_none_or_value(symbols) self.fs_location_info = fs_location_info
def __init__(self, pre_contents_population_action: TcdsAction = TcdsAction(), hds_contents: hds_populators.HdsPopulator = hds_populators.empty(), sds_contents: sds_populator.SdsPopulator = sds_populator.empty(), non_hds_contents: non_hds_populator.NonHdsPopulator = non_hds_populator.empty(), tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(), post_sds_population_action: TcdsAction = TcdsAction(), act_result_producer: ActResultProducer = ActResultProducerFromActResult(), os_services: OsServices = os_services_access.new_for_current_os(), process_execution_settings: ProcessExecutionSettings = ProcessExecutionSettings.null(), default_environ_getter: DefaultEnvironGetter = get_empty_environ, symbols: SymbolTable = None, fs_location_info: FileSystemLocationInfo = ARBITRARY_FS_LOCATION_INFO, ): super().__init__(pre_contents_population_action=pre_contents_population_action, sds_contents=sds_contents, hds_contents=hds_contents, non_hds_contents=non_hds_contents, tcds_contents=tcds_contents, post_sds_population_action=post_sds_population_action, os_services=os_services, process_execution_settings=process_execution_settings, default_environ_getter=default_environ_getter, symbols=symbols, fs_location_info=fs_location_info) self.act_result_producer = act_result_producer
def tcds_with_act_as_curr_dir_2( hds_contents: hds_populators.HdsPopulator = hds_populators.empty(), sds_contents: sds_populator.SdsPopulator = sds_populator.empty(), non_hds_contents: non_hds_populator.NonHdsPopulator = non_hds_populator. empty(), tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(), act_result: Optional[ActResultProducer] = None, pre_contents_population_action: PlainTcdsAction = PlainTcdsAction(), post_contents_population_action: PlainTcdsAction = PlainTcdsAction(), ) -> ContextManager[TestCaseDs]: prefix = strftime(program_info.PROGRAM_NAME + '-test-%Y-%m-%d-%H-%M-%S', localtime()) with home_directory_structure(prefix=prefix + '-home') as hds: with sandbox_directory_structure(prefix=prefix + "-sds-") as sds: tcds = TestCaseDs(hds, sds) with preserved_cwd(): os.chdir(str(sds.act_dir)) pre_contents_population_action.apply(tcds) hds_contents.populate_hds(hds) sds_contents.populate_sds(sds) non_hds_contents.populate_non_hds(sds) tcds_contents.populate_tcds(tcds) if act_result: actual_act_result = act_result.apply(ActEnvironment(tcds)) write_act_result(tcds.sds, actual_act_result) post_contents_population_action.apply(tcds) yield tcds
def arrangement( pre_contents_population_action: TcdsAction = TcdsAction(), hds_contents: hds_populators.HdsPopulator = hds_populators.empty(), sds_contents_before_main: sds_populator.SdsPopulator = sds_populator.empty( ), non_hds_contents_before_main: non_hds_populator. NonHdsPopulator = non_hds_populator.empty(), tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(), act_result_producer: ActResultProducer = ActResultProducerFromActResult(), os_services: OsServices = new_for_current_os(), process_execution_settings: ProcessExecutionSettings = ProcessExecutionSettings.null(), default_environ_getter: DefaultEnvironGetter = get_empty_environ, symbols: SymbolTable = None, ) -> ArrangementPostAct: return ArrangementPostAct( pre_contents_population_action=pre_contents_population_action, hds_contents=hds_contents, sds_contents=sds_contents_before_main, non_hds_contents=non_hds_contents_before_main, tcds_contents=tcds_contents, act_result_producer=act_result_producer, os_services=os_services, process_execution_settings=process_execution_settings, default_environ_getter=default_environ_getter, symbols=symbols)
def test_copy_file__non_existing_destination(self): dst_file_name = 'dst-file_name-file.txt' sub_dir_name = 'src-sub-dir' source_file_contents = 'contents' src_file = File('src-file_name-file.txt', source_file_contents) home_dir_contents_cases = [ (src_file.file_name, DirContents([src_file])), (str(PurePosixPath(sub_dir_name) / src_file.file_name), DirContents([Dir(sub_dir_name, [src_file]) ])), ] expected_destination_dir_contents = DirContents([File(dst_file_name, src_file.contents)]) for src_rel_option in source_relativity_options__hds(): for dst_rel_option in destination_relativity_options(): for src_argument, home_dir_contents in home_dir_contents_cases: self._sub_test__copy_file( src_rel_option=src_rel_option, dst_rel_option=dst_rel_option, src_file_name=src_argument, dst_file_name=dst_file_name, hds_contents=src_rel_option.populator_for_relativity_option_root__hds(home_dir_contents), sds_populator_before_main=sds_populator.empty(), expected_destination_dir_contents=expected_destination_dir_contents, )
def sandbox_directory_structure( contents: sds_populator.SdsPopulator = sds_populator.empty(), prefix: str = program_info.PROGRAM_NAME + '-test-sds-', ) -> ContextManager[sds_module.SandboxDs]: with _tmp_dir.temp_dir(prefix) as sds_root_dir: sds = sds_module.construct_at(str(sds_root_dir)) contents.populate_sds(sds) yield sds
def __init__(self, sds_contents_before: sds_populator. SdsPopulator = sds_populator.empty(), pre_contents_population_action: SdsAction = SdsAction(), pre_action_action: SdsAction = SdsAction(), symbols: SymbolTable = None): self.pre_contents_population_action = pre_contents_population_action self.sds_contents_before = sds_contents_before self.pre_action_action = pre_action_action self.symbols = symbol_table_from_none_or_value(symbols)
def arrangement( self, pre_contents_population_action: TcdsAction = TcdsAction(), hds_contents: hds_populators.HdsPopulator = hds_populators.empty(), sds_contents_before_main: sds_populator. SdsPopulator = sds_populator.empty(), tcds_contents: tcds_populators.TcdsPopulator = tcds_populators. empty(), environ: Optional[Dict[str, str]] = None, default_environ_getter: DefaultEnvironGetter = get_empty_environ, os_services: OsServices = new_for_current_os(), symbols: SymbolTable = None): raise NotImplementedError()
def sds_with_act_as_curr_dir( contents: sds_populator.SdsPopulator = sds_populator.empty(), pre_contents_population_action: SdsAction = SdsAction(), symbols: SymbolTable = None, ) -> PathResolvingEnvironmentPostSds: with tempfile.TemporaryDirectory(prefix=program_info.PROGRAM_NAME + '-test-sds-') as sds_root_dir: sds = sds_module.construct_at(resolved_path_name(sds_root_dir)) environment = PathResolvingEnvironmentPostSds( sds, symbol_table_from_none_or_value(symbols)) with preserved_cwd(): os.chdir(str(sds.act_dir)) pre_contents_population_action.apply(environment) contents.populate_sds(sds) yield environment
def arrangement(self, pre_contents_population_action: TcdsAction = TcdsAction(), hds_contents: hds_populators.HdsPopulator = hds_populators.empty(), sds_contents_before_main: sds_populator.SdsPopulator = sds_populator.empty(), tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(), environ: Optional[Dict[str, str]] = None, default_environ_getter: DefaultEnvironGetter = get_empty_environ, os_services: OsServices = new_for_current_os(), symbols: SymbolTable = None): return ic.Arrangement(pre_contents_population_action=pre_contents_population_action, hds_contents=hds_contents, sds_contents_before_main=sds_contents_before_main, tcds_contents=tcds_contents, process_execution_settings=ProcessExecutionSettings.from_non_immutable(environ=environ), default_environ_getter=default_environ_getter, os_services=os_services, symbols=symbols)
def __init__( self, tcds_contents: tcds_populators.TcdsPopulator = tcds_populators. empty(), hds_contents: hds_populators.HdsPopulator = hds_populators.empty(), non_hds_contents: non_hds_populator. NonHdsPopulator = non_hds_populator.empty(), sds_contents: sds_populator.SdsPopulator = sds_populator.empty(), act_result: Optional[ActResultProducer] = None, pre_population_action: PlainTcdsAction = PlainTcdsAction(), post_population_action: PlainTcdsAction = PlainTcdsAction(), ): self.hds_contents = hds_contents self.sds_contents = sds_contents self.non_hds_contents = non_hds_populator.multiple( [non_hds_contents, sds_contents]) self.tcds_contents = tcds_contents self.act_result = act_result self.pre_population_action = pre_population_action self.post_population_action = post_population_action
def tcds_with_act_as_curr_dir( hds_contents: hds_populators.HdsPopulator = hds_populators.empty(), sds_contents: sds_populator.SdsPopulator = sds_populator.empty(), non_hds_contents: non_hds_populator.NonHdsPopulator = non_hds_populator.empty(), tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(), pre_contents_population_action: TcdsAction = TcdsAction(), symbols: SymbolTable = None) -> ContextManager[PathResolvingEnvironmentPreOrPostSds]: symbols = symbol_table_from_none_or_value(symbols) prefix = strftime(program_info.PROGRAM_NAME + '-test-%Y-%m-%d-%H-%M-%S', localtime()) with home_directory_structure(prefix=prefix + '-home') as hds: with sandbox_directory_structure(prefix=prefix + "-sds-") as sds: tcds = TestCaseDs(hds, sds) ret_val = PathResolvingEnvironmentPreOrPostSds(tcds, symbols) with preserved_cwd(): os.chdir(str(sds.act_dir)) pre_contents_population_action.apply(ret_val) hds_contents.populate_hds(hds) sds_contents.populate_sds(sds) non_hds_contents.populate_non_hds(sds) tcds_contents.populate_tcds(tcds) yield ret_val