def destination_relativity_options() -> List[RelativityOptionConfigurationForRelNonHds]: return [ rel_opt_conf.default_conf_rel_non_hds(RelNonHdsOptionType.REL_CWD), rel_opt_conf.conf_rel_non_hds(RelNonHdsOptionType.REL_CWD), rel_opt_conf.conf_rel_non_hds(RelNonHdsOptionType.REL_ACT), rel_opt_conf.conf_rel_non_hds(RelNonHdsOptionType.REL_TMP), ]
def runTest(self): # ARRANGE # rel_conf = rel_opts.conf_rel_non_hds(RelNonHdsOptionType.REL_TMP) for case in successful_cases(): dst_path = rel_conf.path_abs_stx_of_name(case.dst_file_name) instruction_syntax = NewDirArguments( dst_path, case.contents_syntax, ) with self.subTest(case.name): # ACT & ASSERT # _CHECKER.check__abs_stx( self, instruction_syntax, embryo_arr_exp.Arrangement.phase_agnostic( tcds=TcdsArrangement( non_hds_contents=rel_conf.populator_for_relativity_option_root__non_hds__s( case.pre_existing_files ) ), ), embryo_arr_exp.Expectation.phase_agnostic( main_side_effects_on_sds=rel_conf.assert_root_dir_contains_exactly__p( case.expected_files) ), )
def runTest(self): non_zero_exit_code = 1 program_string_source_syntax = string_source_abs_stx.StringSourceOfProgramAbsStx( ProcOutputFile.STDOUT, program_abs_stx.ProgramOfPythonInterpreterAbsStx. of_execute_python_src_string( py_programs.single_line_pgm_that_exists_with( non_zero_exit_code)), ignore_exit_code=False, ) instruction_syntax = instr_abs_stx.create_w_explicit_contents( conf_rel_non_hds( RelNonHdsOptionType.REL_TMP).path_abs_stx_of_name('dst.txt'), program_string_source_syntax, ) for source_case in equivalent_source_variants__with_source_check__consume_last_line__abs_stx( instruction_syntax): with self.subTest(source_case.name): self.conf.run_test( self, source_case.value.source, self.conf.arrangement(), self.conf.expect_hard_error_of_main__any(), )
def every_src_file_rel_conf( is_before_act: bool ) -> Sequence[RelativityOptionConfiguration]: return [ conf_rel_non_hds(relativity) for relativity in accepted_non_hds_source_relativities(is_before_act) ]
def runTest(self): # ARRANGE # rel_conf = rel_opts.conf_rel_non_hds(RelNonHdsOptionType.REL_TMP) for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) for case in successful_cases(): dst_path = rel_conf.path_abs_stx_of_name(case.dst_file_name) instruction_syntax = InstructionAbsStx( dst_path, case.contents_syntax, ) with self.subTest(case.name, phase_is_after_act=phase_is_after_act): # ACT & ASSERT # checker.check__abs_stx( self, instruction_syntax, embryo_arr_exp.Arrangement.phase_agnostic( symbols=SymbolContext.symbol_table_of_contexts(case.symbols), tcds=TcdsArrangement( non_hds_contents=rel_conf.populator_for_relativity_option_root__non_hds__s( case.pre_existing_files ) ), ), embryo_arr_exp.Expectation.phase_agnostic( symbol_usages=SymbolContext.usages_assertion_of_contexts(case.symbols), main_result=IS_SUCCESS, main_side_effects_on_sds=rel_conf.assert_root_dir_contains_exactly__p( case.expected_files) ), )
def test_with_reference_to_existing_file(self): referenced_file = 'referenced-file.txt' relativity_cases = [ relativity_options.conf_rel_hds(RelHdsOptionType.REL_HDS_CASE), relativity_options.conf_rel_non_hds(RelNonHdsOptionType.REL_ACT), ] for file_existence_case in FILE_EXISTENCE_CASES: for relativity_conf in relativity_cases: source_syntax = RawSystemCommandLineAbsStx.of_str( 'program_name', [ ArgumentOfExistingPathAbsStx( relativity_conf.path_abs_stx_of_name( referenced_file)) ]) with self.subTest( relativity=relativity_conf.option_string, file_do_existence_case=file_existence_case.name): # ACT & ASSERT # CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc, source_syntax, arrangement_w_tcds( tcds_contents=relativity_conf. populator_for_relativity_option_root( DirContents( file_existence_case.files_for_name( referenced_file)))), MultiSourceExpectation(execution=ExecutionExpectation( validation=file_existence_case.expectation_for( relativity_conf.directory_structure_partition)) ), )
def _check_cases_for_dst_file_setup__w_relativity_options( self, dst_file_name: str, dst_root_contents_before_execution: DirContents, ): cases_data = self._file_contents_cases() dst_file_relativity_cases = [ conf_rel_non_hds(RelNonHdsOptionType.REL_CWD), conf_rel_non_hds(RelNonHdsOptionType.REL_ACT), ] for rel_opt_conf in dst_file_relativity_cases: non_hds_contents = rel_opt_conf.populator_for_relativity_option_root__non_hds( dst_root_contents_before_execution) dst_file = rel_opt_conf.path_abs_stx_of_name(dst_file_name) for file_contents_case in cases_data.file_contents_cases: instruction_syntax = instr_abs_stx.InstructionAbsStx( dst_file, file_contents_case.value, ) for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) with self.subTest( file_contents_variant=file_contents_case.name, dst_file_variant=rel_opt_conf.name, phase_is_after_act=phase_is_after_act): # ACT & ASSERT # checker.check__abs_stx( self, instruction_syntax, Arrangement.phase_agnostic( tcds=TcdsArrangement( pre_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, tcds_contents=cases_data. pre_existing_files, non_hds_contents=non_hds_contents, ), symbols=cases_data.symbols, ), Expectation.phase_agnostic_2( main_result=IS_FAILURE, symbol_usages=asrt.anything_goes(), ))
def runTest(self): # ARRANGE # src_file = fs.File('source-file.txt', 'contents of source file') src_rel_opt_conf = conf_rel_hds(RelHdsOptionType.REL_HDS_CASE) expected_file = fs.File('a-file-name.txt', src_file.contents.upper()) dst_rel_opt_conf = conf_rel_non_hds(RelNonHdsOptionType.REL_ACT) to_upper_transformer = StringTransformerSymbolContext.of_primitive( 'TRANSFORMER_SYMBOL', to_uppercase(), ) symbols = to_upper_transformer.symbol_table transformed_file_syntax = string_source_abs_stx.TransformedStringSourceAbsStx( string_source_abs_stx.StringSourceOfFileAbsStx( src_rel_opt_conf.path_abs_stx_of_name(src_file.name)), to_upper_transformer.abstract_syntax, ) instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_rel_opt_conf.path_abs_stx_of_name(expected_file.name), transformed_file_syntax, ) expected_non_hds_contents = dst_rel_opt_conf.assert_root_dir_contains_exactly( fs.DirContents([expected_file])) instruction_checker = self.conf.instruction_checker parser = self.conf.parser() for source_case in equivalent_source_variants__with_source_check__consume_last_line__abs_stx( instruction_syntax): with self.subTest(source_case.name): source = source_case.value.source # ACT # instruction = parser.parse(ARBITRARY_FS_LOCATION_INFO, source) # ASSERT # source_case.value.expectation.apply_with_message( self, source, 'source-after-parse') # ACT & ASSERT # instruction_checker.check( self, instruction, self.conf.arrangement( pre_contents_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR, tcds_contents=src_rel_opt_conf. populator_for_relativity_option_root( DirContents([src_file])), symbols=symbols, ), self.conf.expect_success( symbol_usages=asrt.matches_sequence([ to_upper_transformer.reference_assertion, ]), main_side_effects_on_sds=expected_non_hds_contents, ))
def runTest(self): text_printed_by_program = 'single line of output' expected_file_contents = text_printed_by_program.upper() expected_file = fs.File('dst-file.txt', expected_file_contents) to_upper_transformer = StringTransformerSymbolContext.of_primitive( 'TO_UPPER_CASE', to_uppercase(), ) symbols = to_upper_transformer.symbol_table dst_rel_opt_conf = conf_rel_non_hds(RelNonHdsOptionType.REL_TMP) program_syntax = string_source_abs_stx.StringSourceOfProgramAbsStx( ProcOutputFile.STDOUT, program_abs_stx.FullProgramAbsStx( program_abs_stx.ProgramOfPythonInterpreterAbsStx. of_execute_python_src_string( py_programs.single_line_pgm_that_prints_to( ProcOutputFile.STDOUT, text_printed_by_program)), transformation=to_upper_transformer.abstract_syntax, )) instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_rel_opt_conf.path_abs_stx_of_name(expected_file.name), program_syntax, ) instruction_checker = self.conf.instruction_checker parser = self.conf.parser() for source_case in equivalent_source_variants__with_source_check__consume_last_line__abs_stx( instruction_syntax): with self.subTest(source_case.name): source = source_case.value.source # ACT # instruction = parser.parse(ARBITRARY_FS_LOCATION_INFO, source) # ASSERT # source_case.value.expectation.apply_with_message( self, source, 'source-after-parse') # ACT & ASSERT # instruction_checker.check( self, instruction, self.conf.arrangement( pre_contents_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR, symbols=symbols), self.conf.expect_success( symbol_usages=asrt.matches_sequence([ to_upper_transformer.reference_assertion, ]), main_side_effects_on_sds=non_hds_dir_contains_exactly( dst_rel_opt_conf.root_dir__non_hds, fs.DirContents([expected_file])), ))
def test__with_transformer(self): # ARRANGE # src_file = fs.File('source-file.txt', 'contents of source file') expected_file = fs.File('a-file-name.txt', src_file.contents.upper()) to_upper_transformer = StringTransformerSymbolContext.of_primitive( 'TRANSFORMER_SYMBOL', string_transformers.to_uppercase(), ) src_rel_opt_conf = ALLOWED_SRC_FILE_RELATIVITIES__BEFORE_ACT[0] dst_rel_opt_conf = conf_rel_non_hds(RelNonHdsOptionType.REL_ACT) expected_non_hds_contents = self._expected_non_hds_contents( dst_rel_opt_conf, expected_file, src_rel_opt_conf, src_file, ) transformed_file_contents_abs_stx = string_source_abs_stx.TransformedStringSourceAbsStx( string_source_abs_stx.StringSourceOfFileAbsStx( src_rel_opt_conf.path_abs_stx_of_name(src_file.name)), to_upper_transformer.abstract_syntax, ) instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_rel_opt_conf.path_abs_stx_of_name(expected_file.file_name), transformed_file_contents_abs_stx, ) symbols = to_upper_transformer.symbol_table for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) with self.subTest(phase_is_after_act=phase_is_after_act): # ACT & ASSERT # checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic( tcds=TcdsArrangement( pre_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, tcds_contents=src_rel_opt_conf. populator_for_relativity_option_root( DirContents([src_file])), ), symbols=symbols, ), MultiSourceExpectation.phase_agnostic( main_result=IS_SUCCESS, main_side_effects_on_sds=expected_non_hds_contents, symbol_usages=to_upper_transformer.usages_assertion, ))
def runTest(self): non_zero_exit_code = 1 text_printed_by_program = 'the output from the program' py_file = File( 'exit-with-hard-coded-exit-code.py', py_programs.py_pgm_with_stdout_stderr_exit_code( stdout_output=text_printed_by_program, stderr_output='', exit_code=non_zero_exit_code, ), ) expected_file = fs.File( 'dst-file.txt', text_printed_by_program.upper(), ) to_upper_transformer = StringTransformerSymbolContext.of_primitive( 'TO_UPPER_CASE', to_uppercase(), ) symbols = to_upper_transformer.symbol_table py_src_file_rel_opt_conf = rel_opt.conf_rel_any( RelOptionType.REL_HDS_CASE) dst_file_rel_opt_conf = conf_rel_non_hds(RelNonHdsOptionType.REL_TMP) program_string_source_syntax = string_source_abs_stx.StringSourceOfProgramAbsStx( ProcOutputFile.STDOUT, program_abs_stx.FullProgramAbsStx( program_abs_stx.ProgramOfPythonInterpreterAbsStx. of_execute_python_src_file( py_src_file_rel_opt_conf.path_abs_stx_of_name( py_file.name)), transformation=to_upper_transformer.abstract_syntax, ), ignore_exit_code=True, ) instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_file_rel_opt_conf.path_abs_stx_of_name(expected_file.name), program_string_source_syntax, ) instruction_checker = self.conf.instruction_checker parser = self.conf.parser() for source_case in equivalent_source_variants__with_source_check__consume_last_line__abs_stx( instruction_syntax): with self.subTest(source_case.name): source = source_case.value.source # ACT # instruction = parser.parse(ARBITRARY_FS_LOCATION_INFO, source) # ASSERT # source_case.value.expectation.apply_with_message( self, source, 'source-after-parse') # ACT & ASSERT # instruction_checker.check( self, instruction, self.conf.arrangement( pre_contents_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR, symbols=symbols, tcds_contents=py_src_file_rel_opt_conf. populator_for_relativity_option_root( DirContents([py_file]))), self.conf.expect_success( symbol_usages=asrt.matches_sequence([ to_upper_transformer.reference_assertion, ]), main_side_effects_on_sds=non_hds_dir_contains_exactly( dst_file_rel_opt_conf.root_dir__non_hds, fs.DirContents([expected_file])), ))
def test_existing_path(self): # ARRANGE # plain_file_name = 'path-name' symbol_name = 'symbol_name' relativity_cases = [ PathCase( 'default relativity SHOULD be CASE_HOME', rel_opts.default_conf_rel_hds(RelHdsOptionType.REL_HDS_CASE), list_element_for_path(RelOptionType.REL_HDS_CASE, plain_file_name), ), PathCase( 'relativity in SDS should be validated post SDS', rel_opts.conf_rel_non_hds(RelNonHdsOptionType.REL_TMP), list_element_for_path(RelOptionType.REL_TMP, plain_file_name), ), PathCase( 'rel symbol', rel_opts.symbol_conf_rel_hds( RelHdsOptionType.REL_HDS_ACT, symbol_name, sut.REL_OPTIONS_CONF.accepted_relativity_variants), list_sdvs.string_element( string_sdvs.from_path_sdv( path_sdvs.rel_symbol_with_const_file_name( SymbolReference( symbol_name, reference_restrictions_for_path_symbol( sut.REL_OPTIONS_CONF. accepted_relativity_variants)), plain_file_name))), ), ] for case in relativity_cases: with self.subTest(case.name): rel_opt_conf = case.relativity_variant assert isinstance( rel_opt_conf, RelativityOptionConfiguration) # Type info for IDE _case = Case.of( 'default relativity SHOULD be CASE_HOME', ArgumentOfExistingPathAbsStx( rel_opt_conf.path_abs_stx_of_name(plain_file_name), None, ), Arrangement(rel_opt_conf.symbols.in_arrangement()), Expectation( elements=[case.expected_list_element], references=asrt.matches_sequence( rel_opt_conf.symbols. reference_expectation_assertions()), validators=is_single_validator_with([ NameAndValue( 'fail when file is missing', validation_check.assert_with_files( arrangement=validation_check.Arrangement( dir_contents=tcds_populators.empty()), expectation=validation_check.fails_on( rel_opt_conf. directory_structure_partition), )), NameAndValue( 'fail when file is a broken sym link', validation_check.assert_with_files( arrangement=validation_check.Arrangement( dir_contents=rel_opt_conf. populator_for_relativity_option_root( DirContents([ sym_link( plain_file_name, 'non-existing-target-file' ), ]))), expectation=validation_check.fails_on( rel_opt_conf. directory_structure_partition), )), NameAndValue( 'succeed when file exists (as regular file)', validation_check.assert_with_files( arrangement=validation_check.Arrangement( dir_contents=rel_opt_conf. populator_for_relativity_option_root( DirContents([ File.empty(plain_file_name) ]))), expectation=validation_check.is_success()) ), NameAndValue( 'succeed when file exists (as symlink to regular file)', validation_check.assert_with_files( arrangement=validation_check.Arrangement( dir_contents=rel_opt_conf. populator_for_relativity_option_root( DirContents([ sym_link( plain_file_name, 'target-file'), File.empty('target-file'), ]))), expectation=validation_check.is_success()) ), NameAndValue( 'succeed when file exists (as a dir)', validation_check.assert_with_files( arrangement=validation_check.Arrangement( dir_contents=rel_opt_conf. populator_for_relativity_option_root( DirContents([ Dir.empty(plain_file_name), ]))), expectation=validation_check.is_success()) ), ]), ))
from exactly_lib.tcfs.path_relativity import RelOptionType, PathRelativityVariants, DEPENDENCY_DICT, \ DirectoryStructurePartition, RelHdsOptionType, RelNonHdsOptionType from exactly_lib_test.impls.types.test_resources import relativity_options as rel_opt_conf def path_relativity_variants__src( phase_is_after_act: bool) -> PathRelativityVariants: rel_opts = set(RelOptionType) if not phase_is_after_act: rel_opts.remove(RelOptionType.REL_RESULT) return PathRelativityVariants(rel_opts, True) PATH_RELATIVITY_VARIANTS__DST = PathRelativityVariants( DEPENDENCY_DICT[DirectoryStructurePartition.NON_HDS] - {RelOptionType.REL_RESULT}, False, ) ARBITRARY_LEGAL_RELATIVITY__SRC = RelOptionType.REL_HDS_CASE ARBITRARY_LEGAL_RELATIVITY__SRC__HDS = RelHdsOptionType.REL_HDS_CASE ARBITRARY_LEGAL_RELATIVITY__DST = RelOptionType.REL_ACT ARBITRARY_LEGAL_RELATIVITY__DST__NON_HDS = RelNonHdsOptionType.REL_ACT ARBITRARY_SRC_REL_OPT = rel_opt_conf.conf_rel_hds(RelHdsOptionType.REL_HDS_ACT) ARBITRARY_DST_REL_OPT = rel_opt_conf.conf_rel_non_hds( RelNonHdsOptionType.REL_ACT) DEFAULT_SRC_REL_OPT = rel_opt_conf.default_conf_rel_hds( RelHdsOptionType.REL_HDS_CASE) DEFAULT_DST_REL_OPT = rel_opt_conf.default_conf_rel_non_hds( RelNonHdsOptionType.REL_CWD)
from typing import Sequence, Set from exactly_lib.tcfs.path_relativity import RelHdsOptionType, RelSdsOptionType, RelNonHdsOptionType, RelOptionType, \ PathRelativityVariants from exactly_lib_test.impls.types.test_resources.relativity_options import conf_rel_hds, conf_rel_sds, conf_rel_non_hds, \ default_conf_rel_non_hds, RelativityOptionConfiguration, default_conf_rel_hds ALLOWED_SRC_FILE_RELATIVITIES__BEFORE_ACT = [ conf_rel_hds(RelHdsOptionType.REL_HDS_CASE), conf_rel_hds(RelHdsOptionType.REL_HDS_ACT), conf_rel_sds(RelSdsOptionType.REL_ACT), conf_rel_sds(RelSdsOptionType.REL_TMP), conf_rel_non_hds(RelNonHdsOptionType.REL_CWD), default_conf_rel_hds(RelHdsOptionType.REL_HDS_CASE), ] DISALLOWED_DST_RELATIVITIES = [ RelOptionType.REL_RESULT, RelOptionType.REL_HDS_CASE, RelOptionType.REL_HDS_ACT, ] ARBITRARY_ALLOWED_SRC_FILE_RELATIVITY = conf_rel_non_hds( RelNonHdsOptionType.REL_TMP) ARBITRARY_ALLOWED_DST_FILE_RELATIVITY = conf_rel_non_hds( RelNonHdsOptionType.REL_TMP) ALLOWED_DST_FILE_RELATIVITIES = [ conf_rel_non_hds(RelNonHdsOptionType.REL_ACT), conf_rel_non_hds(RelNonHdsOptionType.REL_TMP), conf_rel_non_hds(RelNonHdsOptionType.REL_CWD),
from typing import Sequence from exactly_lib.impls.instructions.multi_phase import new_dir as sut from exactly_lib.tcfs.path_relativity import RelNonHdsOptionType from exactly_lib_test.impls.types.test_resources import relativity_options as rel_opt from exactly_lib_test.impls.types.test_resources.relativity_options import RelativityOptionConfigurationForRelNonHds from exactly_lib_test.tcfs.test_resources.ds_action import \ MK_DIR_AND_CHANGE_TO_IT_INSIDE_OF_SDS_BUT_OUTSIDE_OF_ANY_OF_THE_RELATIVITY_OPTION_DIRS from exactly_lib_test.test_resources.tcds_and_symbols.sds_env_utils import \ mk_dir_and_change_to_it_inside_of_sds_but_outside_of_any_of_the_relativity_option_dirs RELATIVITY_OPTIONS: Sequence[RelativityOptionConfigurationForRelNonHds] = [ rel_opt.default_conf_rel_non_hds(RelNonHdsOptionType.REL_CWD), rel_opt.conf_rel_non_hds(RelNonHdsOptionType.REL_ACT), rel_opt.conf_rel_non_hds(RelNonHdsOptionType.REL_TMP), rel_opt.symbol_conf_rel_non_hds( RelNonHdsOptionType.REL_TMP, 'DIR_PATH_SYMBOL', sut.RELATIVITY_VARIANTS.options.accepted_relativity_variants), ] RELATIVITY_OPTIONS__PHASE_INTEGRATION: Sequence[ RelativityOptionConfigurationForRelNonHds] = [ rel_opt.default_conf_rel_non_hds(RelNonHdsOptionType.REL_CWD), rel_opt.symbol_conf_rel_non_hds( RelNonHdsOptionType.REL_TMP, 'DIR_PATH_SYMBOL', sut.RELATIVITY_VARIANTS.options.accepted_relativity_variants), ] SETUP_CWD_ACTION = mk_dir_and_change_to_it_inside_of_sds_but_outside_of_any_of_the_relativity_option_dirs( ) SETUP_CWD_TO_NON_TCDS_DIR_ACTION = ( MK_DIR_AND_CHANGE_TO_IT_INSIDE_OF_SDS_BUT_OUTSIDE_OF_ANY_OF_THE_RELATIVITY_OPTION_DIRS
def source_relativity_options__non_hds() -> List[RelativityOptionConfigurationForRelNonHds]: return [ rel_opt_conf.conf_rel_non_hds(RelNonHdsOptionType.REL_ACT), rel_opt_conf.conf_rel_non_hds(RelNonHdsOptionType.REL_TMP), ]