def test_result_SHOULD_be_true_iff_exit_code_is_0(self): # ARRANGE # program_symbol_name = 'PROGRAM_THAT_EXECUTES_PY_FILE' exit_code_symbol_name = 'EXIT_CODE_SYMBOL' # ACT && ASSERT # integration_check.CHECKER__PARSE_FULL.check_multi( self, args.RunProgram( program_args.symbol_ref_command_elements( program_symbol_name, arguments=[ symbol_reference_syntax_for_name(exit_code_symbol_name) ], )).as_arguments, ParseExpectation( source=asrt_source.is_at_end_of_line(1), symbol_references=asrt.matches_sequence([ is_reference_to_program(program_symbol_name), is_reference_to__w_str_rendering(exit_code_symbol_name), ]), ), integration_check.ARBITRARY_MODEL, test_cases.exit_code_exe_cases( program_symbol_name, exit_code_symbol_name, ), )
def runTest(self): # ARRANGE # program_symbol_name = 'PROGRAM_SYMBOL' # ACT && ASSERT # integration_check.CHECKER__PARSE_FULL.check_multi( self, args.RunProgram( program_args.symbol_ref_command_elements( program_symbol_name)).as_arguments, ParseExpectation( source=asrt_source.is_at_end_of_line(1), symbol_references=asrt.matches_sequence([ is_reference_to_program(program_symbol_name), ]), ), model_constructor.arbitrary(self), [ validation_cases.validation_exe_case(validation_case) for validation_case in validation_cases.failing_validation_cases( program_symbol_name, 'TRANSFORMER_SYMBOL') ], )
def _check( self, output: StdOutputFilesContents, exit_code_cases: List[int], ignore_exit_code: bool, execution_expectation: ExecutionExpectation, ): # ARRANGE # py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP) for exit_code in exit_code_cases: with self.subTest(non_zero_exit_code=exit_code): py_file = File( 'exit-with-hard-coded-exit-code.py', py_programs.py_pgm_with_stdout_stderr_exit_code( stdout_output=output.out, stderr_output=output.err, exit_code=exit_code, ), ) py_file_conf = py_file_rel_opt_conf.named_file_conf( py_file.name) program_symbol = ProgramSymbolContext.of_sdv( 'PROGRAM_SYMBOL_NAME', program_sdvs.interpret_py_source_file_that_must_exist( py_file_conf.path_sdv)) # ACT && ASSERT # integration_check.CHECKER__PARSE_FULL.check( self, args.syntax_for_run( program_args.symbol_ref_command_elements( program_symbol.name), ignore_exit_code=ignore_exit_code, ).as_remaining_source, model_constructor.arbitrary(self), arrangement_w_tcds( symbols=program_symbol.symbol_table, tcds_contents=py_file_rel_opt_conf. populator_for_relativity_option_root( DirContents([py_file])), ), Expectation( ParseExpectation( source=asrt_source.is_at_end_of_line(1), symbol_references=program_symbol. references_assertion), execution_expectation, ), )
def runTest(self): # ARRANGE # py_file = File('stdin-to-upper.py', _PGM_THAT_OUTPUTS_STDIN_IN_UPPER_CASE) py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP) py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name) program_symbol = ProgramSymbolContext.of_sdv( 'PROGRAM_THAT_EXECUTES_PY_FILE', program_sdvs.interpret_py_source_file_that_must_exist(py_file_conf.path_sdv) ) input_model_lines = [ 'the\n', 'input\n', 'model', ] expected_output_model_lines = list(map(str.upper, input_model_lines)) for with_ignored_exit_code in [False, True]: with self.subTest(with_ignored_exit_code=with_ignored_exit_code): # ACT && ASSERT # integration_check.CHECKER__PARSE_FULL.check__w_source_variants_for_full_line_parser( self, args.syntax_for_run( program_args.symbol_ref_command_elements(program_symbol.name), ignore_exit_code=with_ignored_exit_code, ), model_constructor.of_lines(self, input_model_lines), arrangement_w_tcds( tcds_contents=py_file_rel_opt_conf.populator_for_relativity_option_root( DirContents([py_file]) ), symbols=program_symbol.symbol_table, ), MultiSourceExpectation( symbol_references=program_symbol.references_assertion, execution=ExecutionExpectation( main_result=asrt_string_source.pre_post_freeze__matches_lines( asrt.equals(expected_output_model_lines), may_depend_on_external_resources=asrt.equals(True), frozen_may_depend_on_external_resources=asrt.anything_goes(), ) ), primitive=prim_asrt__constant( asrt_string_transformer.is_identity_transformer(False) ), ), )
def runTest(self): # ARRANGE # program_symbol = ProgramSymbolContext.of_arbitrary_value( 'PROGRAM_SYMBOL') executor_that_do_not_run_any_program = CommandExecutorThatJustReturnsConstant( 0) for may_depend_on_external_resources in [False, True]: for with_ignored_exit_code in [False, True]: with self.subTest( with_ignored_exit_code=with_ignored_exit_code, may_depend_on_external_resources= may_depend_on_external_resources): # ACT && ASSERT # pass integration_check.CHECKER__PARSE_SIMPLE.check( self, args.syntax_for_run( program_args.symbol_ref_command_elements( program_symbol.name), ignore_exit_code=with_ignored_exit_code, ).as_remaining_source, model_constructor.empty(self, may_depend_on_external_resources= may_depend_on_external_resources), arrangement_w_tcds( symbols=program_symbol.symbol_table, process_execution=ProcessExecutionArrangement( os_services=os_services_access.new_for_cmd_exe( executor_that_do_not_run_any_program)), ), Expectation( ParseExpectation(symbol_references=program_symbol. references_assertion, ), ExecutionExpectation( main_result=asrt_string_source. pre_post_freeze__matches_lines( asrt.anything_goes(), may_depend_on_external_resources=asrt.equals( True), frozen_may_depend_on_external_resources=asrt. anything_goes(), )), prim_asrt__constant( asrt_string_transformer.is_identity_transformer( False)), ), )
def runTest(self): # ARRANGE # program_symbol = ProgramSymbolContext.of_sdv( 'A_PROGRAM', program_sdvs.arbitrary__without_symbol_references()) pgm_and_args_cases = [ NameAndValue('shell command', pgm_args.shell_command('shell-command arg')), NameAndValue( 'system command', pgm_args.system_program_argument_elements( 'system command arg')), NameAndValue('python', pgm_args.interpret_py_source_elements('exit(0)')), NameAndValue( 'symbol reference', pgm_args.symbol_ref_command_elements(program_symbol.name, [])), ] for pgm_and_args_case in pgm_and_args_cases: for validation_case in failing_validation_cases(): arguments = pgm_and_args_case.value.followed_by_lines( [validation_case.value.transformer_arguments_elements]) symbols = SymbolContext.symbol_table_of_contexts([ program_symbol, validation_case.value.symbol_context, ]) with self.subTest(pgm_and_args_case=pgm_and_args_case.name, validation_case=validation_case.name): # ACT & ASSERT # CHECKER_W_TRANSFORMATION.check( self, arguments.as_remaining_source, ProcOutputFile.STDOUT, arrangement_w_tcds(symbols=symbols), Expectation( ParseExpectation( symbol_references=asrt.anything_goes(), ), ExecutionExpectation( validation=validation_case.value.expectation, )))
def _check( put: unittest.TestCase, arg_pos_option: PathArgumentPositionArgument, command_line_arguments_cases: List[List[str]], expected_arg_list: Callable[[List[str], str], List[str]], ): # ARRANGE # program_symbol_name = 'PROGRAM_THAT_EXECUTES_PY_FILE' command_line_arg_list_symbol_name = 'COMMAND_LINE_ARGUMENTS_LIST' model_file_path = 'the-file-to-match' # ACT && ASSERT # integration_check.CHECKER__PARSE_FULL.check_multi__w_source_variants_for_full_line_parser( put, args.RunProgram( program_args.symbol_ref_command_elements( program_symbol_name, arguments=[symbol_reference_syntax_for_name(command_line_arg_list_symbol_name)], ), arg_pos_option, ).as_arguments, input_=integration_check.constant_relative_file_name(model_file_path), symbol_references=asrt.matches_sequence([ is_reference_to_program(program_symbol_name), is_reference_to__w_str_rendering(command_line_arg_list_symbol_name), ]), execution=[ test_cases.argument_list_exe_case( command_line_arguments, expected_arg_list(command_line_arguments, model_file_path), program_symbol_name, command_line_arg_list_symbol_name) for command_line_arguments in command_line_arguments_cases ], )
def runTest(self): # ARRANGE # program_symbol_name = 'PROGRAM_THAT_EXECUTES_PY_FILE' environment_cases = [ { '1': 'one', }, { '1': 'one', '2': 'two', }, ] # ACT && ASSERT # integration_check.CHECKER__PARSE_FULL.check_multi( self, args.RunProgram( program_args.symbol_ref_command_elements( program_symbol_name, arguments=[], ) ).as_arguments, ParseExpectation( source=asrt_source.is_at_end_of_line(1), symbol_references=asrt.matches_singleton_sequence( is_reference_to_program(program_symbol_name) ), ), integration_check.ARBITRARY_MODEL, [ test_cases.environment_exe_case(environment_case, program_symbol_name) for environment_case in environment_cases ], )
def runTest(self): # ARRANGE # program_symbol_name = 'PROGRAM_THAT_EXECUTES_PY_FILE' command_line_arg_list_symbol_name = 'COMMAND_LINE_ARGUMENTS_LIST' command_line_arguments_cases = [ [], ['one'], ['one', 'two'], ] # ACT && ASSERT # integration_check.CHECKER__PARSE_FULL.check_multi__w_source_variants_for_full_line_parser( self, args.RunProgram( program_args.symbol_ref_command_elements( program_symbol_name, arguments=[ symbol_reference_syntax_for_name( command_line_arg_list_symbol_name) ], )).as_arguments, model_constructor.arbitrary(self), symbol_references=asrt.matches_sequence([ is_reference_to_program(program_symbol_name), is_reference_to__w_str_rendering( command_line_arg_list_symbol_name), ]), execution=[ test_cases.argument_list_exe_case( command_line_arguments, command_line_arguments, program_symbol_name, command_line_arg_list_symbol_name) for command_line_arguments in command_line_arguments_cases ], )
def runTest(self): # ARRANGE # py_file = File( 'print-arguments-on-stdout.py', _PY_PROGRAM_THAT_PRINTS_ONE_ARGUMENT_PER_LINE_ON_STDOUT, ) py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP) py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name) program_symbol = ProgramSymbolContext.of_sdv( 'PROGRAM_SYMBOL_NAME', program_sdvs.interpret_py_source_file_that_must_exist( py_file_conf.path_sdv)) command_line_arg_list_symbol_name = 'COMMAND_LINE_ARGUMENTS_LIST' command_line_arguments_cases = [ [], ['one'], ['one', 'two'], ] def arguments_case( command_line_arguments: List[str], ) -> NExArr[PrimAndExeExpectation[StringTransformer, StringSource], Arrangement]: arg_list_symbol = ListSymbolContext.of_constants( command_line_arg_list_symbol_name, command_line_arguments) symbols = [ program_symbol, arg_list_symbol, ] expected_lines_on_stdout = asrt.matches_sequence( [asrt.equals(arg + '\n') for arg in command_line_arguments]) return NExArr( 'Arguments: ' + repr(command_line_arguments), PrimAndExeExpectation( ExecutionExpectation( main_result=asrt_string_source. pre_post_freeze__matches_lines( expected_lines_on_stdout, may_depend_on_external_resources=asrt.equals(True), frozen_may_depend_on_external_resources=asrt. anything_goes(), )), prim_asrt__constant( asrt_string_transformer.is_identity_transformer( False)), ), arrangement_w_tcds( symbols=SymbolContext.symbol_table_of_contexts(symbols), tcds_contents=py_file_rel_opt_conf. populator_for_relativity_option_root(DirContents([py_file ])), ), ) for with_ignored_exit_code in [False, True]: with self.subTest(with_ignored_exit_code=with_ignored_exit_code): # ACT && ASSERT # integration_check.CHECKER__PARSE_FULL.check_multi( self, args.syntax_for_run( program_args.symbol_ref_command_elements( program_symbol.name, arguments=[ symbol_reference_syntax_for_name( command_line_arg_list_symbol_name) ], ), ignore_exit_code=with_ignored_exit_code, ), ParseExpectation( source=asrt_source.is_at_end_of_line(1), symbol_references=asrt.matches_sequence([ program_symbol.reference_assertion, is_reference_to__w_str_rendering( command_line_arg_list_symbol_name), ]), ), model_constructor.arbitrary(self), [ arguments_case(command_line_arguments) for command_line_arguments in command_line_arguments_cases ], )
def argument_elements(self) -> ArgumentElements: return args.symbol_ref_command_elements( self._program_symbol_context.name)
def runTest(self): # ARRANGE # py_file = File('output-env-vars.py', _PGM_THAT_OUTPUTS_ENVIRONMENT_VARS) py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP) py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name) program_symbol = ProgramSymbolContext.of_sdv( 'PROGRAM_THAT_EXECUTES_PY_FILE', program_sdvs.interpret_py_source_file_that_must_exist( py_file_conf.path_sdv)) environment_cases = [ { '1': 'one', }, { '1': 'one', '2': 'two', }, ] for with_ignored_exit_code in [False, True]: with self.subTest(with_ignored_exit_code=with_ignored_exit_code): # ACT && ASSERT # integration_check.CHECKER__PARSE_FULL.check_multi( self, args.syntax_for_run( program_args.symbol_ref_command_elements( program_symbol.name), ignore_exit_code=with_ignored_exit_code, ), ParseExpectation( source=asrt_source.is_at_end_of_line(1), symbol_references=program_symbol.references_assertion, ), model_constructor.arbitrary(self), [ NExArr( 'Environment: {}'.format(repr(environment)), PrimAndExeExpectation( ExecutionExpectation( main_result=asrt_string_source. pre_post_freeze__matches_lines( _AssertLinesRepresentSubSetOfDict( environment), may_depend_on_external_resources=asrt. equals(True), frozen_may_depend_on_external_resources =asrt.anything_goes(), )), prim_asrt__constant( asrt_string_transformer. is_identity_transformer(False)), ), arrangement_w_tcds( tcds_contents=py_file_rel_opt_conf. populator_for_relativity_option_root( DirContents([py_file])), symbols=program_symbol.symbol_table, process_execution=ProcessExecutionArrangement( process_execution_settings= ProcessExecutionSettings.with_environ( environment)))) for environment in environment_cases ], )
def test_with_transformation(self): # ARRANGE # stdout_contents = 'output on stdout' stderr_contents = 'output on stderr' exit_code_cases = [0, 72] to_upper_transformer = test_transformers_setup.TO_UPPER_CASE_TRANSFORMER transformation_cases = [ NIE( 'stdout', stdout_contents.upper(), ProcOutputFile.STDOUT, ), NIE( 'stderr', stderr_contents.upper(), ProcOutputFile.STDERR, ), ] for exit_code_case in exit_code_cases: for transformation_case in transformation_cases: with self.subTest(exit_code=exit_code_case, transformation=transformation_case.name): python_source = py_pgm_with_stdout_stderr_exit_code( stdout_contents, stderr_contents, exit_code_case) program_that_executes_py_source = ProgramSymbolContext.of_sdv( 'PROGRAM_THAT_EXECUTES_PY_SOURCE', program_sdvs.for_py_source_on_command_line( python_source)) source = pgm_args.symbol_ref_command_elements( program_that_executes_py_source.name, transformation=to_upper_transformer.name ).as_remaining_source symbols = SymbolContext.symbol_table_of_contexts([ program_that_executes_py_source, to_upper_transformer ]) # ACT & ASSERT # CHECKER_W_TRANSFORMATION.check( self, source, transformation_case.input_value, arrangement_w_tcds(symbols=symbols, ), Expectation( ParseExpectation( symbol_references=asrt.matches_sequence([ program_that_executes_py_source. reference_assertion, is_reference_to_string_transformer( to_upper_transformer.name), ]), ), ExecutionExpectation( main_result=assert_process_result_data( exitcode=asrt.equals(exit_code_case), stdout_contents=asrt.equals( stdout_contents), stderr_contents=asrt.equals( stderr_contents), contents_after_transformation=asrt.equals( transformation_case.expected_value), ))))