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 runTest(self): for line_filter_case in LINE_FILTER_CASES: for preserve_new_lines in [False, True]: for regex_case in failing_regex_validation_cases(): all_symbols = line_filter_case.value.symbols + regex_case.symbols source = ReplaceRegexAbsStx.of_str( regex_case.regex_string, 'arbitrary_replacement', preserve_new_lines=preserve_new_lines, lines_filter=line_filter_case.value.syntax, ) # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check__abs_stx__layout__std_source_variants( self, source, model_constructor.arbitrary(self), arrangement_w_tcds( symbols=SymbolContext.symbol_table_of_contexts( all_symbols)), MultiSourceExpectation( symbol_references=line_filter_case.value. references_assertion__followed_by( regex_case.reference_assertions), execution=ExecutionExpectation( validation=regex_case.expectation), primitive=prim_asrt__constant( is_identity_transformer(False)), ), sub_test_identifiers={ 'regex_case': regex_case.case_name, 'preserve_new_lines': preserve_new_lines, 'lines_filtering': line_filter_case.name, })
def runTest(self): # ARRANGE # for validation_case in validation_cases.failing_validation_cases(): for preserve_new_lines in [False, True]: syntax = ReplaceRegexAbsStx.of_str( 'valid_regex', 'valid_replacement', preserve_new_lines=preserve_new_lines, lines_filter=validation_case.value.matcher_abs_stx, ) line_matcher_symbol_context = validation_case.value.symbol_context # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check__abs_stx__layout__std_source_variants( self, syntax, model_constructor.arbitrary(self), arrangement_wo_tcds( symbols=line_matcher_symbol_context.symbol_table), MultiSourceExpectation( symbol_references=line_matcher_symbol_context. references_assertion, execution=ExecutionExpectation( validation=validation_case.value.expectation, )), sub_test_identifiers={ 'preserve_new_lines': preserve_new_lines, 'validation': validation_case.name, })
def runTest(self): after_lhs_expression = logic.AND_OPERATOR_NAME + ' after bin op' integer_matcher = IntegerMatcherSymbolContextOfPrimitiveConstant( 'MATCHER_SYMBOL', True, ) complex_expression = ' '.join( (integer_matcher.name__sym_ref_syntax, after_lhs_expression)) integration_check.CHECKER__PARSE_SIMPLE.check( self, args.NumLines(complex_expression).as_remaining_source, model_constructor.arbitrary(self), arrangement_w_tcds(symbols=integer_matcher.symbol_table, ), Expectation( ParseExpectation( source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=after_lhs_expression, ), symbol_references=integer_matcher.references_assertion, ), ExecutionExpectation( main_result=asrt_matching_result.matches_value( integer_matcher.result_value)), ), )
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), ]), ), model_constructor.arbitrary(self), test_cases.exit_code_exe_cases( program_symbol_name, exit_code_symbol_name, ), )
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): cases = [ NameAndValue( 'just space', ' ', ), NameAndValue( 'just space, w new-line', ' \n ', ), NameAndValue( 'just a separator', '{SEPARATOR}', ), NameAndValue( 'just two separators', '{SEPARATOR}{SEPARATOR}', ), NameAndValue( 'too many separators 1', '{SEPARATOR}1{SEPARATOR}', ), NameAndValue( 'too many separators 2', '1{SEPARATOR}{SEPARATOR}', ), NameAndValue( 'too many separators 3', '1{SEPARATOR}2{SEPARATOR}', ), ] for case in cases: with self.subTest(case.name, expr=case.value): range_expr_symbol = StringSymbolContext.of_constant( 'RANGE_SYMBOL', case.value, default_restrictions= IS_RANGE_EXPR_STR_REFERENCE_RESTRICTIONS, ) arguments = args.filter_line_nums( range_args.CustomRange( range_expr_symbol.name__sym_ref_syntax)) integration_check.CHECKER__PARSE_SIMPLE.check( self, arguments.as_remaining_source, model_constructor.arbitrary(self), arrangement_wo_tcds( symbols=range_expr_symbol.symbol_table, ), Expectation( ParseExpectation(symbol_references=range_expr_symbol. references_assertion, ), ExecutionExpectation(validation=ValidationAssertions. pre_sds_fails__w_any_msg(), ), ))
def runTest(self): failure_message = 'failure' failing_validation_result = asrt_validation.new_single_string_text_for_test( failure_message) line_matcher_symbol_name = 'line_matcher_with_failing_validation' asserted_symbol_references = asrt.matches_sequence( [is_reference_to_line_matcher(line_matcher_symbol_name)]) validation_cases = [ NEA('failure pre sds', expected=Expectation( ParseExpectation( symbol_references=asserted_symbol_references, ), ExecutionExpectation( validation=ValidationAssertions.pre_sds_fails( asrt.equals(failure_message)), ), ), actual=ConstantDdvValidator( pre_sds_result=failing_validation_result)), NEA('failure post sds', expected=Expectation( ParseExpectation( symbol_references=asserted_symbol_references, ), ExecutionExpectation(validation=ValidationAssertions. post_sds_fails__w_any_msg(), ), ), actual=ConstantDdvValidator( post_sds_result=failing_validation_result)), ] for case in validation_cases: symbols = LineMatcherSymbolContext.of_sdv( line_matcher_symbol_name, successful_matcher_with_validation(case.actual)).symbol_table for quantifier in Quantifier: arguments_constructor = arguments_building.ImplicitActualFileArgumentsConstructor( CommonArgumentsConstructor(), arguments_building. LineMatchesAssertionArgumentsConstructor( quantifier, line_matcher_symbol_name)) for expectation_type in ExpectationType: arguments = arguments_constructor.apply(expectation_type) source = test_configuration.arguments_for( arguments).as_remaining_source with self.subTest(case=case.name, expectation_type=expectation_type, quantifier=quantifier): self._check(source=source, model=model_constructor.arbitrary(self), arrangement=Arrangement(symbols=symbols), expectation=case.expected)
def runTest(self): # ARRANGE & ACT && ASSERT # integration_check.CHECKER__PARSE_FULL.check( self, args.RunProgram( program_args.system_program_argument_elements( NON_EXISTING_SYSTEM_PROGRAM)).as_remaining_source, model_constructor.arbitrary(self), arrangement_w_tcds(), Expectation( ParseExpectation(source=asrt_source.is_at_end_of_line(1), ), ExecutionExpectation( is_hard_error=asrt_text_doc.is_any_text()), ), )
def runTest(self): for case in failing_integer_validation_cases(): with self.subTest(invalid_value=case.case_name): args_variant_constructor = InstructionArgumentsVariantConstructor( operator=comparators.NE.name, operand=case.integer_expr_string) self._check_single_expression_type( args_variant_constructor, ExpectationType.POSITIVE, model_constructor.arbitrary(self), arrangement=Arrangement(symbols=case.symbol_table), expectation=Expectation( ParseExpectation(symbol_references=case. symbol_references_expectation, ), ExecutionExpectation(validation=case.assertions, ), ))
def runTest(self): invalid_int_expr = range_args.SingleLineRange('1.5') valid_int_expr = range_args.SingleLineRange('1') range_expression_cases = [ [invalid_int_expr, valid_int_expr, valid_int_expr], [valid_int_expr, invalid_int_expr, valid_int_expr], [valid_int_expr, valid_int_expr, invalid_int_expr], ] for range_expressions in range_expression_cases: with self.subTest([str(r) for r in range_expressions]): integration_check.CHECKER__PARSE_SIMPLE.check( self, args.filter_line_nums__multi( range_expressions).as_remaining_source, model_constructor.arbitrary(self), arrangement_wo_tcds(), Expectation( ParseExpectation(), ExecutionExpectation(validation=ValidationAssertions. pre_sds_fails__w_any_msg(), ), ))
def test_failure_to_execute_program(self): # ARRANGE # 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( self, args.syntax_for_run( program_args.system_program_argument_elements( NON_EXISTING_SYSTEM_PROGRAM), ignore_exit_code=with_ignored_exit_code, ).as_remaining_source, model_constructor.arbitrary(self), arrangement_w_tcds(), Expectation( ParseExpectation( source=asrt_source.is_at_end_of_line(1), ), ExecutionExpectation( is_hard_error=asrt_text_doc.is_any_text()), ), )
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 # 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)), ), model_constructor.arbitrary(self), [ test_cases.environment_exe_case(environment_case, program_symbol_name) for environment_case in environment_cases ], )
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 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 test__lower_and_upper_limit__invalid_lower(self): for case in failing_integer_validation_cases(): range_arg = range_args.LowerAndUpperLimitRange( case.integer_expr_string, '1') with self.subTest(invalid_value=case.case_name): self._check(case, range_arg) def test__lower_and_upper_limit__invalid_upper(self): for case in failing_integer_validation_cases(): range_arg = range_args.LowerAndUpperLimitRange( '1', case.integer_expr_string) with self.subTest(invalid_value=case.case_name): self._check(case, range_arg) def _check(self, case: IntegerValidationCase, range_arg: range_args.Range): integration_check.CHECKER__PARSE_SIMPLE.check( self, args.filter_line_nums(range_arg).as_remaining_source, model_constructor.arbitrary(self), arrangement_wo_tcds(symbols=case.symbol_table, ), Expectation( ParseExpectation( symbol_references=case.symbol_references_expectation, ), ExecutionExpectation(validation=case.assertions, ), )) if __name__ == '__main__': unittest.TextTestRunner().run(suite())