def _check_( self, instruction_source: ParseSource, etc: ExpectationTypeConfigForPfh, main_result_for_positive_expectation: PassOrFail, rel_opt_config: RelativityOptionConfiguration, contents_of_relativity_option_root: DirContents = empty_dir_contents(), test_case_name: str = '', following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()): with self.put.subTest(case_name=test_case_name, expectation_type=etc.expectation_type.name, arguments=instruction_source.source_string): instruction_check.check( self.put, self.parser, instruction_source, ArrangementPostAct( pre_contents_population_action= MAKE_CWD_OUTSIDE_OF_EVERY_REL_OPT_DIR, tcds_contents=rel_opt_config. populator_for_relativity_option_root( contents_of_relativity_option_root), symbols=_symbol_table_of(rel_opt_config.symbols, following_symbols_setup), ), Expectation( main_result=etc.main_result( main_result_for_positive_expectation), symbol_usages=asrt.matches_sequence( rel_opt_config.symbols.usage_expectation_assertions() + following_symbols_setup.expected_usages_list), ))
def test_invalid_arguments_with_symbol_references(self): symbol_name = SymbolWithReferenceSyntax('symbol_name') operand_arg_with_symbol_ref_list = [ ' {op} {sym}'.format(op=comparators.EQ.name, sym=symbol_name), ] invalid_symbol_values = [ 'not_a_number', '1.5', '72 87', ] for invalid_symbol_value in invalid_symbol_values: symbol = StringConstantSymbolContext(symbol_name.name, invalid_symbol_value) for operand_arg_with_symbol_ref in operand_arg_with_symbol_ref_list: arguments = self._conf().arguments_constructor.apply( operand_arg_with_symbol_ref) with self.subTest(argument=arguments, invalid_symbol_value=invalid_symbol_value): for source in equivalent_source_variants__with_source_check__consume_last_line( self, arguments): self._check( source, ArrangementPostAct(symbols=symbol.symbol_table), Expectation( validation_pre_sds=svh_asrt. is_validation_error(), symbol_usages=asrt.matches_sequence([ symbol. reference_assertion__string__w_all_indirect_refs_are_strings ]), ), )
def runTest(self): output_from_program = 'first second' transformer_of_program = transformers_setup.DELETE_INITIAL_WORD_TRANSFORMER transformer_of_instruction = transformers_setup.DUPLICATE_WORDS_TRANSFORMER program_that_outputs_something = pgm_args.program( pgm_args.interpret_py_source_line( self.configuration.py_source_for_print(output_from_program)), transformation=transformer_of_program.name) result_when_positive = pfh_expectation_type_config( ExpectationType.POSITIVE) self._check_positive_and_negated( result_when_positive, program_that_outputs_something, matcher_arguments.equals_matcher( ab.quoted_string('second second')), lambda main_result: Expectation( main_result=main_result, symbol_usages=asrt.matches_sequence([ is_reference_to_string_transformer__usage( transformer_of_program.name), is_reference_to_string_transformer__usage( transformer_of_instruction.name), ])), arrangement=ArrangementPostAct( symbols=transformers_setup.SYMBOL_TABLE), transformation=transformer_of_instruction.name)
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 arrangement(self) -> ArrangementPostAct: return ArrangementPostAct( tcds_contents=TcdsPopulatorForRelOptionType( self.checked_file_location, DirContents([Dir.empty(self.checked_file_name)])), symbols=FilesMatcherSymbolContext.of_primitive( self.name_of_referenced_symbol, matchers.MatcherThatReportsHardError( self.error_message)).symbol_table, )
def check(self, put: unittest.TestCase, instruction: Instruction, arrangement: ArrangementPostAct, expectation: MultiSourceExpectation): put.assertIsInstance(instruction, AssertPhaseInstruction, 'instruction type') assert isinstance(instruction, AssertPhaseInstruction) # Type info for IDE expectation.symbol_usages.apply_with_message(put, instruction.symbol_usages(), 'symbol-usages after parse') execution_checker = ExecutionChecker(put, arrangement.as_arrangement_2(), expectation.execution) execution_checker.check(instruction)
def runTest(self): # ARRANGE # program_with_ref_to_file_in_hds_ds = pgm_args.program( pgm_args.interpret_py_source_file(path_arguments.RelOptPathArgument('non-existing-file', RelOptionType.REL_HDS_CASE)) ) arguments = po_ab.from_program(program_with_ref_to_file_in_hds_ds, matcher_arguments.emptiness_matcher()) # ACT & ASSERT # self._check(arguments, ArrangementPostAct(), Expectation(validation_pre_sds=asrt_svh.is_validation_error()))
def runTest(self): # ARRANGE # program_with_ref_to_file_in_hds_ds = pgm_args.program( pgm_args.interpret_py_source_file(path_arguments.RelOptPathArgument('non-existing-file', RelOptionType.REL_ACT)) ) arguments = po_ab.from_program(program_with_ref_to_file_in_hds_ds, matcher_arguments.emptiness_matcher()) # ACT & ASSERT # self._check(arguments, ArrangementPostAct(), Expectation( main_result=asrt_pfh.is_hard_error__with_arbitrary_message()) )
def test_invalid_arguments_without_symbol_references(self): test_cases = [ ' {op} a'.format(op=comparators.EQ.name), '{op} 1.5'.format(op=comparators.GT.name), ] for condition_str in test_cases: with self.subTest(msg=condition_str): instr_arg = self._conf().arguments_constructor.apply( condition_str) for source in equivalent_source_variants__with_source_check__consume_last_line( self, instr_arg): self._check( source, ArrangementPostAct(), Expectation( validation_pre_sds=svh_asrt.is_validation_error(), symbol_usages=asrt.is_empty_sequence, ), )
def runTest(self): program_that_outputs_something = pgm_args.program( pgm_args.interpret_py_source_line( self.configuration.py_source_for_print('some output')), transformation=transformers_setup.DELETE_EVERYTHING_TRANSFORMER. name) result_when_positive = pfh_expectation_type_config( ExpectationType.POSITIVE) self._check_positive_and_negated( result_when_positive, program_that_outputs_something, matcher_arguments.emptiness_matcher(), lambda main_result: Expectation( main_result=main_result, symbol_usages=asrt.matches_sequence([ is_reference_to_string_transformer__usage( transformers_setup.DELETE_EVERYTHING_TRANSFORMER.name), ])), ArrangementPostAct(symbols=transformers_setup.SYMBOL_TABLE))
def _check_positive_and_negated( self, expectation_of_positive: ExpectationTypeConfigForPfh, program: ArgumentElements, contents_matcher: List[WithToString], mk_expectation: Callable[[Assertion[PassOrFailOrHardError]], Expectation], arrangement: ArrangementPostAct = ArrangementPostAct(), transformation: WithToString = None): for case in expectation_of_positive.cases(): matcher_for_case = matcher_arguments.matcher_for_expectation_type( case.expectation_type, contents_matcher) arguments = args.from_program(program, matcher_for_case, transformation) with self.subTest(case.expectation_type): self._check(arguments, arrangement, mk_expectation(case.main_result_assertion))
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 ArrangementPostAct( pre_contents_population_action=pre_contents_population_action, hds_contents=hds_contents, sds_contents=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 runTest(self): # ARRANGE # error_message = 'error message from file matcher' file_matcher_that_raises_hard_error = FileMatcherSymbolContext.of_primitive( 'file_matcher_that_raises_hard_error', matchers.MatcherThatReportsHardError(error_message) ) path_relativity = conf_rel_sds(RelSdsOptionType.REL_ACT) checked_file = File.empty('checked-file.txt') argument = args.CompleteInstructionArg( ExpectationType.POSITIVE, path_relativity.path_argument_of_rel_name(checked_file.name), fm_args.SymbolReference(file_matcher_that_raises_hard_error.name)) # ACT & ASSERT # CHECKER.check( self, remaining_source(str(argument)), ArrangementPostAct( symbols=file_matcher_that_raises_hard_error.symbol_table, sds_contents=path_relativity.populator_for_relativity_option_root__sds( DirContents([checked_file]) ) ), instruction_check.expectation( main_result=pfh_assertions.is_hard_error( asrt_text_doc.rendered_text_matches(asrt_str.contains(error_message)) ), symbol_usages=asrt.matches_sequence([ file_matcher_that_raises_hard_error.reference_assertion ]) ))
def check_rel_opt_variants_with_same_result_for_every_expectation_type( self, make_instruction_arguments: InstructionArgumentsVariantConstructor, main_result: Assertion, contents_of_relativity_option_root: DirContents = empty_dir_contents(), following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()): for rel_opt_config in self.accepted_rel_opt_configurations: for expectation_type_of_test_case in ExpectationType: etc = pfh_expectation_type_config( expectation_type_of_test_case) instruction_arguments = make_instruction_arguments.apply( etc, rel_opt_config) instruction_source = remaining_source(instruction_arguments) with self.put.subTest( expectation_type=etc.expectation_type.name, arguments=instruction_arguments): instruction_check.check( self.put, self.parser, instruction_source, ArrangementPostAct( pre_contents_population_action= MAKE_CWD_OUTSIDE_OF_EVERY_REL_OPT_DIR, tcds_contents=rel_opt_config. populator_for_relativity_option_root( contents_of_relativity_option_root), symbols=_symbol_table_of(rel_opt_config.symbols, following_symbols_setup), ), Expectation( main_result=main_result, symbol_usages=asrt.matches_sequence( rel_opt_config.symbols. usage_expectation_assertions() + following_symbols_setup.expected_usages_list)))
def runTest(self): # ARRANGE # for failing_file_matcher_case in failing_validation_cases__svh(): failing_symbol_context = failing_file_matcher_case.value.symbol_context argument = args.CompleteInstructionArg( ExpectationType.POSITIVE, path_argument('ignored-file'), fm_args.SymbolReference(failing_symbol_context.name)) with self.subTest(failing_file_matcher_case.name): # ACT & ASSERT # CHECKER.check( self, remaining_source(str(argument)), ArrangementPostAct( symbols=failing_symbol_context.symbol_table, ), instruction_check.expectation( validation=failing_file_matcher_case.value.expectation, symbol_usages=failing_symbol_context.references_assertion ))
def arrangement_with_timeout(self, timeout_in_seconds: int): return ArrangementPostAct( process_execution_settings=proc_exe_env_for_test( timeout_in_seconds=timeout_in_seconds))