示例#1
0
 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],
                 ),
             )
示例#2
0
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(),
        ),
    ]
示例#3
0
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,
        )
示例#4
0
 def phase_agnostic_2(
         validation: ValidationAssertions = ValidationAssertions.all_passes(),
         main_result: Assertion[T] = asrt.anything_goes(),
         main_raises_hard_error: bool = False,
         symbol_usages: Assertion[Sequence[SymbolUsage]] = asrt.is_empty_sequence,
         symbols_after_main: Assertion[SymbolTable] = asrt.anything_goes(),
         main_side_effects_on_files: TcdsExpectation = TcdsExpectation(),
         main_side_effect_on_environment_variables: Assertion[Dict[str, str]] = asrt.anything_goes(),
         proc_exe_settings: Assertion[ProcessExecutionSettings]
         = asrt.is_instance(ProcessExecutionSettings),
         instruction_settings: Assertion[InstructionSettings]
         = asrt.is_instance(InstructionSettings),
         instruction_environment:
         Assertion[InstructionApplicationEnvironment] = asrt.anything_goes(),
 ) -> 'MultiSourceExpectation[T]':
     return MultiSourceExpectation.phase_agnostic(
         validation,
         main_result,
         main_raises_hard_error,
         symbol_usages,
         symbols_after_main,
         main_side_effects_on_files.sds,
         main_side_effects_on_files.tcds,
         main_side_effects_on_files.case_home,
         main_side_effect_on_environment_variables,
         proc_exe_settings,
         instruction_settings,
         instruction_environment,
     )
示例#5
0
 def setup_phase_aware(
         validation: ValidationAssertions = ValidationAssertions.all_passes(),
         main_result: Assertion[T] = asrt.anything_goes(),
         main_raises_hard_error: bool = False,
         symbol_usages: Assertion[Sequence[SymbolUsage]] = asrt.is_empty_sequence,
         symbols_after_main: Assertion[SymbolTable] = asrt.anything_goes(),
         main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(),
         side_effects_on_tcds: Assertion[TestCaseDs] = asrt.anything_goes(),
         side_effects_on_hds: Assertion[pathlib.Path] = asrt.anything_goes(),
         main_side_effect_on_environment_variables: Assertion[Dict[str, str]] = asrt.anything_goes(),
         proc_exe_settings: Assertion[ProcessExecutionSettings]
         = asrt.is_instance(ProcessExecutionSettings),
         instruction_settings: Assertion[InstructionSettings]
         = asrt.is_instance(InstructionSettings),
         instruction_environment:
         Assertion[InstructionApplicationEnvironment] = asrt.anything_goes(),
         setup_settings: Assertion[Optional[SettingsBuilderAssertionModel]] = asrt.is_none,
 ) -> 'MultiSourceExpectation[T]':
     return MultiSourceExpectation(
         MainMethodType.SETUP_PHASE_AWARE,
         validation,
         main_result,
         main_raises_hard_error,
         symbol_usages,
         symbols_after_main,
         main_side_effects_on_sds,
         side_effects_on_tcds,
         side_effects_on_hds,
         main_side_effect_on_environment_variables,
         proc_exe_settings,
         instruction_settings,
         instruction_environment,
         setup_settings,
     )
示例#6
0
 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,
                     }
                 )
示例#7
0
 def phase_agnostic(
         validation: ValidationAssertions = ValidationAssertions.all_passes(),
         main_result: Assertion[T] = asrt.anything_goes(),
         main_raises_hard_error: bool = False,
         main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(),
         side_effects_on_tcds: Assertion[TestCaseDs] = asrt.anything_goes(),
         side_effects_on_hds: Assertion[pathlib.Path] = asrt.anything_goes(),
         main_side_effect_on_environment_variables: Assertion[Dict[str, str]] = asrt.anything_goes(),
         proc_exe_settings: Assertion[ProcessExecutionSettings]
         = asrt.is_instance(ProcessExecutionSettings),
         instruction_settings: Assertion[InstructionSettings]
         = asrt.is_instance(InstructionSettings),
         instruction_environment:
         Assertion[InstructionApplicationEnvironment] = asrt.anything_goes(),
 ) -> 'ExecutionExpectation[T]':
     return ExecutionExpectation(
         MainMethodType.PHASE_AGNOSTIC,
         validation,
         main_result,
         main_raises_hard_error,
         main_side_effects_on_sds,
         side_effects_on_tcds,
         side_effects_on_hds,
         main_side_effect_on_environment_variables,
         proc_exe_settings,
         instruction_settings,
         instruction_environment,
         asrt.is_none,
     )
示例#8
0
 def __init__(self,
              main_method_type: MainMethodType,
              validation: ValidationAssertions = ValidationAssertions.all_passes(),
              main_result: Assertion[T] = asrt.anything_goes(),
              main_raises_hard_error: bool = False,
              main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(),
              side_effects_on_tcds: Assertion[TestCaseDs] = asrt.anything_goes(),
              side_effects_on_hds: Assertion[pathlib.Path] = asrt.anything_goes(),
              main_side_effect_on_environment_variables: Assertion[Dict[str, str]] = asrt.anything_goes(),
              proc_exe_settings: Assertion[ProcessExecutionSettings]
              = asrt.is_instance(ProcessExecutionSettings),
              instruction_settings: Assertion[InstructionSettings]
              = asrt.is_instance(InstructionSettings),
              instruction_environment:
              Assertion[InstructionApplicationEnvironment] = asrt.anything_goes(),
              setup_settings: Assertion[Optional[SettingsBuilderAssertionModel]] = asrt.is_none,
              ):
     self.main_method_type = main_method_type
     self.validation = validation
     self.main_result = main_result
     self.main_raises_hard_error = main_raises_hard_error
     self.proc_exe_settings = proc_exe_settings
     self.instruction_settings = instruction_settings
     self.main_side_effects_on_sds = main_side_effects_on_sds
     self.side_effects_on_tcds = side_effects_on_tcds
     self.side_effects_on_hds = side_effects_on_hds
     self.main_side_effect_on_environment_variables = main_side_effect_on_environment_variables
     self.instruction_application_environment = instruction_environment
     self.setup_settings = setup_settings
示例#9
0
 def test_fail_due_to_unexpected_result_from__validate_post_sds(self):
     self._check_source_and_exe_variants__failing_assertions(
         PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
         Arrangement.phase_agnostic(),
         MultiSourceExpectation.phase_agnostic(
             validation=ValidationAssertions.post_sds_fails()
         ),
     )
示例#10
0
 def __init__(
     self,
     validation: ValidationAssertions = ValidationAssertions.all_passes(),
     main_result: Assertion[OUTPUT] = asrt.anything_goes(),
     is_hard_error: Optional[Assertion[TextRenderer]] = None,
 ):
     self.validation = validation
     self.main_result = main_result
     self.is_hard_error = is_hard_error
示例#11
0
 def test_fail_due_to_unexpected_result_from_post_sds_validation(self):
     self._check_raises_test_error__single_and_multi(
         ConstantParser(_MATCHER_THAT_MATCHES),
         Expectation(
             execution=ExecutionExpectation(
                 validation=ValidationAssertions.post_sds_fails(),
             ),
         )
     )
示例#12
0
    def test_quoted_tokens(self):
        # ARRANGE #
        regex_str = '.* regex'

        matches_for_case_sensitive = [' regex', 'before regex after']

        option_cases = [
            option_case_for_no_option(
                _AssertPattern(regex_str,
                               matching_strings=matches_for_case_sensitive,
                               non_matching_string=' REGEX')
            ),

            option_case_for_ignore_case(
                _AssertPattern(regex_str,
                               matching_strings=matches_for_case_insensitive(matches_for_case_sensitive),
                               non_matching_string='regex')
            ),
        ]

        text_on_following_line = 'text on following line'

        source_cases = [
            SourceCase(
                'soft quotes',

                source=
                Arguments('{regex}'.format(
                    regex=surrounded_by_soft_quotes(regex_str),
                )),

                source_assertion=
                assert_token_stream(is_null=asrt.is_true),
            ),
            SourceCase(
                'hard quotes, and text on following line',

                source=
                Arguments('{regex}'.format(
                    regex=surrounded_by_hard_quotes(regex_str),
                ),
                    following_lines=[text_on_following_line]),

                source_assertion=
                assert_token_stream(
                    remaining_source=asrt.equals('\n' + text_on_following_line)),
            ),
        ]
        # ACT & ASSERT #
        check_many(self,
                   Arrangement(),
                   source_cases,
                   ExpectationExceptPattern(
                       validation=ValidationAssertions.all_passes()
                   ),
                   option_cases,
                   )
示例#13
0
    def test_symbol_references(self):
        # ARRANGE #
        star_string_symbol = StringSymbolContext.of_constant('STAR_SYMBOL', '* ')

        regex_str = '.* regex'

        regex_arg_str = '.{star}regex'.format(
            star=symbol_reference_syntax_for_name(star_string_symbol.name),
        )

        matches_for_case_sensitive = [' regex', 'before regex after']

        option_cases = [
            option_case_for_no_option(
                _AssertPattern(regex_str,
                               matching_strings=matches_for_case_sensitive,
                               non_matching_string=' REGEX')
            ),

            option_case_for_ignore_case(
                _AssertPattern(regex_str,
                               matching_strings=matches_for_case_insensitive(matches_for_case_sensitive),
                               non_matching_string='regex')
            ),
        ]

        source_cases = [
            SourceCase('single invalid star',
                       Arguments(regex_arg_str),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
            SourceCase('invalid stars at start of regex',
                       Arguments(surrounded_by_soft_quotes(regex_arg_str)),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
        ]

        arrangement = Arrangement(
            symbols=star_string_symbol.symbol_table
        )

        expectation = ExpectationExceptPattern(
            references=asrt.matches_sequence([
                is_reference_to__regex_string_part(star_string_symbol.name),
            ]),
            validation=ValidationAssertions.all_passes(),
        )

        # ACT & ASSERT #

        check_many(self,
                   arrangement,
                   source_cases,
                   expectation,
                   option_cases,
                   )
示例#14
0
 def __init__(self,
              pattern: Assertion[Pattern] = asrt.anything_goes(),
              token_stream: Assertion[TokenStream] = asrt.anything_goes(),
              validation: ValidationAssertions = ValidationAssertions.all_passes(),
              references: Assertion[Sequence[SymbolReference]] = asrt.is_empty_sequence,
              ):
     self.pattern = pattern
     self.references = references
     self.validation = validation
     self.token_stream = token_stream
示例#15
0
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
示例#16
0
 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},
         )
示例#17
0
    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)
示例#18
0
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(),
        ),
    ]
示例#19
0
 def __init__(
     self,
     symbol_name: str,
     actual: ValidationActual,
 ):
     self._symbol_context = StringSourceSymbolContext.of_sdv(
         symbol_name,
         sdvs.StringSourceSdvConstantTestImpl(
             ddvs.StringSourceDdvWoResolvingTestImpl(
                 ddv_validators.constant(actual))))
     self.syntax = self._symbol_context.abstract_syntax
     self._expectation = validation.Expectation.corresponding_to(actual)
     self._assertions = ValidationAssertions.corresponding_to(actual)
示例#20
0
 def of_exe(
     validation: ValidationAssertions = ValidationAssertions.all_passes(),
     main_result: Assertion[OUTPUT] = asrt.anything_goes(),
     is_hard_error: Optional[Assertion[TextRenderer]] = None,
 ) -> 'PrimAndExeExpectation[PRIMITIVE, OUTPUT]':
     return PrimAndExeExpectation(
         ExecutionExpectation(
             validation=validation,
             main_result=main_result,
             is_hard_error=is_hard_error,
         ),
         prim_asrt__any,
     )
示例#21
0
 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,
                 )
示例#22
0
    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))
示例#23
0
 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(),
                     ),
                 )
示例#24
0
 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()
                         ),
                     )
                 )
示例#25
0
    def test_SHOULD_match_WHEN_post_sds_validation_fails_expectedly_but_primitive_value_is_unexpected(
            self):
        # ARRANGE #

        sdv_of_actual = RegexSdvConstantTestImpl(
            ARBITRARY_PATTERN,
            value_validator=ConstantDdvValidator(
                post_sds_result=asrt_validation.
                new_single_string_text_for_test('expected failure')),
        )

        assertion_to_check = sut.matches_regex_sdv(
            dir_dependencies=DirDependencies.NONE,
            validation=ValidationAssertions.post_sds_fails(),
            primitive_value=check_of_primitive_value_fails_expectedly,
        )

        # ACT & ASSERT #
        assertion_to_check.apply_without_message(self, sdv_of_actual)
示例#26
0
    def __init__(self,
                 main_method_type: MainMethodType,
                 validation_pre_sds: ValidationResultAssertion = asrt.is_none,
                 validation_post_sds: ValidationResultAssertion = asrt.is_none,
                 main_result: Assertion[T] = asrt.anything_goes(),
                 main_raises_hard_error: bool = False,
                 symbol_usages: Assertion[Sequence[SymbolUsage]] = asrt.is_empty_sequence,
                 symbols_after_main: Assertion[SymbolTable] = asrt.anything_goes(),
                 main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(),
                 side_effects_on_tcds: Assertion[TestCaseDs] = asrt.anything_goes(),
                 side_effects_on_hds: Assertion[pathlib.Path] = asrt.anything_goes(),
                 source: Assertion[ParseSource] = asrt.anything_goes(),
                 main_side_effect_on_environment_variables: Assertion[Dict[str, str]] = asrt.anything_goes(),
                 proc_exe_settings: Assertion[ProcessExecutionSettings]
                 = asrt.is_instance(ProcessExecutionSettings),
                 instruction_settings: Assertion[InstructionSettings]
                 = asrt.is_instance(InstructionSettings),
                 assertion_on_instruction_environment:
                 Assertion[InstructionApplicationEnvironment] = asrt.anything_goes(),
                 setup_settings: Assertion[Optional[SettingsBuilderAssertionModel]] = asrt.is_none,
                 ):
        super().__init__(
            main_method_type,
            ValidationAssertions(validation_pre_sds,
                                 validation_post_sds),
            main_result,
            main_raises_hard_error,

            symbol_usages,
            symbols_after_main,

            main_side_effects_on_sds,
            side_effects_on_tcds,
            side_effects_on_hds,
            main_side_effect_on_environment_variables,

            proc_exe_settings,
            instruction_settings,
            assertion_on_instruction_environment,
            setup_settings,
        )
        self.source = source
示例#27
0
 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,
                     }
                 )
示例#28
0
    def test_symbol_references_with_dir_dependencies(self):
        # ARRANGE #

        path_symbol_name = 'PATH_SYMBOL'

        regex_source_string = (symbol_reference_syntax_for_name(self.STAR_STRING_SYMBOL.name) +
                               symbol_reference_syntax_for_name(path_symbol_name))

        expectation = Expectation(
            references=asrt.matches_sequence([
                is_reference_to__regex_string_part(self.STAR_STRING_SYMBOL.name),
                is_reference_to__regex_string_part(path_symbol_name),
            ]),
            validation=ValidationAssertions.post_sds_fails__w_any_msg(),
            token_stream=assert_token_stream(is_null=asrt.is_true),
        )

        rel_opt_cases = [
            RelOptionType.REL_HDS_CASE,
            RelOptionType.REL_CWD,
            RelOptionType.REL_ACT,
        ]

        for rel_opt in rel_opt_cases:
            path_symbol = PathDdvSymbolContext.of_no_suffix(path_symbol_name, rel_opt)

            arrangement = Arrangement(
                symbols=SymbolContext.symbol_table_of_contexts([
                    self.STAR_STRING_SYMBOL,
                    path_symbol,
                ])
            )

            # ACT & ASSERT #

            self._check(regex_source_string,
                        arrangement,
                        expectation,
                        )
示例#29
0
 def expectation(self) -> ValidationAssertions:
     return ValidationAssertions.corresponding_to(self.actual)
示例#30
0
 def of_expectation(
     expectation: Expectation,
     tcds: TestCaseDs,
 ) -> Assertion[DdvValidator]:
     return DdvValidationAssertion(
         tcds, ValidationAssertions.of_expectation(expectation))