def runTest(self): # ARRANGE # cases = [ NameAndValue( 'pre sds', ( RelOptionType.REL_HDS_CASE, ValidationAssertions.pre_sds_fails__w_any_msg(), ), ), NameAndValue( 'post sds', ( RelOptionType.REL_ACT, ValidationAssertions.post_sds_fails__w_any_msg(), ), ), ] for case in cases: with self.subTest(case.name): CHECKER.check__w_source_variants( self, command_line( 'program', program_arguments.existing_path( path_arguments.RelOptPathArgument('name', case.value[0]), ) ).as_str, Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( validation=case.value[1], ), )
def test_string_symbol_reference(self): for other_valid_file_spec_case in OTHER_VALID_FILE_SPECS: for file_name_case in INVALID_FILE_NAMES: file_name_symbol = StringSymbolContext.of_constant( 'FILE_NAME_SYMBOL', file_name_case.value, default_restrictions=asrt_rest.is__string__w_all_indirect_refs_are_strings(), ) file_name_abs_stx = file_name_symbol.abstract_syntax for file_spec_case in file_type_and_contents_variants(file_name_abs_stx): integration_check.CHECKER.check__abs_stx__layout__std_source_variants( self, LiteralFilesSourceAbsStx(other_valid_file_spec_case.value + [file_spec_case.value]), models.empty(), arrangement_wo_tcds( symbols=file_name_symbol.symbol_table ), MultiSourceExpectation( symbol_references=file_name_symbol.references_assertion, execution=ExecutionExpectation( validation=ValidationAssertions.pre_sds_fails__w_any_msg() ) ), sub_test_identifiers={ 'file-name': file_name_case.name, 'type-and-contents': file_spec_case.name, 'other-valid-file-spec': other_valid_file_spec_case.name, } )
def failing_integer_validation_cases(symbol_in_integer_name: str = 'symbol_in_integer' ) -> Sequence[IntegerValidationCase]: non_int_string_symbol = StringSymbolContext.of_constant( symbol_in_integer_name, 'tre' ) non_iterable_string_symbol = StringSymbolContext.of_constant( symbol_in_integer_name, '1' ) constant_string_cases = [ IntegerValidationCase('failing validation/pre sds: ' + expr_str, expr_str, [], [], validation.PRE_SDS_FAILURE_EXPECTATION, validation.ValidationAssertions.pre_sds_fails__w_any_msg(), ) for expr_str in _PRE_SDS_VALIDATION_FAILURE__CONSTANT_STRINGS ] string_with_symbol_cases = [ IntegerValidationCase('failing validation/pre sds: non-int string ref', symbol_reference_syntax_for_name(non_int_string_symbol.name), [non_int_string_symbol], [is_reference_to_symbol_in_expression(non_int_string_symbol.name)], validation.PRE_SDS_FAILURE_EXPECTATION, ValidationAssertions.pre_sds_fails__w_any_msg(), ), IntegerValidationCase('failing validation/pre sds: non-iterable string ref', 'len({})'.format(symbol_reference_syntax_for_name(non_iterable_string_symbol.name)), [non_iterable_string_symbol], [is_reference_to_symbol_in_expression(non_iterable_string_symbol.name)], validation.PRE_SDS_FAILURE_EXPECTATION, ValidationAssertions.pre_sds_fails__w_any_msg(), ), ] return constant_string_cases + string_with_symbol_cases
def runTest(self): for value_case in INVALID_INT_VALUES: CHECKER.check__abs_stx__layout_and_source_variants( self, InstructionArgumentsAbsStx.of_int( StringLiteralAbsStx(value_case)), Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.pre_sds_fails__w_any_msg( )), sub_test_identifiers={'value_case': value_case}, )
def dir_partition_cases_for_validation(dst_path_symbol_name: str, ) -> Sequence[NArrEx[RelativityOptionConfiguration, ValidationAssertions]]: return [ NArrEx( DirectoryStructurePartition.HDS.name, _relativity_conf_for_symbol(dst_path_symbol_name, RelOptionType.REL_HDS_CASE), ValidationAssertions.pre_sds_fails__w_any_msg(), ), NArrEx( DirectoryStructurePartition.NON_HDS.name, _relativity_conf_for_symbol(dst_path_symbol_name, RelOptionType.REL_ACT), ValidationAssertions.post_sds_fails__w_any_msg(), ), ]
def _expect_validation_error_and_symbol_usages( relativity_option_conf: rel_opt_conf.RelativityOptionConfiguration, expected_symbol_usage: list) -> MultiSourceExpectation: expected_symbol_usages_assertion = asrt.matches_sequence( expected_symbol_usage) if relativity_option_conf.exists_pre_sds: return MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.pre_sds_fails__w_any_msg(), symbol_usages=expected_symbol_usages_assertion, ) else: return MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.post_sds_fails__w_any_msg(), symbol_usages=expected_symbol_usages_assertion, )
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): for maybe_with_transformer_option in TRANSFORMER_OPTION_ALTERNATIVES: for maybe_full_match in FULL_MATCH_OPTION_ALTERNATIVES: with self.subTest(maybe_with_transformer_option=maybe_with_transformer_option, maybe_full_match=maybe_full_match): self._check_with_source_variants( test_configuration.arguments_for( args('{maybe_with_transformer_option} {maybe_not} {matches} {maybe_full_match} **', maybe_with_transformer_option=maybe_with_transformer_option, maybe_full_match=maybe_full_match, maybe_not=maybe_not.nothing__if_positive__not_option__if_negative)), model_constructor.empty(self), Arrangement(), Expectation( execution=ExecutionExpectation( validation=ValidationAssertions.pre_sds_fails__w_any_msg() ), ) )
def test_ERROR_when_file_does_not_exist__without_explicit_destination__hds(self): for execution_checker in _EXECUTION_CHECKERS: for relativity_option in source_relativity_options__hds(): with self.subTest(parser=execution_checker.name, relativity=relativity_option.test_case_description): execution_checker.value.check( self, args.copy( relativity_option.path_argument_of_rel_name('source-that-do-not-exist') ).as_remaining_source, Arrangement.phase_agnostic( tcds=TcdsArrangement(), symbols=relativity_option.symbols.in_arrangement(), ), Expectation.phase_agnostic_2( validation=ValidationAssertions.pre_sds_fails__w_any_msg(), symbol_usages=relativity_option.symbols.usages_expectation(), ), )
def failing_regex_validation_cases( symbol_in_regex_name: str = 'symbol_in_regex' ) -> Sequence[RegexValidationCase]: post_sds_path = PathDdvSymbolContext.of_no_suffix(symbol_in_regex_name, RelOptionType.REL_ACT) return [ RegexValidationCase( 'failing validation/pre sds', '*', [], [], ValidationAssertions.pre_sds_fails__w_any_msg(), ), RegexValidationCase( 'failing validation/post sds', '*' + symbol_reference_syntax_for_name(post_sds_path.name), [post_sds_path], [is_reference_to__regex_string_part(post_sds_path.name)], ValidationAssertions.post_sds_fails__w_any_msg(), ), ]
def test_string_literal(self): for other_valid_file_spec_case in OTHER_VALID_FILE_SPECS: for file_name_case in INVALID_FILE_NAMES: file_name_abs_stx = StringLiteralAbsStx(file_name_case.value, QuoteType.HARD) for file_spec_case in file_type_and_contents_variants(file_name_abs_stx): integration_check.CHECKER.check__abs_stx__layout__std_source_variants( self, LiteralFilesSourceAbsStx(other_valid_file_spec_case.value + [file_spec_case.value]), models.empty(), arrangement_wo_tcds(), MultiSourceExpectation( execution=ExecutionExpectation( validation=ValidationAssertions.pre_sds_fails__w_any_msg() ) ), sub_test_identifiers={ 'file-name': file_name_case.name, 'type-and-contents': file_spec_case.name, 'other-valid-file-spec': other_valid_file_spec_case.name, } )
def runTest(self): # ARRANGE # cases = [ NArrEx( 'pre SDS validation failure SHOULD cause validation error', RelOptionType.REL_HDS_CASE, MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.pre_sds_fails__w_any_msg() ), ), NArrEx( 'post SDS validation failure SHOULD cause main error', RelOptionType.REL_ACT, MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.post_sds_fails__w_any_msg() ), ), ] for case in cases: program_with_ref_to_non_existing_file = program_abs_stx.ProgramOfExecutableFileCommandLineAbsStx( path_abs_stx.RelOptPathAbsStx(case.arrangement, 'non-existing-file') ) instruction_syntax = instr_abs_stx.create_w_explicit_contents( path_abs_stx.DefaultRelPathAbsStx('dst-file'), string_source_abs_stx.StringSourceOfProgramAbsStx(ProcOutputFile.STDOUT, program_with_ref_to_non_existing_file, ignore_exit_code=False) ) # ACT & ASSERT # for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) with self.subTest(phase_is_after_act=phase_is_after_act, step=case.name): checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic(), case.expectation, )
def _expect_failure_in( step_of_expected_failure: Step) -> MultiSourceExpectation: symbol_usages_expectation = asrt.is_sequence_of( asrt.is_instance(SymbolReference)) if step_of_expected_failure is Step.VALIDATE_PRE_SDS: return MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.pre_sds_fails__w_any_msg(), symbol_usages=symbol_usages_expectation, ) elif step_of_expected_failure is Step.VALIDATE_POST_SDS: return MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.post_sds_fails__w_any_msg(), symbol_usages=symbol_usages_expectation, ) elif step_of_expected_failure is Step.MAIN: return MultiSourceExpectation.phase_agnostic( main_result=IS_FAILURE, symbol_usages=symbol_usages_expectation, ) else: raise ValueError('Unknown {}: {}'.format(Step, step_of_expected_failure))
def test_non_transformer_components(self): # ARRANGE # relativity_cases = [ NArrEx( 'pre SDS validation failure', RelOptionType.REL_HDS_CASE, ValidationAssertions.pre_sds_fails__w_any_msg(), ), NArrEx( 'post SDS validation failure', RelOptionType.REL_ACT, ValidationAssertions.post_sds_fails__w_any_msg(), ), ] def make_pgm_w_ref_to_executable_file( relativity: RelOptionType) -> ProgramAbsStx: return program_abs_stx.ProgramOfExecutableFileCommandLineAbsStx( path_abs_stx.RelOptPathAbsStx(relativity, 'non-existing-file')) def make_pgm_w_ref_to_stdin_file( relativity: RelOptionType) -> ProgramAbsStx: return program_abs_stx.FullProgramAbsStx( program_abs_stx.ProgramOfSystemCommandLineAbsStx.of_str( 'a-system-command'), stdin=string_source_abs_stx.StringSourceOfFileAbsStx( path_abs_stx.RelOptPathAbsStx(relativity, 'non-existing-file'))) def make_pgm_w_ref_to_argument_file( relativity: RelOptionType) -> ProgramAbsStx: return program_abs_stx.ProgramOfSystemCommandLineAbsStx.of_str( 'a-system-command', [ ArgumentOfExistingPathAbsStx( path_abs_stx.RelOptPathAbsStx(relativity, 'non-existing-file')) ]) program_cases = [ NameAndValue( 'missing executable file', make_pgm_w_ref_to_executable_file, ), NameAndValue( 'missing argument file', make_pgm_w_ref_to_argument_file, ), NameAndValue( 'missing stdin file', make_pgm_w_ref_to_stdin_file, ), ] for relativity_case in relativity_cases: for program_case in program_cases: string_source_syntax = string_source_abs_stx.StringSourceOfProgramAbsStx( ProcOutputFile.STDOUT, program_case.value(relativity_case.arrangement), ignore_exit_code=False, ) # ACT & ASSERT # checker = integration_check.checker__w_arbitrary_file_relativities( ) with self.subTest(step=relativity_case.name, program=program_case.name): checker.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_full_line_expr_parse__s__nsc, OptionallyOnNewLine(string_source_syntax), arrangement_w_tcds(), MultiSourceExpectation(execution=ExecutionExpectation( validation=relativity_case.expectation)))
def test_validation_pre_sds_SHOULD_fail_WHEN_source_is_not_an_existing_file_rel_hds(self): self._check_of_invalid_src_file(RelOptionType.REL_HDS_CASE, ValidationAssertions.pre_sds_fails__w_any_msg())
def test_non_existing_executable(self): EXECUTION_CHECKER.check__w_source_variants( self, '/not/an/executable/program', Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.pre_sds_fails__w_any_msg()))