def runTest(self): exe_file = fs.python_executable_file('program-name', py_programs.exit_with(0)) cases = [ NameAndValue( 'pre sds', ( RelOptionType.REL_HDS_CASE, self.conf.expect_failing_validation_pre_sds(), ), ), NameAndValue( 'post sds', ( RelOptionType.REL_ACT, self.conf.expect_hard_error_of_main__any(), ), ), ] for case in cases: with self.subTest(case.name): arguments = sys_cmd.command_line( exe_file.name, program_arguments.existing_file( path_arguments.RelOptPathArgument( 'non-existing', case.value[0])), ) with tmp_dir_in_path_with_files(fs.DirContents([exe_file ])) as env: self.conf.run_single_line_test_with_source_variants_and_source_check( self, arguments.as_str, self.conf.arrangement(environ=env), case.value[1], )
def test_arguments_of_interpreter(self): # ARRANGE # exe_file = fs.python_executable_file( 'program-name', py_programs.exit_with(0) ) for case in VALIDATION_CASES: with self.subTest(case.name): interpreter_arguments = arguments_sdvs.ref_to_path_that_must_exist( path_sdvs.of_rel_option_with_const_file_name(case.path_relativity, 'non-existing-file') ) actor = sut.actor( command_sdvs.for_executable_file( path_sdvs.constant(path_ddvs.absolute_file_name(sys.executable)), interpreter_arguments ) ) act_instruction = instr([exe_file.name]) # ACT & ASSERT # integration_check.check_execution( self, actor, [act_instruction], arrangement_w_tcds( hds_contents=relativity_configurations.ATC_FILE.populator_for_relativity_option_root__hds( fs.DirContents([exe_file]) ) ), Expectation(validation=case.expectation), )
def test_arguments_of_program_file(self): # ARRANGE # exe_file = fs.python_executable_file( 'program-name', py_programs.exit_with(0) ) actor = sut.actor(COMMAND_THAT_RUNS_PYTHON_PROGRAM_FILE) for case in VALIDATION_CASES: with self.subTest(case.name): act_contents = ab.sequence__r([ ab.singleton(exe_file.name), program_arguments.existing_file( path_arguments.RelOptPathArgument('non-existing', case.path_relativity) ) ]) act_instruction = instr([act_contents.as_str]) # ACT & ASSERT # integration_check.check_execution( self, actor, [act_instruction], arrangement_w_tcds( hds_contents=relativity_configurations.ATC_FILE.populator_for_relativity_option_root__hds( fs.DirContents([exe_file]) ) ), Expectation(validation=case.expectation), )
def test_symbol_value_with_space_SHOULD_be_given_as_single_argument_to_program( self): symbol = StringConstantSymbolContext('symbol_name', 'symbol value with space') expected_output = lines_content([symbol.str_value]) executable_file_name = 'the-executable_file_name' command_line = '{executable_file_name} {symbol}'.format( executable_file_name=executable_file_name, symbol=symbol.name__sym_ref_syntax, ) arrangement = arrangement_w_tcds( hds_contents=relativity_configurations.ATC_FILE. populator_for_relativity_option_root__hds( fs.DirContents([ fs.python_executable_file( executable_file_name, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES ) ])), symbol_table=symbol.symbol_table) expectation = Expectation( symbol_usages=asrt.matches_sequence( [symbol.reference_assertion__w_str_rendering]), execute=eh_assertions.is_exit_code(0), post_sds=PostSdsExpectation. constant(sub_process_result_from_execute=pr.stdout( asrt.Equals(expected_output, 'CLI arguments, one per line'))), ) check_execution(self, sut.actor(), [instr([command_line])], arrangement, expectation)
def test_possibility_to_have_sds_path_references_in_argument(self): file_name_of_referenced_file = 'file-name.txt' symbol = ConstantSuffixPathDdvSymbolContext( 'symbol_name', RelOptionType.REL_TMP, file_name_of_referenced_file) executable = 'the-executable' command_line = '{executable} {symbol}'.format( executable=executable, symbol=symbol.name__sym_ref_syntax, ) arrangement = arrangement_w_tcds( hds_contents=relativity_configurations.ATC_FILE. populator_for_relativity_option_root__hds( fs.DirContents([ fs.python_executable_file( executable, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES ) ])), symbol_table=symbol.symbol_table) expectation = Expectation( execute=eh_assertions.is_exit_code(0), symbol_usages=asrt.matches_singleton_sequence( symbol.reference_assertion__w_str_rendering), post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=pr.stdout( str_asrt.contains(file_name_of_referenced_file))), ) check_execution(self, sut.actor(), [instr([command_line])], arrangement, expectation)
def runTest(self): # ARRANGE # exit_code_from_program = 0 exe_file_in_path = fs.python_executable_file( 'the-program', lines_content(py_program.exit_with_code(exit_code_from_program)), ) program_symbol = StringConstantSymbolContext( 'PROGRAM_NAME_SYMBOL', exe_file_in_path.name, ) program_line = args.system_program_command_line( program_symbol.name__sym_ref_syntax).as_str with tmp_dir_in_path_with_files(DirContents([exe_file_in_path ])) as environ: for source_case in valid_source_variants(program_line): with self.subTest(source_case.name): # ACT & ASSERT # integration_check.check_execution( self, sut.actor(), [instr([program_line])], arrangement_w_tcds( symbol_table=program_symbol.symbol_table, act_exe_input=AtcExeInputArr(environ=environ), ), Expectation( symbol_usages=asrt.matches_singleton_sequence( program_symbol. reference_assertion__string__w_all_indirect_refs_are_strings ), execute=asrt_eh.is_exit_code( exit_code_from_program)), )
def _instructions_for_executing_py_source( self, py_src: List[str]) -> ContextManager[TestCaseSourceSetup]: exe_file = fs.python_executable_file('the-program', lines_content(py_src)) yield TestCaseSourceSetup( act_phase_instructions=[instr([exe_file.name])], home_act_dir_contents=DirContents([exe_file]))
def file_structure(self, root_path: pathlib.Path) -> DirContents: return DirContents([ File('main.suite', lines_content(['[cases]', 'the.case'])), File('the.case', lines_content(['[act]', 'system-under-test', '[assert]', 'exit-code {eq} 0'.format(eq=comparators.EQ.name)])), python_executable_file('system-under-test', PYTHON_PROGRAM_THAT_EXISTS_WITH_STATUS_0) ])
def runTest(self): exe_file = fs.python_executable_file('program-name', py_programs.exit_with(0)) with tmp_dir_in_path_with_files(fs.DirContents([exe_file])) as env: instruction_argument = exe_file.name self.conf.run_single_line_test_with_source_variants_and_source_check( self, instruction_argument, self.conf.arrangement(environ=env), self.conf.expectation_for_zero_exitcode(), )
def file_structure(self, root_path: pathlib.Path) -> DirContents: return DirContents([ File('main.suite', lines_content(['[cases]', 'the.case'])), File( 'the.case', lines_content([ '[act]', 'system-under-test', '[assert]', 'exit-code {eq} 0'.format(eq=comparators.EQ.name) ])), python_executable_file('system-under-test', PYTHON_PROGRAM_THAT_EXISTS_WITH_STATUS_0) ])
def _instructions_for_executing_py_source( self, py_src: List[str]) -> ContextManager[TestCaseSourceSetup]: exe_file_in_path = fs.python_executable_file('the-program', lines_content(py_src)) with tmp_dir_in_path_with_files(DirContents([exe_file_in_path ])) as environ: program_line = args.system_program_command_line( exe_file_in_path.name).as_str yield TestCaseSourceSetup( act_phase_instructions=[instr([program_line])], environ=environ)
def test_multiple_symbol_references_in_executable(self): sub_dir_of_home = 'sub-dir' dir_symbol = NameAndValue('dir_symbol_name', file_refs.rel_home_act(file_refs.constant_path_part(sub_dir_of_home))) executable_file_name_symbol = NameAndValue('executable_file_name_symbol_name', 'the-executable-file') argument = 'argument_string' expected_output = lines_content([argument]) command_line = '{dir}/{file_name} {argument} '.format( dir=symbol_reference_syntax_for_name(dir_symbol.name), file_name=symbol_reference_syntax_for_name(executable_file_name_symbol.name), argument=argument, ) executable_file = fs.python_executable_file( executable_file_name_symbol.value, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES) arrangement = Arrangement( hds_contents=contents_in(RelHomeOptionType.REL_HOME_ACT, fs.DirContents([ fs.Dir(sub_dir_of_home, [executable_file]) ])), symbol_table=SymbolTable({ dir_symbol.name: su.file_ref_constant_container(dir_symbol.value), executable_file_name_symbol.name: su.string_constant_container(executable_file_name_symbol.value), }) ) expectation = Expectation( result_of_execute=eh_assertions.is_exit_code(0), sub_process_result_from_execute=pr.stdout(asrt.Equals(expected_output, 'CLI arguments, one per line')), symbol_usages=equals_symbol_references([ SymbolReference(dir_symbol.name, path_or_string_reference_restrictions(PATH_RELATIVITY_VARIANTS_FOR_FILE_TO_RUN)), SymbolReference(executable_file_name_symbol.name, PATH_COMPONENT_STRING_REFERENCES_RESTRICTION), ]), ) check_execution(self, sut.Parser(), [instr([command_line])], arrangement, expectation)
def file_structure(self, root_path: pathlib.Path) -> DirContents: exe_file = python_executable_file('executable-file', PYTHON_PROGRAM_THAT_EXISTS_WITH_STATUS_0) instruction_that_runs_program = '{run} {exe_file}'.format( run=instruction_names.RUN_INSTRUCTION_NAME, exe_file=exe_file.name, ) return DirContents([ File('main.suite', lines_content(['[cases]', 'the.case'])), File('the.case', lines_content(['[setup]', instruction_that_runs_program, ])), exe_file ])
def test_multiple_symbol_references_in_executable(self): sub_dir_of_home = 'sub-dir' dir_symbol = ConstantSuffixPathDdvSymbolContext( 'dir_symbol_name', RelOptionType.REL_HDS_ACT, sub_dir_of_home, PATH_RELATIVITY_VARIANTS_FOR_FILE_TO_RUN) executable_file_name_symbol = StringConstantSymbolContext( 'executable_file_name_symbol_name', 'the-executable-file') argument = 'argument_string' expected_output = lines_content([argument]) command_line = '{dir}/{file_name} {argument} '.format( dir=dir_symbol.name__sym_ref_syntax, file_name=executable_file_name_symbol.name__sym_ref_syntax, argument=argument, ) executable_file = fs.python_executable_file( executable_file_name_symbol.str_value, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES ) arrangement = arrangement_w_tcds( hds_contents=relativity_configurations.ATC_FILE. populator_for_relativity_option_root__hds( fs.DirContents([fs.Dir(sub_dir_of_home, [executable_file])])), symbol_table=SymbolContext.symbol_table_of_contexts([ dir_symbol, executable_file_name_symbol, ])) expectation = Expectation( symbol_usages=asrt.matches_sequence([ dir_symbol.reference_assertion__path_or_string, executable_file_name_symbol. reference_assertion__string__w_all_indirect_refs_are_strings, ]), execute=eh_assertions.is_exit_code(0), post_sds=PostSdsExpectation. constant(sub_process_result_from_execute=pr.stdout( asrt.Equals(expected_output, 'CLI arguments, one per line'))), ) check_execution(self, sut.actor(), [instr([command_line])], arrangement, expectation)
def test_symbol_reference_in_arguments(self): list_symbol = NameAndValue('list_symbol_name', ['first element', 'second element']) string_constant = 'string-constant' expected_output = lines_content(['string-constant'] + list_symbol.value) executable = 'the-executable' command_line = '{executable} {string_constant} {list_symbol}'.format( executable=executable, string_constant=string_constant, list_symbol=symbol_reference_syntax_for_name(list_symbol.name), ) arrangement = Arrangement( hds_contents=contents_in(RelHomeOptionType.REL_HOME_ACT, fs.DirContents([ fs.python_executable_file( executable, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES) ])), symbol_table=SymbolTable({ list_symbol.name: su.list_value_constant_container(lv.list_value_of_string_constants(list_symbol.value)), }) ) expectation = Expectation( result_of_execute=eh_assertions.is_exit_code(0), sub_process_result_from_execute=pr.stdout(asrt.Equals(expected_output, 'CLI arguments, one per line')), symbol_usages=equals_symbol_references( [SymbolReference(list_symbol.name, is_any_data_type())] ) ) check_execution(self, sut.Parser(), [instr([command_line])], arrangement, expectation)
def test_string_symbol_reference_in_executable_and_argument(self): symbol_for_executable = NameAndValue('executable_symbol_name', 'the-executable') argument_symbol = NameAndValue('argument_symbol_name', 'string-constant') expected_output = lines_content([argument_symbol.value]) command_line = '{executable} {argument} '.format( executable=symbol_reference_syntax_for_name(symbol_for_executable.name), argument=symbol_reference_syntax_for_name(argument_symbol.name), ) arrangement = Arrangement( hds_contents=contents_in(RelHomeOptionType.REL_HOME_ACT, fs.DirContents([ fs.python_executable_file( symbol_for_executable.value, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES) ])), symbol_table=SymbolTable({ symbol_for_executable.name: su.string_constant_container(symbol_for_executable.value), argument_symbol.name: su.string_constant_container(argument_symbol.value), }) ) expectation = Expectation( result_of_execute=eh_assertions.is_exit_code(0), sub_process_result_from_execute=pr.stdout(asrt.Equals(expected_output, 'CLI arguments, one per line')), symbol_usages=equals_symbol_references([ SymbolReference(symbol_for_executable.name, path_or_string_reference_restrictions(PATH_RELATIVITY_VARIANTS_FOR_FILE_TO_RUN)), SymbolReference(argument_symbol.name, is_any_data_type()), ]), ) check_execution(self, sut.Parser(), [instr([command_line])], arrangement, expectation)
def test_string_symbol_reference_in_executable_and_argument(self): symbol_for_executable = StringConstantSymbolContext( 'executable_symbol_name', 'the-executable') argument_symbol = StringConstantSymbolContext('argument_symbol_name', 'string-constant') expected_output = lines_content([argument_symbol.str_value]) command_line = '{executable} {argument} '.format( executable=symbol_for_executable.name__sym_ref_syntax, argument=argument_symbol.name__sym_ref_syntax, ) arrangement = arrangement_w_tcds( hds_contents=relativity_configurations.ATC_FILE. populator_for_relativity_option_root__hds( fs.DirContents([ fs.python_executable_file( symbol_for_executable.str_value, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES ) ])), symbol_table=SymbolContext.symbol_table_of_contexts([ symbol_for_executable, argument_symbol, ])) expectation = Expectation( execute=eh_assertions.is_exit_code(0), symbol_usages=asrt.matches_sequence([ symbol_for_executable.reference_assertion__path_or_string( PATH_RELATIVITY_VARIANTS_FOR_FILE_TO_RUN), argument_symbol.reference_assertion__w_str_rendering, ]), post_sds=PostSdsExpectation. constant(sub_process_result_from_execute=pr.stdout( asrt.Equals(expected_output, 'CLI arguments, one per line'))), ) check_execution(self, sut.actor(), [instr([command_line])], arrangement, expectation)
def runTest(self): executor_constructor = sut.Parser() act_phase_instructions = [ instr(['system-under-test first-argument "quoted argument"']) ] arrangement = Arrangement( hds_contents=contents_in(RelHomeOptionType.REL_HOME_ACT, fs.DirContents([ fs.python_executable_file( 'system-under-test', PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES) ]))) expected_output = lines_content(['first-argument', 'quoted argument']) expectation = Expectation(result_of_execute=eh_assertions.is_exit_code(0), sub_process_result_from_execute=pr.stdout(asrt.Equals(expected_output, 'CLI arguments, one per line'))) check_execution(self, executor_constructor, act_phase_instructions, arrangement, expectation)
def runTest(self): non_zero_exit_code = 1 exe_file = fs.python_executable_file( 'program-name', py_programs.copy_stdin_to_stderr_and_exit_with(non_zero_exit_code) ) with tmp_dir_in_path_with_files(fs.DirContents([exe_file])) as env: # ACT & ASSERT # CHECKER.check( self, command_line( exe_file.name, ).as_remaining_source, Arrangement.phase_agnostic( process_execution_settings=proc_exe_env_for_test(environ=env), tcds=TcdsArrangement(), ), Expectation.phase_agnostic_2( source=asrt_source.source_is_at_end, main_result=result_assertions.equals(non_zero_exit_code, ''), ), )
def runTest(self): executable_file_that_exits_with_code_0 = python_executable_file( 'executable-file', 'exit(0)') symbol_name = 'SYMBOL_NAME' relativity_option = rel_opt_conf.symbol_conf_rel_any( RelOptionType.REL_TMP, symbol_name, syntax_elements. EXE_FILE_REL_OPTION_ARG_CONF.options.accepted_relativity_variants) self.conf.run_test( self, single_line_source('{relativity_option} {executable_file}'.format( relativity_option=relativity_option.option_argument, executable_file=executable_file_that_exits_with_code_0. file_name)), self.conf.arrangement( tcds_contents=relativity_option. populator_for_relativity_option_root( DirContents([executable_file_that_exits_with_code_0])), symbols=relativity_option.symbols.in_arrangement()), self.conf.expect_success( symbol_usages=relativity_option.symbols.usages_expectation(), ), )
def runTest(self): actor = sut.actor() act_phase_instructions = [ instr(['system-under-test first-argument "quoted argument"']) ] arrangement = arrangement_w_tcds( hds_contents=relativity_configurations.ATC_FILE. populator_for_relativity_option_root__hds( fs.DirContents([ fs.python_executable_file( 'system-under-test', PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES ) ]))) expected_output = lines_content(['first-argument', 'quoted argument']) expectation = Expectation( execute=eh_assertions.is_exit_code(0), post_sds=PostSdsExpectation. constant(sub_process_result_from_execute=pr.stdout( asrt.Equals(expected_output, 'CLI arguments, one per line')))) check_execution(self, actor, act_phase_instructions, arrangement, expectation)
def runTest(self): executable_file_that_exits_with_code_0 = python_executable_file('executable-file', 'exit(0)') symbol_name = 'SYMBOL_NAME' relativity_option = rel_opt_conf.symbol_conf_rel_any( RelOptionType.REL_TMP, symbol_name, syntax_elements.REL_OPTION_ARG_CONF.options.accepted_relativity_variants) self.conf.run_test( self, single_line_source('{relativity_option} {executable_file}'.format( relativity_option=relativity_option.option_argument, executable_file=executable_file_that_exits_with_code_0.file_name)), self.conf.arrangement( home_or_sds_contents=relativity_option.populator_for_relativity_option_root( DirContents([executable_file_that_exits_with_code_0]) ), symbols=relativity_option.symbols.in_arrangement()), self.conf.expect_success( symbol_usages=relativity_option.symbols.usages_expectation(), ), )
def test_symbol_value_with_space_SHOULD_be_given_as_single_argument_to_program(self): symbol = NameAndValue('symbol_name', 'symbol value with space') expected_output = lines_content([symbol.value]) executable_file_name = 'the-executable_file_name' command_line = '{executable_file_name} {symbol}'.format( executable_file_name=executable_file_name, symbol=symbol_reference_syntax_for_name(symbol.name), ) arrangement = Arrangement( hds_contents=contents_in(RelHomeOptionType.REL_HOME_ACT, fs.DirContents([ fs.python_executable_file( executable_file_name, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES) ])), symbol_table=SymbolTable({ symbol.name: su.string_constant_container(symbol.value), }) ) expectation = Expectation( result_of_execute=eh_assertions.is_exit_code(0), sub_process_result_from_execute=pr.stdout(asrt.Equals(expected_output, 'CLI arguments, one per line')), symbol_usages=equals_symbol_references( [SymbolReference(symbol.name, is_any_data_type())] ) ) check_execution(self, sut.Parser(), [instr([command_line])], arrangement, expectation)
def test_symbol_reference_in_arguments(self): list_symbol = ListConstantSymbolContext( 'list_symbol_name', ['first element', 'second element']) string_constant = 'string-constant' expected_output = lines_content(['string-constant'] + list_symbol.constant_list) executable = 'the-executable' command_line = '{executable} {string_constant} {list_symbol}'.format( executable=executable, string_constant=string_constant, list_symbol=list_symbol.name__sym_ref_syntax, ) arrangement = arrangement_w_tcds( hds_contents=relativity_configurations.ATC_FILE. populator_for_relativity_option_root__hds( fs.DirContents([ fs.python_executable_file( executable, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES ) ])), symbol_table=list_symbol.symbol_table) expectation = Expectation( symbol_usages=asrt.matches_singleton_sequence( list_symbol.reference_assertion), execute=eh_assertions.is_exit_code(0), post_sds=PostSdsExpectation. constant(sub_process_result_from_execute=pr.stdout( asrt.Equals(expected_output, 'CLI arguments, one per line'))), ) check_execution(self, sut.actor(), [instr([command_line])], arrangement, expectation)
def test_possibility_to_have_sds_file_references_in_argument(self): file_name_of_referenced_file = 'file-name.txt' symbol = NameAndValue('symbol_name', file_refs.of_rel_option(RelOptionType.REL_TMP, file_refs.constant_path_part(file_name_of_referenced_file))) executable = 'the-executable' command_line = '{executable} {symbol}'.format( executable=executable, symbol=symbol_reference_syntax_for_name(symbol.name), ) arrangement = Arrangement( hds_contents=contents_in(RelHomeOptionType.REL_HOME_ACT, fs.DirContents([ fs.python_executable_file( executable, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES) ])), symbol_table=SymbolTable({ symbol.name: su.file_ref_constant_container(symbol.value), }) ) expectation = Expectation( result_of_execute=eh_assertions.is_exit_code(0), sub_process_result_from_execute=pr.stdout(str_asrt.contains(file_name_of_referenced_file)), symbol_usages=equals_symbol_references( [SymbolReference(symbol.name, is_any_data_type())] ) ) check_execution(self, sut.Parser(), [instr([command_line])], arrangement, expectation)
rel_opt.conf_rel_any(RelOptionType.REL_ACT), rel_opt.conf_rel_any(RelOptionType.REL_TMP), rel_opt.symbol_conf_rel_any(RelOptionType.REL_TMP, symbol_name, syntax_elements.REL_OPTION_ARG_CONF.options.accepted_relativity_variants), rel_opt.symbol_conf_rel_any(RelOptionType.REL_HOME_CASE, symbol_name, syntax_elements.REL_OPTION_ARG_CONF.options.accepted_relativity_variants), ] RELATIVITY_OPTIONS = relativity_options('EXECUTABLE_FILE_SYMBOL_NAME') python_program_that_exits_with_code_0 = 'exit(0)' EXECUTABLE_FILE_THAT_EXITS_WITH_CODE_0 = fs.python_executable_file('executable-file', python_program_that_exits_with_code_0) python_program_that_exits_with_code_given_as_first_cl_arg = """\ import sys exit_code = int(sys.argv[1]) sys.exit(exit_code) """ if __name__ == '__main__': unittest.TextTestRunner().run(suite())
rel_opt.conf_rel_any(RelOptionType.REL_ACT), rel_opt.conf_rel_any(RelOptionType.REL_TMP), rel_opt.symbol_conf_rel_any( RelOptionType.REL_TMP, symbol_name, syntax_elements. EXE_FILE_REL_OPTION_ARG_CONF.options.accepted_relativity_variants), rel_opt.symbol_conf_rel_any( RelOptionType.REL_HDS_CASE, symbol_name, syntax_elements. EXE_FILE_REL_OPTION_ARG_CONF.options.accepted_relativity_variants), ] RELATIVITY_OPTIONS = relativity_options_of_symbol( 'EXECUTABLE_FILE_SYMBOL_NAME') python_program_that_exits_with_code_0 = 'exit(0)' EXECUTABLE_FILE_THAT_EXITS_WITH_CODE_0 = fs.python_executable_file( 'executable-file', python_program_that_exits_with_code_0) python_program_that_exits_with_code_given_as_first_cl_arg = """\ import sys exit_code = int(sys.argv[1]) sys.exit(exit_code) """ PARSE_CHECKER = parse_checker.Checker(sut.embryo_parser('instruction-name')) EXECUTION_CHECKER = embryo_check.Checker(sut.embryo_parser('instruction-name')) if __name__ == '__main__': unittest.TextTestRunner().run(suite())
def _additional_files_in_file_structure( self, root_path: pathlib.Path) -> List[FileSystemElement]: return [ fs.python_executable_file( 'system-under-test', PYTHON_PROGRAM_THAT_EXISTS_WITH_STATUS_0) ]
def runTest(self): # ARRANGE # actor = sut.actor(COMMAND_THAT_RUNS_PYTHON_PROGRAM_FILE) exe_file = fs.python_executable_file( 'program-name', py_programs.exit_with_0() ) argument_to_act_file = 'argument-to-act-file' act_contents = ab.sequence__r([ ab.singleton(exe_file.name), ab.singleton(argument_to_act_file) ]) interpreter_arguments_symbol = ListConstantSymbolContext('INTERPRETER_ARGS_LIST', ['1st', '2nd']) interpreter_arguments = ArgumentsSdv.new_without_validation( interpreter_arguments_symbol.sdv ) actor = sut.actor( command_sdvs.for_executable_file( path_sdvs.constant(path_ddvs.absolute_file_name(sys.executable)), interpreter_arguments ) ) def get_command_assertion(tcds: TestCaseDs) -> Assertion[Command]: symbols = SymbolTable.empty() return asrt_command.matches_command( asrt.anything_goes(), asrt.equals( interpreter_arguments_symbol.constant_list + [ str(relativity_configurations.ATC_FILE .named_file_conf(exe_file.name) .path_sdv .resolve(symbols) .value_of_any_dependency__d(tcds) .primitive ), argument_to_act_file, ] ) ) act_instruction = instr([act_contents.as_str]) executor_that_records_arguments = CommandExecutorThatRecordsArguments() # ACT & ASSERT # integration_check.check_execution( self, actor, [act_instruction], arrangement_w_tcds( process_execution=ProcessExecutionArrangement( os_services=os_services_access.new_for_cmd_exe(executor_that_records_arguments) ), hds_contents=relativity_configurations.ATC_FILE.populator_for_relativity_option_root__hds( fs.DirContents([exe_file]) ) ), Expectation( after_execution=ExecutedCommandAssertion( executor_that_records_arguments, get_command_assertion, ) ), )
def runTest(self): # ARRANGE # actor = sut.actor(COMMAND_THAT_RUNS_PYTHON_PROGRAM_FILE) exe_file = fs.python_executable_file( 'program-name', py_programs.exit_with_0() ) text_until_end_of_line = 'some {}invalidly quoted text'.format(SOFT_QUOTE_CHAR) existing_path_relativity = relativity_options.conf_rel_hds(RelHdsOptionType.REL_HDS_CASE) existing_path_argument = path_arguments.RelOptPathArgument( 'existing-path', existing_path_relativity.relativity, ) act_contents = ab.sequence__r([ ab.singleton(exe_file.name), program_arguments.existing_path( existing_path_argument ), program_arguments.remaining_part_of_current_line_as_literal(text_until_end_of_line), ]) def get_command_assertion(tcds: TestCaseDs) -> Assertion[Command]: symbols = SymbolTable.empty() return asrt_command.matches_command( asrt.anything_goes(), asrt.equals([ str(relativity_configurations.ATC_FILE .named_file_conf(exe_file.name) .path_sdv .resolve(symbols) .value_of_any_dependency__d(tcds) .primitive ), str(existing_path_relativity .named_file_conf(existing_path_argument.name) .path_sdv .resolve(symbols) .value_of_any_dependency__d(tcds) .primitive ), text_until_end_of_line, ]) ) act_instruction = instr([act_contents.as_str]) executor_that_records_arguments = CommandExecutorThatRecordsArguments() # ACT & ASSERT # integration_check.check_execution( self, actor, [act_instruction], arrangement_w_tcds( process_execution=ProcessExecutionArrangement( os_services=os_services_access.new_for_cmd_exe(executor_that_records_arguments) ), hds_contents=hds_populators.multiple([ relativity_configurations.ATC_FILE.populator_for_relativity_option_root__hds( fs.DirContents([exe_file]) ), existing_path_relativity.populator_for_relativity_option_root__hds( fs.DirContents([fs.File.empty(existing_path_argument.name)]) ), ]) ), Expectation( after_execution=ExecutedCommandAssertion( executor_that_records_arguments, get_command_assertion, ) ), )
def _additional_files_in_file_structure(self, root_path: pathlib.Path) -> List[FileSystemElement]: return [ fs.python_executable_file('system-under-test', PYTHON_PROGRAM_THAT_EXISTS_WITH_STATUS_0) ]