Exemple #1
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,
     )
Exemple #2
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,
     )
Exemple #3
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,
     )
Exemple #4
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
Exemple #5
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
Exemple #6
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,
                   )
Exemple #7
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,
                   )
Exemple #8
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
Exemple #9
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,
     )
Exemple #10
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,
                 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,
                 ):
        super().__init__(
            main_method_type,
            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,
            setup_settings,

        )
        self.symbol_usages = symbol_usages
        self.symbols_after_main = symbols_after_main
Exemple #11
0
 def __init__(self,
              references: Assertion[Sequence[SymbolReference]] = asrt.is_empty_sequence,
              validation: ValidationAssertions = ValidationAssertions.all_passes(),
              ):
     self.references = references
     self.validation = validation
Exemple #12
0
    def test_here_document(self):
        # ARRANGE #
        star_string_symbol = StringSymbolContext.of_constant('STAR_SYMBOL', '*')

        regex_str = '.*'

        regex_source_line = '.' + symbol_reference_syntax_for_name(star_string_symbol.name)

        arrangement = Arrangement(
            symbols=star_string_symbol.symbol_table
        )

        matches_for_case_sensitive = []

        option_cases = [
            option_case_for_no_option(
                _AssertPattern(regex_str + '\n',
                               matching_strings=matches_for_case_sensitive,
                               non_matching_string='missing new line')
            ),

            option_case_for_ignore_case(
                _AssertPattern(regex_str + '\n',
                               matching_strings=matches_for_case_insensitive(matches_for_case_sensitive),
                               non_matching_string='missing new line')
            ),
        ]

        text_on_following_line = 'text on following line'

        here_doc_argument = here_document([regex_source_line])
        source_cases = [
            SourceCase(
                'end of file after HD',
                source=
                here_doc_argument,

                source_assertion=
                assert_token_stream(remaining_part_of_current_line=asrt.equals(''),
                                    remaining_source=asrt.equals('')),
            ),
            SourceCase(
                'followed by more lines',
                source=
                here_doc_argument.followed_by_lines([text_on_following_line]),

                source_assertion=
                assert_token_stream(remaining_part_of_current_line=asrt.equals(''),
                                    remaining_source=asrt.equals('\n' + text_on_following_line)),
            ),
        ]

        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,
                   )
Exemple #13
0
    def test_unquoted_tokens(self):
        # ARRANGE #
        regex_str = 'a.*regex'

        matches_for_case_sensitive = ['aBCregex', 'aBCregex and more']

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

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

        text_on_following_line = 'text on following line'

        def _arg(format_string: str) -> str:
            return format_string.format(
                regex=regex_str)

        source_cases = [
            SourceCase(
                'REG-EX is only source',
                source=
                Arguments(_arg('{regex}')),
                source_assertion=
                assert_token_stream(is_null=asrt.is_true),
            ),
            SourceCase(
                'REG-EX is followed by a token',
                source=
                Arguments(_arg('{regex} following_token')),
                source_assertion=
                assert_token_stream(
                    is_null=asrt.is_false,
                    remaining_part_of_current_line=asrt.equals('following_token')),
            ),
            SourceCase(
                'REG-EX is only element on current line, but followed by more lines',
                source=
                Arguments(_arg('{regex}'),
                          following_lines=[text_on_following_line]),
                source_assertion=
                assert_token_stream(
                    is_null=asrt.is_false,
                    remaining_part_of_current_line=asrt.equals(''),
                    remaining_source=asrt.equals('\n' + text_on_following_line)),
            ),
        ]
        # ACT & ASSERT #
        check_many(self,
                   Arrangement(),
                   source_cases,
                   ExpectationExceptPattern(
                       validation=ValidationAssertions.all_passes()
                   ),
                   option_cases,
                   )