Example #1
0
    def test_act(self):
        # ARRANGE #
        cases = {
            STEP__ACT__PARSE: {
                EXECUTION__INTERNAL_ERROR:
                ActorThatRunsConstantActions(parse_atc=DO_RAISES_EXCEPTION),
            },
            STEP__VALIDATE_PRE_SDS: {
                EXECUTION__VALIDATION_ERROR:
                ActorThatRunsConstantActions(
                    validate_pre_sds_action=SVH_VALIDATION_ERROR),
                EXECUTION__HARD_ERROR:
                ActorThatRunsConstantActions(
                    validate_pre_sds_action=SVH_HARD_ERROR),
                EXECUTION__INTERNAL_ERROR:
                ActorThatRunsConstantActions(
                    validate_pre_sds_initial_action=DO_RAISES_EXCEPTION),
            },
        }
        test_case_definition = test_case_definition_for(instruction_set())

        test_case_source = ''

        for step, exit_value_2_constructor in cases.items():
            for exit_value, constructor in exit_value_2_constructor.items():
                expectation = Expectation(exit_value, output_is_empty)
                with self.subTest(step=step,
                                  exit_value=exit_value.exit_identifier):
                    # ACT & ASSERT #
                    _check(self, test_case_definition, constructor,
                           test_case_source,
                           self.sandbox_dir_resolver_that_should_not_be_called,
                           expectation)
    def _check_defaults(self, default_environ: Optional[Mapping[str, str]]):
        recording_media = _empty_recording_media()
        expected_recordings = [
            # setup #
            RecordingEntry.from_settings(PhaseEnum.SETUP, None,
                                         default_environ),
            # act #
            RecordingEntry.from_settings(PhaseEnum.ACT, None, default_environ),
        ]

        helper = RecordingsHelper(recording_media)
        test_case = partial_test_case_with_instructions([
            setup_phase_instruction_that(
                main_initial_action=helper.action_for_recordings_for(
                    PhaseEnum.SETUP, None), ),
        ], )
        actor_that_records_env_vars_of_act_exe_input = ActorThatRunsConstantActions(
            execute_initial_action=helper.
            actor_action_for_recording_environ_of_act_exe_input, )
        # ACT #
        test__va(
            self,
            test_case,
            Arrangement(
                actor=actor_that_records_env_vars_of_act_exe_input,
                environ=default_environ,
            ),
            result_is_pass(),
        )
        self.assertEqual(expected_recordings, recording_media, 'recordings')
 def test_internal_error_in_act_execute(self):
     test_case = _single_successful_instruction_in_each_phase(
         single_line_sequence(72, 'ignored'))
     self._check(
         Arrangement(
             test_case,
             ActorThatRunsConstantActions(
                 execute_action=execute_action_that_raises(
                     test.ImplementationErrorTestException()))),
         Expectation(
             asrt_result.matches2(
                 ExecutionFailureStatus.INTERNAL_ERROR,
                 asrt_result.has_sds(),
                 asrt_result.has_no_action_to_check_outcome(),
                 ExpectedFailureForPhaseFailure.new_with_exception(
                     phase_step.ACT__EXECUTE,
                     test.ImplementationErrorTestException)),
             atc_stdout_output=asrt.equals(''),
             atc_stderr_output=asrt.equals(''),
             step_recordings=[phase_step.ACT__PARSE] +
             SYMBOL_VALIDATION_STEPS__ONCE +
             PRE_SDS_VALIDATION_STEPS__ONCE + [
                 phase_step.SETUP__MAIN,
                 phase_step.SETUP__VALIDATE_POST_SETUP,
                 phase_step.ACT__VALIDATE_POST_SETUP,
                 phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP,
                 phase_step.ASSERT__VALIDATE_POST_SETUP,
                 phase_step.ACT__VALIDATE_EXE_INPUT,
                 phase_step.ACT__PREPARE,
                 phase_step.ACT__EXECUTE,
                 (phase_step.CLEANUP__MAIN, PreviousPhase.ACT),
             ],
         ))
    def test_instruction_environment_specifies_correct_tmp_dir_space_for_each_instruction(
            self):
        # ARRANGE #
        recorder = {}

        setup_phase_instr_that_records = setup_phase_instruction_that(
            validate_post_setup_initial_action=
            RecordTmpDirForInstructionInPhase(PhaseEnum.SETUP, recorder),
            main_initial_action=RecordTmpDirForInstructionInPhase(
                PhaseEnum.SETUP, recorder).call,
        )
        before_assert_phase_instr_that_records = before_assert_phase_instruction_that(
            validate_post_setup_initial_action=
            RecordTmpDirForInstructionInPhase(PhaseEnum.BEFORE_ASSERT,
                                              recorder),
            main_initial_action=RecordTmpDirForInstructionInPhase(
                PhaseEnum.BEFORE_ASSERT, recorder).call)
        assert_phase_instr_that_records = assert_phase_instruction_that(
            validate_post_setup_initial_action=
            RecordTmpDirForInstructionInPhase(PhaseEnum.ASSERT, recorder),
            main_initial_action=RecordTmpDirForInstructionInPhase(
                PhaseEnum.ASSERT, recorder).call)
        cleanup_phase_instr_that_records = cleanup_phase_instruction_that(
            main_initial_action=RecordTmpDirForInstructionInPhase(
                PhaseEnum.CLEANUP, recorder).call)
        test_case = partial_test_case_with_instructions(
            [
                setup_phase_instr_that_records,
                setup_phase_instr_that_records,
            ],
            [act_phase_instruction_with_source(LineSequence(1, ('line', )))],
            [
                before_assert_phase_instr_that_records,
                before_assert_phase_instr_that_records,
            ],
            [
                assert_phase_instr_that_records,
                assert_phase_instr_that_records,
            ],
            [
                cleanup_phase_instr_that_records,
                cleanup_phase_instr_that_records,
            ],
        )
        actor_that_registers_tmp_dirs = ActorThatRunsConstantActions(
            validate_post_setup_initial_action=
            RecordTmpDirForInstructionInPhase(PhaseEnum.ACT, recorder),
            prepare_initial_action=RecordTmpDirForInstructionInPhase(
                PhaseEnum.ACT, recorder),
            execute_initial_action=RecordTmpDirForInstructionInPhase(
                PhaseEnum.ACT, recorder),
        )
        # ACT & ASSERT #
        test(self,
             test_case,
             actor_that_registers_tmp_dirs,
             functools.partial(tmp_dir_is_correct_for_each_instruction,
                               recorder, 2),
             is_keep_sandbox=False)
Example #5
0
def actor_that_records_property_of_env_for_each_step_post_sds(
        property_recorder: PropertyRecorderBuilder) -> Actor:
    return ActorThatRunsConstantActions(
        validate_post_setup_initial_action=property_recorder.of_first_arg(
            step.ACT__VALIDATE_POST_SETUP),
        prepare_initial_action=property_recorder.of_first_arg(
            step.ACT__PREPARE),
        execute_initial_action=property_recorder.of_first_arg(
            step.ACT__EXECUTE),
    )
Example #6
0
 def test_WHEN_pass_THEN_sds_SHOULD_be_printed(self):
     # ARRANGE #
     test_case_definition = test_case_definition_for(instruction_set())
     test_case_source = ''
     expectation = Expectation(EXECUTION__PASS,
                               output_is_sds_which_should_be_preserved)
     # ACT & ASSERT #
     _check(self, test_case_definition, ActorThatRunsConstantActions(),
            test_case_source, self.sandbox_dir_resolver_of_given_dir,
            expectation)
Example #7
0
 def _actor(self) -> Actor:
     return ActorThatRunsConstantActions(
         validate_pre_sds_initial_action=_RecordEnvVars(
             self.recorder, phase_step.ACT__VALIDATE_PRE_SDS).call,
         validate_post_setup_initial_action=_RecordEnvVars(
             self.recorder, phase_step.ACT__VALIDATE_POST_SETUP).call,
         prepare_initial_action=_RecordEnvVars(
             self.recorder, phase_step.ACT__PREPARE).call,
         execute_initial_action=_RecordEnvVars(
             self.recorder,
             phase_step.ACT__EXECUTE).as_execute_initial_action)
Example #8
0
def actor_that_runs_constant_actions(
        validate_pre_sds_action=test_actions.validate_action_that_returns(svh.new_svh_success()),
        validate_post_setup_action=test_actions.validate_action_that_returns(svh.new_svh_success()),
        prepare_action=test_actions.prepare_action_that_returns(sh.new_sh_success()),
        execute_action=test_actions.execute_action_that_returns_exit_code()) -> Actor:
    return ActorThatRunsConstantActions(
        validate_pre_sds_action=validate_pre_sds_action,
        validate_post_setup_action=validate_post_setup_action,
        prepare_action=prepare_action,
        execute_action=execute_action
    )
def main_program_config(
    tc_definition: TestCaseDefinitionForMainProgram,
    test_suite_definition:
    TestSuiteDefinition = test_suite_definition_without_instructions(),
    act_phase_setup: ActPhaseSetup = ActPhaseSetup(
        'actor that runs constant actions', ActorThatRunsConstantActions()),
) -> MainProgramConfig:
    return MainProgramConfig(
        TestCaseHandlingSetup(act_phase_setup, IDENTITY_PREPROCESSOR),
        tc_definition,
        test_suite_definition,
    )
def actor_that_records_a_value_per_step(
    recorder_for_step_with_env: Callable,
    recorder_for_parse_step: Callable,
) -> Actor:
    return ActorThatRunsConstantActions(
        parse_atc=recorder_for_parse_step(step.ACT__PARSE),
        validate_pre_sds_initial_action=recorder_for_step_with_env(
            step.ACT__VALIDATE_PRE_SDS),
        validate_post_setup_initial_action=recorder_for_step_with_env(
            step.ACT__VALIDATE_POST_SETUP),
        prepare_initial_action=recorder_for_step_with_env(step.ACT__PREPARE),
        execute_initial_action=recorder_for_step_with_env(step.ACT__EXECUTE),
    )
Example #11
0
    def test_failing_parse(self):
        # ARRANGE #
        test_case_definition = test_case_definition_for(instruction_set())
        actor = ActorThatRunsConstantActions()
        test_case_source = lines_content([
            section_header(phase_identifier.SETUP.identifier),
            'not_the_name_of_an_instruction',
        ])

        expectation = Expectation(NO_EXECUTION__SYNTAX_ERROR, output_is_empty)
        # ACT & ASSERT #
        _check(self, test_case_definition, actor, test_case_source,
               self.sandbox_dir_resolver_that_should_not_be_called,
               expectation)
    def runTest(self):
        default_environ = None
        modified_environ = {'modified_var': 'val of modified var'}

        recording_media = _empty_recording_media()
        expected_recordings = [
            # setup #
            RecordingEntry.from_settings(PhaseEnum.SETUP,
                                         PosInPhase.BEFORE_MODIFY,
                                         default_environ),
            RecordingEntry.from_settings(PhaseEnum.SETUP,
                                         PosInPhase.AFTER_MODIFY,
                                         modified_environ),
            # act #
            RecordingEntry.from_settings(PhaseEnum.ACT, None,
                                         modified_environ),
        ]

        helper = RecordingsHelper(recording_media)
        test_case = partial_test_case_with_instructions([
            setup_phase_instruction_that(
                main_initial_action=helper.action_for_recordings_for(
                    PhaseEnum.SETUP, PosInPhase.BEFORE_MODIFY), ),
            setup_phase_instruction_that(
                main_initial_action=ActionThatSetsSettings(
                    dict(modified_environ)).initial_action, ),
            setup_phase_instruction_that(
                main_initial_action=helper.action_for_recordings_for(
                    PhaseEnum.SETUP, PosInPhase.AFTER_MODIFY), ),
        ], )
        actor_that_records_env_vars_of_act_exe_input = ActorThatRunsConstantActions(
            execute_initial_action=helper.
            actor_action_for_recording_environ_of_act_exe_input, )
        # ACT #
        test__va(
            self,
            test_case,
            Arrangement(
                actor=actor_that_records_env_vars_of_act_exe_input,
                environ=default_environ,
            ),
            result_is_pass(),
        )
        self.assertEqual(expected_recordings, recording_media, 'recordings')
Example #13
0
    def test_act(self):
        # ARRANGE #
        cases = {
            STEP__VALIDATE_POST_SETUP: {
                EXECUTION__VALIDATION_ERROR:
                ActorThatRunsConstantActions(
                    validate_post_setup_action=SVH_VALIDATION_ERROR),
                EXECUTION__HARD_ERROR:
                ActorThatRunsConstantActions(
                    validate_post_setup_action=SVH_HARD_ERROR),
                EXECUTION__INTERNAL_ERROR:
                ActorThatRunsConstantActions(
                    validate_post_setup_initial_action=DO_RAISES_EXCEPTION),
            },
            STEP__ACT__PREPARE: {
                EXECUTION__HARD_ERROR:
                ActorThatRunsConstantActions(prepare_action=SH_HARD_ERROR),
                EXECUTION__INTERNAL_ERROR:
                ActorThatRunsConstantActions(
                    prepare_initial_action=DO_RAISES_EXCEPTION),
            },
            STEP__ACT__EXECUTE: {
                EXECUTION__INTERNAL_ERROR:
                ActorThatRunsConstantActions(
                    execute_initial_action=DO_RAISES_EXCEPTION),
            },
        }
        test_case_definition = test_case_definition_for(instruction_set())

        test_case_source = ''

        for step, exit_value_2_constructor in cases.items():
            for exit_value, actor in exit_value_2_constructor.items():
                expectation = Expectation(
                    exit_value, output_is_sds_which_should_be_preserved)
                with self.subTest(step=step,
                                  exit_value=exit_value.exit_identifier):
                    # ACT & ASSERT #
                    _check(self, test_case_definition, actor, test_case_source,
                           self.sandbox_dir_resolver_of_given_dir, expectation)
Example #14
0
 def actor(self, recording_media: List[Recording]) -> Actor:
     return ActorThatRunsConstantActions()
Example #15
0
def test_case_handling_setup_with_identity_preprocessor(
) -> TestCaseHandlingSetup:
    return TestCaseHandlingSetup(
        ActPhaseSetup('actor that does nothing',
                      ActorThatRunsConstantActions()), IDENTITY_PREPROCESSOR)
Example #16
0
def dummy_actor() -> Actor:
    return ActorThatRunsConstantActions()
Example #17
0
 def _actor(self) -> Actor:
     return ActorThatRunsConstantActions(
         validate_post_setup_action=_RecordCurrDirAndReturn(self.recorder, phase_step.ACT__VALIDATE_POST_SETUP,
                                                            svh.new_svh_success()),
         execute_action=_RecordCurrDirAndReturn(self.recorder, phase_step.ACT__EXECUTE,
                                                new_eh_exit_code(0)))
Example #18
0
def act_phase_setup_for_reference_instruction() -> ActPhaseSetup:
    return ActPhaseSetup('actor that runs constant actions',
                         ActorThatRunsConstantActions())
Example #19
0
                                                 SandboxRootDirNameResolver],
                       case: Case):
    # ARRANGE #

    instruction_name = 'the_instruction'

    test_case_definition = test_case_definition_for(
        case.arrangement.instruction_setup_with_the_instruction(
            instruction_name))

    test_case_source = lines_content([
        section_header(case.arrangement.phase.identifier),
        instruction_name,
    ])

    _check(put, test_case_definition, ActorThatRunsConstantActions(),
           test_case_source, mk_sds_resolver, case.expectation)


def _check(
    put: unittest.TestCase,
    test_case_definition: TestCaseDefinitionForMainProgram,
    actor: Actor,
    test_case_source: str,
    mk_sds_resolver: Callable[[str], SandboxRootDirNameResolver],
    expectation: Expectation,
):
    # ARRANGE #

    case_file = File('the-test.case', test_case_source)
    source_files_dir_contents = DirContents([case_file])