Example #1
0
    def __init__(
            self,
            validation_post_sds: Assertion[svh.SuccessOrValidationErrorOrHardError] =
            svh_assertions.is_success(),

            validation_pre_sds: Assertion[svh.SuccessOrValidationErrorOrHardError] =
            svh_assertions.is_success(),

            main_result: Assertion[pfh.PassOrFailOrHardError] = pfh_assertions.is_pass(),
            symbol_usages: Assertion[Sequence[SymbolUsage]] = asrt.is_empty_sequence,
            main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(),
            main_side_effects_on_tcds: Assertion[TestCaseDs] = asrt.anything_goes(),
            source: Assertion[ParseSource] = asrt.anything_goes(),
            main_raises_hard_error: bool = False,
            proc_exe_settings: Assertion[ProcessExecutionSettings]
            = asrt.is_instance(ProcessExecutionSettings),
            instruction_settings: Assertion[InstructionSettings]
            = asrt.is_instance(InstructionSettings)
    ):
        super().__init__(
            symbol_usages,
            ExecutionExpectation(
                validation_post_sds,
                validation_pre_sds,
                main_result,
                main_raises_hard_error,
                main_side_effects_on_sds,
                main_side_effects_on_tcds,
                proc_exe_settings,
                instruction_settings,
            )
        )
        self.source = source
        self.symbol_usages = symbol_usages
def matches_exception(
        exception: Assertion[Exception] = asrt.anything_goes(),
        message: Optional[Assertion[MinorTextRenderer]] = asrt.anything_goes()
) -> Assertion[ErrorDescription]:
    return asrt.is_none_or_instance_with__many(
        err_descr.ErrorDescriptionOfException,
        [
            asrt.sub_component_many(
                'message',
                err_descr.ErrorDescriptionOfException.message.fget,
                [
                    asrt.is_none_or_instance_with(
                        SequenceRenderer,
                        asrt_renderer.is_renderer_of_major_blocks()),
                    message,
                ],
            ),
            asrt.sub_component(
                'exception',
                err_descr.ErrorDescriptionOfException.exception.fget,
                asrt.is_instance_with(
                    Exception,
                    exception,
                )),
        ],
    )
Example #3
0
 def __init__(
     self,
     validation: ValidationExpectationSvh = ValidationExpectationSvh.passes(
     ),
     main_result: Assertion[
         sh.SuccessOrHardError] = sh_assertions.is_success(),
     symbols_after_parse: Assertion[
         Sequence[SymbolUsage]] = asrt.is_empty_sequence,
     main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(),
     main_side_effects_on_tcds: Assertion[TestCaseDs] = asrt.anything_goes(
     ),
     settings_builder: Assertion[
         SettingsBuilderAssertionModel] = asrt_settings.
     stdin_is_not_present(),
     symbols_after_main: Assertion[
         Sequence[SymbolUsage]] = asrt.anything_goes(),
     proc_exe_settings: Assertion[ProcessExecutionSettings] = asrt.
     is_instance(ProcessExecutionSettings),
     instruction_settings: Assertion[InstructionSettings] = asrt.
     is_instance(InstructionSettings),
 ):
     self.validation = validation
     self.main_result = main_result
     self.settings_builder = settings_builder
     self.main_side_effects_on_sds = main_side_effects_on_sds
     self.main_side_effects_on_tcds = main_side_effects_on_tcds
     self.symbols_after_parse = symbols_after_parse
     self.symbols_after_main = symbols_after_main
     self.proc_exe_settings = proc_exe_settings
     self.instruction_settings = instruction_settings
Example #4
0
    def __new__(cls,
                validation_post_sds: Assertion[svh.SuccessOrValidationErrorOrHardError] =
                svh_assertions.is_success(),

                validation_pre_sds: Assertion[svh.SuccessOrValidationErrorOrHardError] =
                svh_assertions.is_success(),

                main_result: Assertion[pfh.PassOrFailOrHardError] = pfh_assertions.is_pass(),
                main_raises_hard_error: bool = False,
                main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(),
                main_side_effects_on_tcds: Assertion[TestCaseDs] = asrt.anything_goes(),
                proc_exe_settings: Assertion[ProcessExecutionSettings]
                = asrt.is_instance(ProcessExecutionSettings),
                instruction_settings: Assertion[InstructionSettings]
                = asrt.is_instance(InstructionSettings)
                ):
        return tuple.__new__(cls, (
            validation_post_sds,
            validation_pre_sds,

            main_result,
            main_raises_hard_error,

            main_side_effects_on_sds,
            main_side_effects_on_tcds,

            proc_exe_settings,
            instruction_settings
        ))
Example #5
0
 def phase_agnostic_3(
         validation: ValidationAssertions = validation_utils.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(),
         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(),
 ) -> 'Expectation[T]':
     return Expectation(
         MainMethodType.PHASE_AGNOSTIC,
         validation_pre_sds=validation.pre_sds,
         validation_post_sds=validation.post_sds,
         main_result=main_result,
         main_raises_hard_error=main_raises_hard_error,
         symbol_usages=symbol_usages,
         symbols_after_main=symbols_after_main,
         main_side_effects_on_sds=main_side_effects_on_files.sds,
         side_effects_on_tcds=main_side_effects_on_files.tcds,
         side_effects_on_hds=main_side_effects_on_files.case_home,
         source=source,
         proc_exe_settings=proc_exe_settings,
         instruction_settings=instruction_settings,
         main_side_effect_on_environment_variables=main_side_effect_on_environment_variables,
         assertion_on_instruction_environment=assertion_on_instruction_environment,
         setup_settings=asrt.is_none,
     )
Example #6
0
 def __init__(
     self,
     validation_pre_sds: Assertion = svh_assertions.is_success(),
     validation_post_setup: Assertion = svh_assertions.is_success(),
     main_result: Assertion[
         sh.SuccessOrHardError] = sh_assertions.is_success(),
     symbol_usages: Assertion = asrt.is_empty_sequence,
     main_side_effects_on_sds: Assertion = asrt.anything_goes(),
     main_side_effects_on_tcds: Assertion = asrt.anything_goes(),
     source: Assertion = asrt.anything_goes(),
     proc_exe_settings: Assertion[ProcessExecutionSettings] = asrt.
     is_instance(ProcessExecutionSettings),
     instruction_settings: Assertion[InstructionSettings] = asrt.
     is_instance(InstructionSettings),
 ):
     super().__init__(
         validation_pre_sds,
         validation_post_setup,
         main_result,
         symbol_usages,
         main_side_effects_on_sds,
         main_side_effects_on_tcds,
         proc_exe_settings,
         instruction_settings,
     )
     self.source = source
Example #7
0
    def test_no_symbol_references(self):
        # ARRANGE #
        option_cases = [
            option_case_for_no_option(asrt.anything_goes()),
            option_case_for_ignore_case(asrt.anything_goes()),
        ]

        source_cases = [
            SourceCase('single invalid star',
                       Arguments('*'),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
            SourceCase('invalid stars inside valid regex',
                       Arguments('before**after'),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
        ]
        # ACT & ASSERT #
        check_many(self,
                   Arrangement(),
                   source_cases,
                   ExpectationExceptPattern(
                       validation=pre_sds_validation_fails(),
                   ),
                   option_cases,
                   )
def sub_process_result(exitcode: ValueAssertion = asrt.anything_goes(),
                       stdout: ValueAssertion = asrt.anything_goes(),
                       stderr: ValueAssertion = asrt.anything_goes(),
                       ) -> ValueAssertion[SubProcessResult]:
    return _SubProcessResultAssertion(exitcode,
                                      stdout,
                                      stderr)
Example #9
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
Example #10
0
 def __init__(self,
              expected_action_result: ValueAssertion = asrt.anything_goes(),
              expected_sds_contents_after: ValueAssertion = asrt.anything_goes(),
              post_action_check: PostActionCheck = PostActionCheck()):
     self.expected_action_result = expected_action_result
     self.expected_sds_contents_after = expected_sds_contents_after
     self.post_action_check = post_action_check
Example #11
0
    def test_no_symbol_references(self):
        # ARRANGE #
        option_cases = [
            option_case_for_no_option(asrt.anything_goes()),
            option_case_for_ignore_case(asrt.anything_goes()),
        ]

        source_cases = [
            SourceCase('single invalid star',
                       Arguments('*'),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
            SourceCase('invalid stars inside valid regex',
                       Arguments('before**after'),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
        ]
        # ACT & ASSERT #
        check_many(self,
                   Arrangement(),
                   source_cases,
                   ExpectationExceptPattern(
                       validation=validation.ValidationAssertions.pre_sds_fails__w_any_msg(),
                   ),
                   option_cases,
                   )
Example #12
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,
     )
Example #13
0
 def test_matches(self):
     cases = [
         NEA(
             'empty',
             expected=dict(),
             actual=dict(),
         ),
         NEA(
             'single element',
             expected={1: sut.equals('value')},
             actual={1: 'value'},
         ),
         NEA(
             'many values',
             expected={
                 1: sut.anything_goes(),
                 5: sut.anything_goes()
             },
             actual={
                 1: 'one value',
                 5: 'another value'
             },
         ),
     ]
     for nea in cases:
         with self.subTest(nea.name):
             assertion = sut.matches_mapping(nea.expected)
             # ACT & ASSERT #
             assertion.apply_without_message(self, nea.actual)
Example #14
0
 def __init__(self,
              expected_action_result: Assertion = asrt.anything_goes(),
              expected_sds_contents_after: Assertion = asrt.anything_goes(),
              post_action_check: PostActionCheck = PostActionCheck()):
     self.expected_action_result = expected_action_result
     self.expected_sds_contents_after = expected_sds_contents_after
     self.post_action_check = post_action_check
    def test_fail(self):
        a_symbol = NameAndValue('symbol name',
                                ASymbolTableValue('symbol value'))

        a_different_symbol = NameAndValue('a different symbol name',
                                          ASymbolTableValue('a different symbol value'))
        cases = [
            ('table is empty',
             empty_symbol_table(),
             a_symbol.name,
             asrt.anything_goes(),
             ),
            ('table is singleton but contains a different name',
             SymbolTable({a_symbol.name: a_symbol.value}),
             a_different_symbol.name,
             asrt.anything_goes(),
             ),
            ('table is singleton with given name but value assertion fails',
             SymbolTable({a_symbol.name: a_symbol.value}),
             a_symbol.name,
             assert_string_value_equals(a_different_symbol.value.value)
             ),
            ('table contains more than one element',
             SymbolTable({a_symbol.name: a_symbol.value,
                          a_different_symbol.name: a_different_symbol.value
                          }),
             a_symbol.name,
             asrt.anything_goes(),
             ),
        ]
        for name, table, symbol_name, value_assertion in cases:
            with self.subTest(name=name):
                assertion = sut.assert_symbol_table_is_singleton(symbol_name, value_assertion)
                assert_that_assertion_fails(assertion, table)
Example #16
0
def error_info_matches(
        description: Assertion[
            Optional[ErrorDescription]] = asrt.anything_goes(),
        source_location_path: Assertion[
            Optional[SourceLocationPath]] = asrt.anything_goes(),
        section_name: Assertion[Optional[str]] = asrt.anything_goes()
) -> Assertion[ErrorInfo]:
    return asrt.is_instance_with__many(ErrorInfo, [
        asrt.sub_component_many('description', ErrorInfo.description.fget, [
            asrt.is_none_or_instance(ErrorDescription),
            description,
        ]),
        asrt.sub_component_many(
            'source_location_path', ErrorInfo.source_location_path.fget, [
                asrt.is_none_or_instance_with(
                    SourceLocationPath,
                    asrt_source_loc.matches_source_location_path(),
                ), source_location_path
            ]),
        asrt.sub_component_many('maybe_section_name',
                                ErrorInfo.maybe_section_name.fget, [
                                    asrt.is_none_or_instance(str),
                                    section_name,
                                ]),
    ])
Example #17
0
 def test_fail_due_to_unexpected_resolved_value(self):
     # ARRANGE #
     string_resolver = _StringResolverTestImpl(resolve_constant(STRING_VALUE))
     assertion = sut.matches_resolver(asrt.anything_goes(),
                                      asrt.anything_goes(),
                                      asrt.not_(asrt.is_(STRING_VALUE)))
     # ACT & ASSERT #
     test_of_test_resources_util.assert_that_assertion_fails(assertion, string_resolver)
Example #18
0
def matches_sdv_of_files_matcher(
        references: Assertion[
            Sequence[SymbolReference]] = asrt.anything_goes(),
        primitive_value: Assertion[FilesMatcher] = asrt.anything_goes(),
        symbols: Optional[SymbolTable] = None,
        tcds: TestCaseDs = fake_tcds(),
) -> Assertion[SymbolDependentValue]:
    return matches_matcher_sdv(primitive_value, references, symbols, tcds)
Example #19
0
 def test_fail_due_to_unexpected_resolved_value(self):
     # ARRANGE #
     string_sdv = _StringSdvTestImpl(resolve_constant(STRING_DDV))
     assertion = sut.matches_sdv(asrt.anything_goes(), asrt.anything_goes(),
                                 asrt.not_(asrt.is_(STRING_DDV)))
     # ACT & ASSERT #
     test_of_test_resources_util.assert_that_assertion_fails(
         assertion, string_sdv)
Example #20
0
 def __init__(self,
              sds: Assertion[SandboxDs] = asrt.anything_goes(),
              tcds: Assertion[TestCaseDs] = asrt.anything_goes(),
              case_home: Assertion[pathlib.Path] = asrt.anything_goes(),
              ):
     self.sds = sds
     self.tcds = tcds
     self.case_home = case_home
 def __init__(self,
              exitcode: ValueAssertion = asrt.anything_goes(),
              stdout: ValueAssertion = asrt.anything_goes(),
              stderr: ValueAssertion = asrt.anything_goes(),
              ):
     self._exitcode = exitcode
     self._stdout = stdout
     self._stderr = stderr
 def test_failure_of_value_type(self):
     # ARRANGE #
     actual_container = StringSymbolValueContext.of_arbitrary_value(
     ).container
     assertion_to_check = sut.matches_container(
         value_type=asrt.is_(ValueType.PATH),
         sdv=asrt.anything_goes(),
         definition_source=asrt.anything_goes())
     assert_that_assertion_fails(assertion_to_check, actual_container)
Example #23
0
def assert_process_result_data(
    exitcode: Assertion[int] = asrt.anything_goes(),
    stdout_contents: Assertion[str] = asrt.anything_goes(),
    stderr_contents: Assertion[str] = asrt.anything_goes(),
    contents_after_transformation: Assertion[str] = asrt.anything_goes(),
) -> Assertion[ResultWithTransformationData]:
    return ResultWithTransformationDataAssertion(
        exitcode, stdout_contents, stderr_contents,
        contents_after_transformation)
Example #24
0
 def __init__(self,
              expected_action_result: Assertion = anything_goes(),
              expected_sds_contents_after: Assertion = asrt.anything_goes(),
              post_action_check: PostActionCheck = PostActionCheck(),
              acton_raises_hard_error: bool = False):
     self.expected_action_result = expected_action_result
     self.acton_raises_hard_error = acton_raises_hard_error
     self.expected_sds_contents_after = expected_sds_contents_after
     self.post_action_check = post_action_check
 def __init__(
         self,
         exitcode: Assertion[int] = asrt.anything_goes(),
         stdout: Assertion[str] = asrt.anything_goes(),
         stderr: Assertion[str] = asrt.anything_goes(),
 ):
     self._exitcode = exitcode
     self._stdout = stdout
     self._stderr = stderr
def assert_process_result_data(exitcode: ValueAssertion[int] = asrt.anything_goes(),
                               stdout_contents: ValueAssertion[str] = asrt.anything_goes(),
                               stderr_contents: ValueAssertion[str] = asrt.anything_goes(),
                               contents_after_transformation: ValueAssertion[str] = asrt.anything_goes(),
                               ) -> ValueAssertion[ResultWithTransformationData]:
    return ResultWithTransformationDataAssertion(exitcode,
                                                 stdout_contents,
                                                 stderr_contents,
                                                 contents_after_transformation)
Example #27
0
 def test_fail_due_to_unexpected_resolver_type(self):
     # ARRANGE #
     string_resolver = _StringResolverTestImpl()
     assertion = sut.matches_resolver(sut.is_resolver_of_logic_type(LogicValueType.PROGRAM,
                                                                    ValueType.PROGRAM),
                                      asrt.anything_goes(),
                                      asrt.anything_goes())
     # ACT & ASSERT #
     test_of_test_resources_util.assert_that_assertion_fails(assertion, string_resolver)
Example #28
0
 def __init__(self,
              pattern: ValueAssertion[Pattern] = asrt.anything_goes(),
              token_stream: ValueAssertion[TokenStream] = asrt.anything_goes(),
              validation: ValidationExpectation = all_validations_passes(),
              references: ValueAssertion[Sequence[SymbolReference]] = asrt.is_empty_sequence,
              ):
     self.pattern = pattern
     self.references = references
     self.validation = validation
     self.token_stream = token_stream
Example #29
0
 def __init__(self,
              sub_process_result_from_execute: Assertion[SubProcessResult] = asrt.anything_goes(),
              source_after_parse: Assertion[ParseSource] = asrt.anything_goes(),
              symbol_usages: Assertion[Sequence[SymbolUsage]] = asrt.is_empty_sequence,
              after_execution: Assertion[TestCaseDs] = asrt.anything_goes(),
              ):
     self.sub_process_result_from_execute = sub_process_result_from_execute
     self.source_after_parse = source_after_parse
     self.symbol_usages = symbol_usages
     self.after_execution = after_execution
Example #30
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
def assert_token(token_type: ValueAssertion = asrt.anything_goes(),
                 string: ValueAssertion = asrt.anything_goes(),
                 source_string: ValueAssertion = asrt.anything_goes()) -> ValueAssertion:
    return asrt.And([
        asrt.is_instance(Token, 'Value to apply assertions on must be a {}'.format(
            Token)),
        asrt.sub_component('type', Token.type.fget, token_type),
        asrt.sub_component('string', Token.string.fget, string),
        asrt.sub_component('source_string', Token.source_string.fget, source_string),
    ])
Example #32
0
 def __init__(
     self,
     exitcode: Assertion[int] = asrt.anything_goes(),
     stdout_contents: Assertion[str] = asrt.anything_goes(),
     stderr_contents: Assertion[str] = asrt.anything_goes(),
     contents_after_transformation: Assertion[str] = asrt.anything_goes()):
     self.exitcode = exitcode
     self.stdout_contents = stdout_contents
     self.stderr_contents = stderr_contents
     self.contents_after_transformation = contents_after_transformation
 def __init__(self,
              exitcode: ValueAssertion[int] = asrt.anything_goes(),
              stdout_contents: ValueAssertion[str] = asrt.anything_goes(),
              stderr_contents: ValueAssertion[str] = asrt.anything_goes(),
              contents_after_transformation: ValueAssertion[str] = asrt.anything_goes()
              ):
     self.exitcode = exitcode
     self.stdout_contents = stdout_contents
     self.stderr_contents = stderr_contents
     self.contents_after_transformation = contents_after_transformation
def assert_source(is_at_eof: Assertion[bool] = asrt.anything_goes(),
                  is_at_eol: Assertion[bool] = asrt.anything_goes(),
                  is_at_eol__except_for_space: Assertion[bool] = asrt.anything_goes(),
                  has_current_line: Assertion[bool] = asrt.anything_goes(),
                  current_line_number: Assertion[int] = asrt.anything_goes(),
                  current_line_text: Assertion[str] = asrt.anything_goes(),
                  column_index: Assertion[int] = asrt.anything_goes(),
                  remaining_part_of_current_line: Assertion[str] = asrt.anything_goes(),
                  remaining_source: Assertion[str] = asrt.anything_goes(),
                  ) -> Assertion[ParseSource]:
    return asrt.And([
        asrt.is_instance(ParseSource, 'Value to apply assertions on must be a {}'.format(ParseSource)),
        asrt.sub_component('is_at_eof', ParseSource.is_at_eof.fget, is_at_eof),
        asrt.sub_component('has_current_line', ParseSource.has_current_line.fget, has_current_line),
        asrt.Or([
            asrt.sub_component('has_current_line', ParseSource.has_current_line.fget, asrt.equals(False)),
            # The following must only be checked if has_current_line (because of precondition of ParseSource):
            asrt.And([
                asrt.sub_component('is_at_eol', ParseSource.is_at_eol.fget, is_at_eol),
                asrt.sub_component('is_at_eol__except_for_space', ParseSource.is_at_eol__except_for_space.fget,
                                   is_at_eol__except_for_space),
                asrt.sub_component('current_line_number', ParseSource.current_line_number.fget, current_line_number),
                asrt.sub_component('column_index', ParseSource.column_index.fget, column_index),
                asrt.sub_component('current_line_text', ParseSource.current_line_text.fget, current_line_text),
                asrt.sub_component('remaining_part_of_current_line', ParseSource.remaining_part_of_current_line.fget,
                                   remaining_part_of_current_line),
            ])
        ]),
        asrt.sub_component('remaining_source', ParseSource.remaining_source.fget, remaining_source),
    ])
Example #35
0
def result_matches(
    hds: Assertion[HomeDs] = asrt.anything_goes(),
    sds: Assertion[SandboxDs] = asrt.anything_goes(),
    partial_result: Assertion[PartialExeResult] = asrt.anything_goes(),
) -> Assertion[Result]:
    return asrt.and_([
        asrt.sub_component('hds', Result.hds.fget, hds),
        asrt.sub_component('sds', Result.sds.fget, sds),
        asrt.sub_component('partial_result', Result.partial_result.fget,
                           partial_result),
    ])
def matches_source_location_info2(
        source: ValueAssertion[LineSequence] = asrt.anything_goes(),
        file_path_rel_referrer: ValueAssertion[pathlib.Path] = asrt.anything_goes(),
        file_inclusion_chain: ValueAssertion[Sequence[SourceLocation]] = asrt.anything_goes(),
        abs_path_of_dir_containing_root_file: ValueAssertion[pathlib.Path] = asrt.anything_goes(),
) -> ValueAssertion[SourceLocationInfo]:
    return matches_source_location_info(
        abs_path_of_dir_containing_first_file_path=abs_path_of_dir_containing_root_file,
        source_location_path=matches_source_location_path(
            matches_source_location(source, file_path_rel_referrer),
            file_inclusion_chain))
def has(timeout: ValueAssertion[Optional[int]] = asrt.anything_goes(),
        test_case_status: ValueAssertion[TestCaseStatus] = asrt.anything_goes(),
        ) -> ValueAssertion[ConfigurationBuilder]:
    return asrt.and_([
        asrt.sub_component('timeout',
                           ConfigurationBuilder.timeout_in_seconds.fget,
                           timeout),
        asrt.sub_component('test-case-status',
                           ConfigurationBuilder.test_case_status.fget,
                           test_case_status),
    ])
Example #38
0
 def __init__(self,
              main_result: ValueAssertion[SuccessOrHardError] = sh_assertions.is_success(),
              source: ValueAssertion[ParseSource] = asrt.anything_goes(),
              configuration: ValueAssertion[ConfigurationBuilder] = asrt.anything_goes(),
              file_ref_rel_root_2_conf: Callable[[pathlib.Path], ValueAssertion[ConfigurationBuilder]] =
              lambda x: asrt.anything_goes()
              ):
     self.main_result = main_result
     self.configuration = configuration
     self.file_ref_rel_root_2_conf = file_ref_rel_root_2_conf
     self.source = source
def matches_source_location_info2(
        source: Assertion[LineSequence] = asrt.anything_goes(),
        file_path_rel_referrer: Assertion[pathlib.Path] = asrt.anything_goes(),
        file_inclusion_chain: Assertion[Sequence[SourceLocation]] = asrt.anything_goes(),
        abs_path_of_dir_containing_root_file: Assertion[pathlib.Path] = asrt.anything_goes(),
) -> Assertion[SourceLocationInfo]:
    return matches_source_location_info(
        abs_path_of_dir_containing_first_file_path=abs_path_of_dir_containing_root_file,
        source_location_path=matches_source_location_path(
            matches_source_location(source, file_path_rel_referrer),
            file_inclusion_chain))
Example #40
0
def matches_file_inclusion_directive(
    files_to_include: Assertion[Sequence[pathlib.Path]] = asrt.anything_goes(),
    source: Assertion[LineSequence] = asrt.anything_goes(),
) -> Assertion[ParsedFileInclusionDirective]:
    return asrt.and_([
        asrt.sub_component('files_to_include',
                           ParsedFileInclusionDirective.files_to_include.fget,
                           files_to_include),
        asrt.sub_component('source', ParsedFileInclusionDirective.source.fget,
                           source),
    ])
 def __init__(
         self,
         header: Assertion[str] = asrt.anything_goes(),
         data: Assertion = asrt.anything_goes(),
         details: Assertion[Sequence[Detail]] = asrt.anything_goes(),
         children: Assertion[Sequence[Node]] = asrt.anything_goes(),
 ):
     self._header = header
     self._data = data
     self._details = details
     self._children = children
Example #42
0
    def _check_failing_validation_of_referenced_program__for_relativity(self, missing_file_relativity: RelOptionType):
        relativity_conf = relativity_options.conf_rel_any(missing_file_relativity)

        program_symbol_with_ref_to_non_exiting_exe_file = ProgramSymbolContext.of_sdv(
            'PGM_WITH_REF_TO_EXE_FILE',
            program_sdvs.ref_to_exe_file(
                constant(simple_of_rel_option(relativity_conf.relativity_option,
                                              'non-existing-exe-file')))
        )

        program_symbol_with_ref_to_non_exiting_file_as_argument = ProgramSymbolContext.of_sdv(
            'PGM_WITH_ARG_WITH_REF_TO_FILE',
            program_sdvs.interpret_py_source_file_that_must_exist(
                constant(simple_of_rel_option(relativity_conf.relativity_option,
                                              'non-existing-python-file.py')))
        )

        expectation = MultiSourceExpectation.of_const(
            symbol_references=asrt.anything_goes(),
            primitive=asrt.anything_goes(),
            execution=ExecutionExpectation(
                validation=FAILING_VALIDATION_ASSERTION_FOR_PARTITION[relativity_conf.directory_structure_partition],
            )
        )

        symbols = SymbolContext.symbol_table_of_contexts([
            program_symbol_with_ref_to_non_exiting_exe_file,
            program_symbol_with_ref_to_non_exiting_file_as_argument,
        ])
        arrangement = arrangement_w_tcds(
            symbols=symbols,
        )

        cases = [
            NameAndValue(
                'executable does not exist',
                RawProgramOfSymbolReferenceAbsStx(program_symbol_with_ref_to_non_exiting_exe_file.name),
            ),
            NameAndValue(
                'file referenced from argument does not exist',
                RawProgramOfSymbolReferenceAbsStx(program_symbol_with_ref_to_non_exiting_file_as_argument.name),
            ),
        ]

        for case in cases:
            with self.subTest(case=case.name):
                # ACT & ASSERT #
                CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input(
                    self,
                    equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc,
                    case.value,
                    arrangement,
                    expectation,
                )
def matches_source_location(source: ValueAssertion[LineSequence] = asrt.anything_goes(),
                            file_path_rel_referrer: ValueAssertion[pathlib.Path] = asrt.anything_goes(),
                            ) -> ValueAssertion[SourceLocation]:
    return asrt.is_instance_with(SourceLocation,
                                 asrt.and_([
                                     asrt.sub_component('source',
                                                        SourceLocation.source.fget,
                                                        source),
                                     asrt.sub_component('file_path_rel_referrer',
                                                        SourceLocation.file_path_rel_referrer.fget,
                                                        file_path_rel_referrer),
                                 ]))
Example #44
0
 def expect_success(
     self,
     main_side_effects_on_sds: Assertion[SandboxDs] = asrt.anything_goes(),
     symbol_usages: Assertion[
         Sequence[SymbolUsage]] = asrt.is_empty_sequence,
     source: Assertion[ParseSource] = asrt.anything_goes(),
     proc_exe_settings: Assertion[ProcessExecutionSettings] = asrt.
     is_instance(ProcessExecutionSettings),
     instruction_settings: Assertion[InstructionSettings] = asrt.
     is_instance(InstructionSettings),
 ):
     raise NotImplementedError()
def matches_file_inclusion_directive(
        files_to_include: ValueAssertion[Sequence[pathlib.Path]] = asrt.anything_goes(),
        source: ValueAssertion[LineSequence] = asrt.anything_goes(),
) -> ValueAssertion[ParsedFileInclusionDirective]:
    return asrt.and_([
        asrt.sub_component('files_to_include',
                           ParsedFileInclusionDirective.files_to_include.fget,
                           files_to_include),
        asrt.sub_component('source',
                           ParsedFileInclusionDirective.source.fget,
                           source),
    ])
def matches_value__w_header(
    value: Assertion[bool],
    header: Assertion[str],
    details: Assertion[Sequence[Detail]] = asrt.anything_goes(),
    children: Assertion[Sequence[Node]] = asrt.anything_goes(),
) -> Assertion[MatchingResult]:
    return matches(value=value,
                   trace=asrt_trace_rendering.matches_node_renderer(
                       asrt_d_tree.matches_node(header=header,
                                                data=value,
                                                details=details,
                                                children=children), ))
def matches_line_sequence(first_line_number: ValueAssertion[int] = asrt.anything_goes(),
                          lines: ValueAssertion[Sequence[str]] = asrt.anything_goes(),
                          ) -> ValueAssertion[LineSequence]:
    return asrt.is_instance_with(LineSequence,
                                 asrt.and_([
                                     asrt.sub_component('first_line_number',
                                                        LineSequence.first_line_number.fget,
                                                        first_line_number),
                                     asrt.sub_component('lines',
                                                        LineSequence.lines.fget,
                                                        lines),
                                 ]))
Example #48
0
    def test_fail_due_to_unexpected_references(self):
        # ARRANGE #
        reference = data_symbol_utils.symbol_reference('symbol_name')
        string_resolver_with_single_reference = _StringResolverTestImpl(explicit_references=[reference])

        assertion = sut.matches_resolver(asrt.anything_goes(),
                                         asrt.is_empty_sequence,
                                         asrt.anything_goes())
        # ACT & ASSERT #
        test_of_test_resources_util.assert_that_assertion_fails(
            assertion,
            string_resolver_with_single_reference)
Example #49
0
    def test_symbol_table_is_passed_to_resolve_method(self):
        # ARRANGE #
        symbol_name = 'symbol_name'
        string_resolver = _StringResolverTestImpl(resolve_string_via_symbol_table(symbol_name))
        symbol_table = singleton_symbol_table_2(symbol_name,
                                                data_symbol_utils.string_value_constant_container2(STRING_VALUE))

        assertion = sut.matches_resolver(asrt.anything_goes(),
                                         asrt.anything_goes(),
                                         asrt.is_(STRING_VALUE),
                                         symbols=symbol_table)
        # ACT & ASSERT #
        assertion.apply_without_message(self, string_resolver)
Example #50
0
def matches_instruction_with_parse_source_info(
        section_name: ValueAssertion[str] = asrt.anything_goes(),
        current_source_file: ValueAssertion[FileLocationInfo] = asrt.anything_goes(),
) -> ValueAssertion[model.Instruction]:
    return asrt.is_instance_with_many(InstructionInSectionWithParseSourceInfo,
                                      [
                                          asrt.sub_component('section_name',
                                                             InstructionInSectionWithParseSourceInfo.section_name.fget,
                                                             section_name),
                                          asrt.sub_component('current_source_file',
                                                             lambda instr: instr.fs_location_info.current_source_file,
                                                             current_source_file),
                                      ])
def matches_source_location_path(
        source_location: ValueAssertion[SourceLocation] = asrt.anything_goes(),
        file_inclusion_chain: ValueAssertion[Sequence[SourceLocation]] = asrt.anything_goes(),
) -> ValueAssertion[SourceLocationPath]:
    return asrt.is_instance_with(SourceLocationPath,
                                 asrt.and_([
                                     asrt.sub_component('location',
                                                        SourceLocationPath.location.fget,
                                                        source_location),
                                     asrt.sub_component('file_inclusion_chain',
                                                        SourceLocationPath.file_inclusion_chain.fget,
                                                        file_inclusion_chain),
                                 ]))
Example #52
0
 def __init__(
         self,
         source: ValueAssertion[ParseSource] = asrt.anything_goes(),
         symbol_references: ValueAssertion[Sequence[SymbolReference]] = asrt.is_empty_sequence,
         validation: ValidationExpectation = all_validations_passes(),
         main_result: ValueAssertion[StringTransformerModel] = asrt.anything_goes(),
         is_hard_error: Optional[ValueAssertion[str]] = None,
 ):
     self.source = source
     self.symbol_references = symbol_references
     self.validation = validation
     self.main_result = main_result
     self.is_hard_error = is_hard_error
def matches_recording(string: ValueAssertion[str] = asrt.anything_goes(),
                      file_location_info: ValueAssertion[FileLocationInfo] = asrt.anything_goes()
                      ) -> ValueAssertion[Recording]:
    return asrt.and_([
        asrt.sub_component('string',
                           Recording.string.fget,
                           string
                           ),
        asrt.sub_component('file_location_info',
                           Recording.file_location_info.fget,
                           file_location_info,
                           ),
    ])
def assert_token_stream(
        source: ValueAssertion[str] = asrt.anything_goes(),
        remaining_source: ValueAssertion[str] = asrt.anything_goes(),
        remaining_part_of_current_line: ValueAssertion[str] = asrt.anything_goes(),
        remaining_source_after_head: ValueAssertion[str] = asrt.anything_goes(),
        is_null: ValueAssertion[bool] = asrt.anything_goes(),
        head_token: ValueAssertion[Token] = asrt.anything_goes(),
        look_ahead_state: ValueAssertion[LookAheadState] = asrt.anything_goes(),
        position: ValueAssertion[int] = asrt.anything_goes()) -> ValueAssertion:
    return asrt.is_instance_with(
        TokenStream,
        asrt.and_([
            asrt.sub_component('source', TokenStream.source.fget, source),
            asrt.sub_component('remaining_source',
                               TokenStream.remaining_source.fget,
                               remaining_source),
            asrt.sub_component('remaining_part_of_current_line',
                               TokenStream.remaining_part_of_current_line.fget,
                               remaining_part_of_current_line),
            asrt.sub_component('position', TokenStream.position.fget, position),
            asrt.sub_component('look_ahead_state', TokenStream.look_ahead_state.fget, look_ahead_state),
            asrt.sub_component('is_null', TokenStream.is_null.fget, is_null),
            asrt.or_([
                asrt.sub_component('is_null', TokenStream.is_null.fget, asrt.is_true),
                # The following must only be checked if not is_null (because of precondition):
                asrt.and_([
                    asrt.sub_component('head_token', TokenStream.head.fget, head_token),
                    asrt.sub_component('remaining_source_after_head',
                                       TokenStream.remaining_source_after_head.fget, remaining_source_after_head),
                ])
            ]),
        ]))
 def __init__(self,
              result: ValueAssertion[ResultWithTransformationData] = assert_process_result_data(),
              validation: ValidationExpectation = all_validations_passes(),
              symbol_references: ValueAssertion = asrt.is_empty_sequence,
              main_side_effects_on_sds: ValueAssertion = asrt.anything_goes(),
              main_side_effects_on_home_and_sds: ValueAssertion = asrt.anything_goes(),
              source: ValueAssertion = asrt.anything_goes(),
              ):
     self.source = source
     self.symbol_references = symbol_references
     self.validation = validation
     self.result = result
     self.main_side_effects_on_home_and_sds = main_side_effects_on_home_and_sds
     self.main_side_effects_on_sds = main_side_effects_on_sds
def matches_source_location_info(
        abs_path_of_dir_containing_first_file_path: ValueAssertion[pathlib.Path] = asrt.anything_goes(),
        source_location_path: ValueAssertion[SourceLocationPath] = asrt.anything_goes(),
) -> ValueAssertion[SourceLocationInfo]:
    return asrt.is_instance_with_many(
        SourceLocationInfo,
        [
            asrt.sub_component('abs_path_of_dir_containing_first_file_path',
                               SourceLocationInfo.abs_path_of_dir_containing_first_file_path.fget,
                               abs_path_of_dir_containing_first_file_path),
            asrt.sub_component('source_location_path',
                               SourceLocationInfo.source_location_path.fget,
                               source_location_path),
        ])
Example #57
0
 def __init__(self,
              result_of_validate_pre_sds: ValueAssertion = svh_assertions.is_success(),
              result_of_prepare: ValueAssertion = sh_assertions.is_success(),
              result_of_execute: ValueAssertion = eh_assertions.is_any_exit_code,
              symbol_usages: ValueAssertion = asrt.is_empty_sequence,
              side_effects_on_files_after_execute: ValueAssertion = asrt.anything_goes(),
              side_effects_on_files_after_prepare: ValueAssertion = asrt.anything_goes(),
              sub_process_result_from_execute: ValueAssertion = asrt.anything_goes()):
     self.result_of_validate_pre_sds = result_of_validate_pre_sds
     self.symbol_usages = symbol_usages
     self.side_effects_on_files_after_prepare = side_effects_on_files_after_prepare
     self.side_effects_on_files_after_execute = side_effects_on_files_after_execute
     self.result_of_prepare = result_of_prepare
     self.result_of_execute = result_of_execute
     self.sub_process_result_from_execute = sub_process_result_from_execute
Example #58
0
def result_assertion(hds: ValueAssertion[HomeDirectoryStructure] = asrt.anything_goes(),
                     sds: ValueAssertion[SandboxDirectoryStructure] = asrt.anything_goes(),
                     partial_result: ValueAssertion[PartialExeResult] = asrt.anything_goes(),
                     ) -> ValueAssertion[Result]:
    return asrt.and_([
        asrt.sub_component('hds',
                           Result.hds.fget,
                           hds),
        asrt.sub_component('sds',
                           Result.sds.fget,
                           sds),
        asrt.sub_component('partial_result',
                           Result.partial_result.fget,
                           partial_result),
    ])
Example #59
0
 def expect_hard_error_of_main(self,
                               assertion_on_error_message: ValueAssertion = asrt.anything_goes()):
     """
     Expectation that the result should be HARD_ERROR,
     both for assert- and non-assert phase instructions.
     """
     return self.expect_failure_of_main(assertion_on_error_message)
Example #60
0
def matches_section_contents_element(
        element_type: ElementType,
        instruction_info: ValueAssertion[model.InstructionInfo] = asrt.anything_goes(),
        source_location_info: ValueAssertion[SourceLocationInfo] = asrt.anything_goes(),
) -> ValueAssertion[model.SectionContentElement]:
    return asrt.and_([
        asrt.sub_component('element type',
                           model.SectionContentElement.element_type.fget,
                           asrt.equals(element_type)),
        asrt.sub_component('instruction_info',
                           model.SectionContentElement.instruction_info.fget,
                           instruction_info),
        asrt.sub_component('source_location_info',
                           model.SectionContentElement.source_location_info.fget,
                           source_location_info),
    ])