def runTest(self): # ARRANGE # string_72_plus = StringSymbolContext.of_constant( 'SYMBOL_72_PLUS', '72+', default_restrictions=asrt_data_rest. is__string__w_all_indirect_refs_are_strings(), ) string_5 = StringSymbolContext.of_constant( 'SYMBOL_5', '5', default_restrictions=asrt_data_rest. is__string__w_all_indirect_refs_are_strings(), ) expected = 72 + 5 all_symbols = [string_72_plus, string_5] value_syntax = StringConcatAbsStx([ string_72_plus.abstract_syntax, string_5.abstract_syntax, ]) # ACT & ASSERT # self.conf.instruction_checker.check_parsing__abs_stx__const( self, self.conf.parser(), InstructionArgumentsAbsStx.of_int(value_syntax), self.conf.arrangement( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), ), self.conf.expect_success( symbol_usages=SymbolContext.usages_assertion_of_contexts( all_symbols), instruction_settings=asrt_is.matches( timeout=asrt.equals(expected))))
def _check(put: unittest.TestCase, integer_matcher: IntegerMatcherAbsStx, integer_matcher_symbols: List[SymbolContext]): # ARRANGE # program_symbol = ProgramSymbolContext.of_arbitrary_value('PROGRAM_SYMBOL') all_symbols = [program_symbol] + integer_matcher_symbols command_execution_counter = recording.Counter(initial_value=0) # ACT & ASSERT # CHECKER.check__abs_stx( put, InstructionArguments( program_symbol.abstract_syntax, integer_matcher, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), process_execution=ProcessExecutionArrangement( os_services=os_services_w_cmd_exe_counting__w_wrapped( command_execution_counter, CommandExecutorThatJustReturnsConstant(1) ), ) ), Expectation2( ParseExpectation( symbol_usages=SymbolContext.usages_assertion_of_contexts(all_symbols) ) ), ) put.assertEqual(1, command_execution_counter.value, 'number of times the program has been executed')
def runTest(self): # ARRANGE # program_symbol = StringConstantSymbolContext( 'program_name_symbol', 'the-program', default_restrictions=asrt_rest.is__string__w_all_indirect_refs_are_strings(), ) argument_list_symbol = ListConstantSymbolContext( 'arguments_symbol', ['1st', '2nd'], ) symbols = [program_symbol, argument_list_symbol] expected_command = asrt_command.matches_command( driver=asrt_command.matches_system_program_command_driver( asrt.equals(program_symbol.str_value) ), arguments=asrt.equals(argument_list_symbol.constant), ) # ACT & ASSERT # check_successful_execution( self, arguments=command_line( program_symbol.name__sym_ref_syntax, program_arguments.simple(argument_list_symbol.name__sym_ref_syntax), ), expected_command=expected_command, symbols=SymbolContext.symbol_table_of_contexts(symbols), symbol_usages=SymbolContext.usages_assertion_of_contexts(symbols) )
def runTest(self): # ARRANGE # sm_1 = StringMatcherSymbolContextOfPrimitiveConstant('sm_1', True) sm_2 = StringMatcherSymbolContextOfPrimitiveConstant('sm_2', False) symbols = [sm_1, sm_2] matcher_syntax = StringMatcherInfixOpAbsStx.disjunction([ sm_1.abstract_syntax, sm_2.abstract_syntax, ]) is_pass = sm_1.result_value or sm_2.result_value # ACT & ASSERT # self.configuration.checker.check__abs_stx__source_variants( self, self.configuration.syntax_for_matcher(matcher_syntax), self.configuration.arrangement_for_contents( actual_contents='', symbols=SymbolContext.symbol_table_of_contexts(symbols), post_sds_population_action= MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY, ).as_arrangement_2(), MultiSourceExpectation( symbol_usages=SymbolContext.usages_assertion_of_contexts( symbols), execution=ExecutionExpectation( main_result=asrt_pfh.is_non_hard_error(is_pass), ), ))
def runTest(self): # ARRANGE # stdin_from_act_exe_input = 'the stdin from the Act Execution Input (via [setup])' stdin_defined_by_the_program = 'the stdin defined by the program' test_setup = StdinCheckViaCopyToOutputFileTestSetup( ProcOutputFile.STDOUT, stdin_defined_for_program=[ ss_sdvs.const_str(stdin_defined_by_the_program) ]) full_stdin = stdin_defined_by_the_program + stdin_from_act_exe_input # ACT & ASSERT # CHECKER.check__abs_stx( self, test_setup.program_that_copies_stdin_syntax(), Arrangement( symbols=SymbolContext.symbol_table_of_contexts( test_setup.symbols), atc_exe_input=AtcExeInputArr( stdin_contents=stdin_from_act_exe_input, ), tcds=TcdsArrangementPreAct(), ), Expectation( symbol_usages=SymbolContext.usages_assertion_of_contexts( test_setup.symbols), post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=asrt_proc_result. matches_proc_result(exit_code=asrt.equals(0), stdout=asrt.equals(full_stdin))), ), )
def runTest(self): vars_before = [ ValueWSymRefsAndVarRefs.REFERENCED_VAR_1, ValueWSymRefsAndVarRefs.REFERENCED_VAR_2 ] setup_before = EnvironsSetup(vars_before, vars_before) var_to_set__resolved = NameAndValue( NameWSymRefs.RESOLVED_STR, ValueWSymRefsAndVarRefs.VALUE_WO_VAR_REFS) all_symbols = NameWSymRefs.SYMBOL_CONTEXTS + ValueWSymRefsAndVarRefs.SYMBOL_CONTEXTS execution_cases = _exe_cases_of_modification( before_modification=setup_before, after_modification=setup_before.new_with_added( var_to_set__resolved, var_to_set__resolved), symbols=SymbolContext.symbol_table_of_contexts(all_symbols), ) # ACT & ASSERT # CHECKER.check__abs_stx__multi__std_layouts_and_source_variants( self, SetVariableArgumentsAbsStx( NameWSymRefs.STRING_ABS_STX, StringSourceOfStringAbsStx( ValueWSymRefsAndVarRefs.STRING_ABS_STX), phase_spec=None, ), symbol_usages=SymbolContext.usages_assertion_of_contexts( all_symbols), execution_cases=execution_cases, )
def test_stdin_is_concatenation_of_string_sources_WHEN_program_defines_multiple_stdin( self): # ARRANGE # test_setup = MultipleStdinOfProgramTestSetup(self, exit_code=0) all_symbols = [ test_setup.program_symbol, CONST_TRUE_INT_MATCHER_SYMBOL ] # ACT & ASSERT # CHECKER.check__abs_stx__source_variants( self, InstructionArguments( test_setup.program_w_stdin_syntax, CONST_TRUE_INT_MATCHER_SYMBOL.abstract_syntax, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), process_execution=test_setup.proc_exe_env__w_stdin_check, ), MultiSourceExpectation( symbol_usages=SymbolContext.usages_assertion_of_contexts( all_symbols), execution=ExecutionExpectation(main_result=asrt_pfh.is_pass()), ), )
def runTest(self): string_72_plus = StringSymbolContext.of_constant( 'SYMBOL_72_PLUS', '72+', default_restrictions=asrt_data_rest. is__string__w_all_indirect_refs_are_strings(), ) string_5 = StringSymbolContext.of_constant( 'SYMBOL_5', '5', default_restrictions=asrt_data_rest. is__string__w_all_indirect_refs_are_strings(), ) expected = 72 + 5 all_symbols = [string_72_plus, string_5] value_syntax = StringConcatAbsStx([ string_72_plus.abstract_syntax, string_5.abstract_syntax, ]) CHECKER.check__abs_stx__layout_and_source_variants( self, InstructionArgumentsAbsStx.of_int(value_syntax), Arrangement.phase_agnostic( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), ), MultiSourceExpectation.phase_agnostic( symbol_usages=SymbolContext.usages_assertion_of_contexts( all_symbols), instruction_settings=asrt_instr_settings.matches( timeout=asrt.equals(expected))), )
def runTest(self): # ARRANGE # checked_dir = Dir.empty('the-checked-dir') fsm_1 = FilesMatcherSymbolContextOfPrimitiveConstant('fsm_1', True) fsm_2 = FilesMatcherSymbolContextOfPrimitiveConstant('fsm_2', False) symbols = [fsm_1, fsm_2] rel_conf = rel_opt_conf.conf_rel_any(RelOptionType.REL_ACT) arguments = args.recursive( rel_conf.path_argument_of_rel_name(checked_dir.name), fsm_args.disjunction([fsm_1.argument, fsm_2.argument]), ) is_pass = fsm_1.result_value or fsm_2.result_value # ACT # & ASSERT # INSTRUCTION_CHECKER.check_2( self, arguments.as_remaining_source, ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts(symbols), tcds=TcdsArrangementPostAct( tcds_contents=rel_conf. populator_for_relativity_option_root( DirContents([checked_dir])))), Expectation2( ParseExpectation( source=asrt_source.source_is_at_end, symbol_usages=SymbolContext.usages_assertion_of_contexts( symbols), ), ExecutionExpectation( main_result=asrt_pfh.is_non_hard_error(is_pass), ), ))
def runTest(self): vars_before = [ ValueWSymRefsAndVarRefs.REFERENCED_VAR_1, ValueWSymRefsAndVarRefs.REFERENCED_VAR_2 ] var_to_set__resolved = NameAndValue( NameWSymRefs.RESOLVED_STR, ValueWSymRefsAndVarRefs.VALUE_WO_VAR_REFS) all_symbols = NameWSymRefs.SYMBOL_CONTEXTS + ValueWSymRefsAndVarRefs.SYMBOL_CONTEXTS execution_cases = _exe_cases_of_modification( before_modification=vars_before, after_modification=vars_before + [var_to_set__resolved], symbols=SymbolContext.symbol_table_of_contexts(all_symbols), ) # ACT & ASSERT # for phase_spec__source in [None, Phase.NON_ACT]: CHECKER.check__abs_stx__multi__std_layouts_and_source_variants( self, SetVariableArgumentsAbsStx( NameWSymRefs.STRING_ABS_STX, StringSourceOfStringAbsStx( ValueWSymRefsAndVarRefs.STRING_ABS_STX), phase_spec=phase_spec__source, ), symbol_usages=SymbolContext.usages_assertion_of_contexts( all_symbols), execution_cases=execution_cases, sub_test_identifiers={ 'phase_spec__source': phase_spec__source, }, )
def runTest(self): file_in_root = File.empty('file-in-root.txt') files_in_root_dir = [file_in_root] file_matcher_symbol = FileMatcherSymbolContext.of_primitive_constant( 'FILE_MATCHER_SYMBOL', True, ) file_matcher_cases = [ NInpArr( 'wo file matcher', None, (), ), NInpArr( 'w file matcher', file_matcher_symbol.abstract_syntax, [file_matcher_symbol], ), ] relativity_cases = [ rel_opt_conf.conf_rel_any(RelOptionType.REL_TMP), rel_opt_conf.conf_rel_any(RelOptionType.REL_HDS_CASE), ] for expectation_type in ExpectationType: for file_matcher_case in file_matcher_cases: for rel_conf in relativity_cases: with self.subTest(relativity=rel_conf.relativity, file_matcher=file_matcher_case.name, expectation_type=expectation_type): CHECKER.check__abs_stx__source_variants( self, InstructionArguments( rel_conf.path_abs_stx_of_name__c([ file_in_root.name, 'path-to-check' ]), expectation_type=expectation_type, file_matcher=file_matcher_case.input, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts(file_matcher_case.arrangement), tcds=TcdsArrangementPostAct( tcds_contents=rel_conf.populator_for_relativity_option_root( DirContents(files_in_root_dir) ) ) ), MultiSourceExpectation( symbol_usages=SymbolContext.usages_assertion_of_contexts(file_matcher_case.arrangement), execution=ExecutionExpectation( main_result=pfh_assertions.is_pass_of_fail( expectation_type is ExpectationType.NEGATIVE ) ) ) )
def runTest(self): # ARRANGE # actual_file_name = 'actual' file_type_cases = [ NameAndValue( 'regular file', [fs.File.empty(actual_file_name)], ), NameAndValue( 'sym-link to regular file', [ fs.File.empty('a-regular-file'), fs.sym_link(actual_file_name, 'a-regular-file') ], ), ] for file_type_case in file_type_cases: for rel_conf in RELATIVITY_OPTION_CONFIGURATIONS_FOR_ACTUAL_FILE: for matcher_result in [False, True]: matcher_symbol = StringMatcherSymbolContextOfPrimitiveConstant('STRING_MATCHER', matcher_result) all_symbols = list(rel_conf.symbols.contexts_for_arrangement()) + [matcher_symbol] with self.subTest(file_type=file_type_case, path_variant=rel_conf.name, matcher_result=matcher_result): CHECKER.check__abs_stx__source_variants( self, InstructionArgumentsAbsStx( rel_conf.path_abs_stx_of_name(actual_file_name), matcher_symbol.abstract_syntax, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), tcds=TcdsArrangementPostAct( tcds_contents=rel_conf.populator_for_relativity_option_root( DirContents(file_type_case.value)), post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY, ) ), MultiSourceExpectation( symbol_usages=SymbolContext.usages_assertion_of_contexts(all_symbols), execution=ExecutionExpectation( main_result=asrt_pfh.is_pass_of_fail(matcher_symbol.result_value) ) ), )
def runTest(self): var_to_unset = NameAndValue(NameWSymRefs.RESOLVED_STR, 'value of var') vars_before = EnvironsSetup([var_to_unset], [var_to_unset]) all_symbols = NameWSymRefs.SYMBOL_CONTEXTS execution_cases = _exe_cases_of_modification( before_modification=vars_before, after_modification=vars_before.new_with_removed(var_to_unset.name), symbols=SymbolContext.symbol_table_of_contexts(all_symbols), ) # ACT & ASSERT # CHECKER.check__abs_stx__multi__std_layouts_and_source_variants( self, UnsetVariableArgumentsAbsStx(NameWSymRefs.STRING_ABS_STX, phase_spec=None), symbol_usages=SymbolContext.usages_assertion_of_contexts( all_symbols), execution_cases=execution_cases, )
def runTest(self): # ARRANGE # program_symbol = ProgramSymbolContext.of_arbitrary_value( 'PROGRAM_SYMBOL') const_true_int_matcher_symbol = IntegerMatcherSymbolContext.of_primitive_constant( 'CONST_TRUE_INT_MATCHER', result=True, ) string_transformer_that_reports_failure_if_applied = StringTransformerSymbolContext.of_primitive( 'STRING_TRANSFORMER_THAT_MUST_NOT_BE_USED', StringTransformerThatFailsTestIfApplied(self)) all_symbols = [ program_symbol, string_transformer_that_reports_failure_if_applied, const_true_int_matcher_symbol, ] # ACT & ASSERT # CHECKER.check__abs_stx( self, InstructionArguments( FullProgramAbsStx( program_symbol.abstract_syntax, transformation= string_transformer_that_reports_failure_if_applied. abstract_syntax), const_true_int_matcher_symbol.abstract_syntax, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), process_execution=ProcessExecutionArrangement( os_services_access.new_for_cmd_exe( CommandExecutorThatJustReturnsConstant(1), ), ), ), Expectation2( ParseExpectation( symbol_usages=SymbolContext.usages_assertion_of_contexts( all_symbols), ), ExecutionExpectation(main_result=asrt_pfh.is_pass()), ))
def runTest(self): # ARRANGE # program_symbol = ProgramSymbolContext.of_arbitrary_value('PROGRAM_SYMBOL') const_true_int_matcher_symbol = IntegerMatcherSymbolContext.of_primitive_constant( 'CONST_TRUE_INT_MATCHER', result=True, ) all_symbols = [program_symbol, const_true_int_matcher_symbol, ] hard_error_message = 'the err msg' # ACT & ASSERT # CHECKER.check__abs_stx( self, InstructionArguments( program_symbol.abstract_syntax, const_true_int_matcher_symbol.abstract_syntax, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), process_execution=ProcessExecutionArrangement( os_services_access.new_for_cmd_exe( CommandExecutorThatRaisesHardError( asrt_text_doc.new_single_string_text_for_test(hard_error_message) ), ), ), ), Expectation2( ParseExpectation( symbol_usages=SymbolContext.usages_assertion_of_contexts(all_symbols), ), ExecutionExpectation( main_result=asrt_pfh.is_hard_error( asrt_text_doc.is_string_for_test_that_equals(hard_error_message) ) ), ) )
def runTest(self): vars_before = [NameAndValue(NameWSymRefs.RESOLVED_STR, 'value of var')] vars_after = [] all_symbols = NameWSymRefs.SYMBOL_CONTEXTS execution_cases = _exe_cases_of_modification( before_modification=vars_before, after_modification=vars_after, symbols=SymbolContext.symbol_table_of_contexts(all_symbols), ) # ACT & ASSERT # for phase_spec__source in [None, Phase.NON_ACT]: CHECKER.check__abs_stx__multi__std_layouts_and_source_variants( self, UnsetVariableArgumentsAbsStx(NameWSymRefs.STRING_ABS_STX, phase_spec=phase_spec__source), symbol_usages=SymbolContext.usages_assertion_of_contexts( all_symbols), execution_cases=execution_cases, sub_test_identifiers={ 'phase_spec__source': phase_spec__source, }, )
def _check_exit_codes(self, exit_code_cases: List[int], ignore_exit_code: bool, main_result: Assertion[Optional[TextRenderer]], expected_output_dir_contents: Optional[Callable[[str, str], DirContents]], ): # ARRANGE # destination_file_name = 'dst-file.txt' program_output = { ProcOutputFile.STDOUT: 'output on stdout', ProcOutputFile.STDERR: 'output on stderr', } transformer = TO_UPPER_TRANSFORMER_SYMBOL sym_ref_program = ProgramOfSymbolReferenceAbsStx('PROGRAM_SYMBOL_NAME') program_builder = program_abs_stx.TransformableProgramAbsStxBuilder( ProgramOfSymbolReferenceAbsStx(sym_ref_program.symbol_name) ) program_cases = [ ProgramAndSymbolsCase( 'without transformation', program_builder.without_transformation(), [], adapt_expected_program_output=lambda s: s ), ProgramAndSymbolsCase( 'with transformation', program_builder.with_transformation(transformer.abstract_syntax), [transformer], adapt_expected_program_output=str.upper ), ] program_builder.with_and_without_transformer_cases(transformer.abstract_syntax) py_file_rel_conf = rel_opt.conf_rel_any(RelOptionType.REL_HDS_CASE) dst_file_rel_conf = ARBITRARY_ALLOWED_DST_FILE_RELATIVITY for output_file in ProcOutputFile: for exit_code in exit_code_cases: py_file = File('exit-with-hard-coded-exit-code.py', py_programs.py_pgm_with_stdout_stderr_exit_code( exit_code=exit_code, stdout_output=program_output[ProcOutputFile.STDOUT], stderr_output=program_output[ProcOutputFile.STDERR], ), ) py_file_conf = py_file_rel_conf.named_file_conf(py_file.name) dst_file_conf = dst_file_rel_conf.named_file_conf(destination_file_name) program_symbol = ProgramSymbolContext.of_sdv( sym_ref_program.symbol_name, program_sdvs.interpret_py_source_file_that_must_exist(py_file_conf.path_sdv) ) for program_case in program_cases: instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_file_conf.abstract_syntax, string_source_abs_stx.StringSourceOfProgramAbsStx( output_file, program_case.syntax, ignore_exit_code=ignore_exit_code) ) expected_program_output = program_case.adapt_expected_program_output(program_output[output_file]) main_side_effects_on_sds = ( dst_file_rel_conf.assert_root_dir_contains_exactly( expected_output_dir_contents(dst_file_conf.name, expected_program_output) ) if expected_output_dir_contents is not None else asrt.anything_goes() ) symbol_contexts = [program_symbol] + program_case.additional_symbols # ACT && ASSERT # for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic( symbols=SymbolContext.symbol_table_of_contexts(symbol_contexts), tcds=TcdsArrangement( tcds_contents=py_file_rel_conf.populator_for_relativity_option_root( DirContents([py_file]) ) ), ), MultiSourceExpectation.phase_agnostic( symbol_usages=SymbolContext.usages_assertion_of_contexts(symbol_contexts), main_result=main_result, main_side_effects_on_sds=main_side_effects_on_sds, ), sub_test_identifiers={ 'exit_code': exit_code, 'output_file': output_file, 'program': program_case.name, 'phase_is_after_act': phase_is_after_act, }, )
def usages_assertion(self) -> Assertion[Sequence[SymbolUsage]]: return SymbolContext.usages_assertion_of_contexts(self.symbols)