예제 #1
0
 def test_setup(self):
     # ARRANGE #
     cases = {
         STEP__VALIDATE_POST_SETUP: {
             EXECUTION__VALIDATION_ERROR:
             setup_phase_instruction_that(
                 validate_post_setup=SVH_VALIDATION_ERROR),
             EXECUTION__HARD_ERROR:
             setup_phase_instruction_that(
                 validate_post_setup=SVH_HARD_ERROR),
             EXECUTION__INTERNAL_ERROR:
             setup_phase_instruction_that(
                 validate_post_setup_initial_action=DO_RAISES_EXCEPTION),
         },
         STEP__MAIN: {
             EXECUTION__HARD_ERROR:
             setup_phase_instruction_that(main=SH_HARD_ERROR),
             EXECUTION__INTERNAL_ERROR:
             setup_phase_instruction_that(
                 main_initial_action=DO_RAISES_EXCEPTION),
         },
     }
     # ACT & ASSERT #
     self._check_and_assert_sds_is_preserved_and_is_printed(
         phase_identifier.SETUP, cases)
예제 #2
0
    def test_setup(self):
        # ARRANGE #
        cases = {
            STEP__VALIDATE_POST_SETUP:
                {
                    EXECUTION__VALIDATION_ERROR:
                        setup_phase_instruction_that(validate_post_setup=SVH_VALIDATION_ERROR),

                    EXECUTION__HARD_ERROR:
                        setup_phase_instruction_that(validate_post_setup=SVH_HARD_ERROR),

                    EXECUTION__IMPLEMENTATION_ERROR:
                        setup_phase_instruction_that(validate_post_setup_initial_action=DO_RAISES_EXCEPTION),
                },
            STEP__MAIN:
                {
                    EXECUTION__HARD_ERROR:
                        setup_phase_instruction_that(main=SH_HARD_ERROR),

                    EXECUTION__IMPLEMENTATION_ERROR:
                        setup_phase_instruction_that(main_initial_action=DO_RAISES_EXCEPTION),
                },
        }
        # ACT & ASSERT #
        self._check_and_assert_sds_is_preserved_and_is_printed(phase_identifier.SETUP, cases)
예제 #3
0
    def test_setup(self):
        # ARRANGE #
        cases = {
            EXECUTION__VALIDATION_ERROR:
                setup_phase_instruction_that(validate_pre_sds=SVH_VALIDATION_ERROR),

            EXECUTION__HARD_ERROR:
                setup_phase_instruction_that(validate_pre_sds=SVH_HARD_ERROR),

            EXECUTION__IMPLEMENTATION_ERROR:
                setup_phase_instruction_that(validate_pre_sds_initial_action=DO_RAISES_EXCEPTION),
        }
        # ACT & ASSERT #
        self._check_and_assert_sds_is_not_created_and_stdout_is_empty(phase_identifier.SETUP, cases)
예제 #4
0
 def test_setup(self):
     # ARRANGE #
     cases = {
         EXECUTION__VALIDATION_ERROR:
         setup_phase_instruction_that(
             validate_pre_sds=SVH_VALIDATION_ERROR),
         EXECUTION__HARD_ERROR:
         setup_phase_instruction_that(validate_pre_sds=SVH_HARD_ERROR),
         EXECUTION__INTERNAL_ERROR:
         setup_phase_instruction_that(
             validate_pre_sds_initial_action=DO_RAISES_EXCEPTION),
     }
     # ACT & ASSERT #
     self._check_and_assert_sds_is_not_created_and_stdout_is_empty(
         phase_identifier.SETUP, cases)
예제 #5
0
    def runTest(self):
        conf = self.configuration
        defined_symbol = data_symbol_utils.string_symbol_definition('symbol_name')
        error_message_for_failed_restriction = 'error message'
        reference_with_restriction_failure = SymbolReference(
            defined_symbol.name,
            ReferenceRestrictionsOnDirectAndIndirect(
                direct=value_restriction_that_is_unconditionally_unsatisfied(error_message_for_failed_restriction)))

        test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \
            .add(PartialPhase.SETUP,
                 setup_phase_instruction_that(symbol_usages=do_return([defined_symbol]))) \
            .add(conf.phase,
                 conf.instruction_that_returns([reference_with_restriction_failure]))

        execute_test_case_with_recording(
            self,
            Arrangement(test_case),
            Expectation(
                asrt_result.matches2(
                    PartialExeResultStatus.VALIDATION_ERROR,
                    asrt_result.has_no_sds(),
                    asrt_result.has_no_action_to_check_outcome(),
                    ExpectedFailureForInstructionFailure.new_with_phase_and_message_assertion(
                        conf.step,
                        asrt.equals(error_message_for_failed_restriction)),
                ),
                conf.expected_steps_before_failing_instruction,
            )
        )
예제 #6
0
 def _test_case(self) -> test_case_doc.TestCase:
     return full_test_case_with_instructions(
         [configuration_phase_instruction_that(
             main_initial_action=_RecordCurrDir(self.recorder,
                                                phase_step.CONFIGURATION__MAIN).call)],
         [setup_phase_instruction_that(
             validate_post_setup_initial_action=_RecordCurrDir(self.recorder,
                                                               phase_step.SETUP__VALIDATE_POST_SETUP),
             main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder,
                                                                        phase_step.SETUP__MAIN))],
         [act_phase_instruction_with_source(LineSequence(1, ('not used',)))],
         [before_assert_phase_instruction_that(
             validate_post_setup_initial_action=_RecordCurrDir(self.recorder,
                                                               phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP),
             main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder,
                                                                        phase_step.BEFORE_ASSERT__MAIN))],
         [assert_phase_instruction_that(
             validate_post_setup_initial_action=_RecordCurrDir(self.recorder,
                                                               phase_step.ASSERT__VALIDATE_POST_SETUP),
             main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder,
                                                                        phase_step.ASSERT__MAIN))],
         [cleanup_phase_instruction_that(
             main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder,
                                                                        phase_step.CLEANUP__MAIN))],
     )
예제 #7
0
 def test_hard_error_in_setup_main_step(self):
     py_pgm_setup = PyProgramSetup('some output to stdout',
                                   'some output to stderr',
                                   72)
     test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr(
         act_phase_source=py_pgm_setup.as_line_sequence()) \
         .add(PartialPhase.SETUP,
              test.setup_phase_instruction_that(
                  main=do_return(sh.new_sh_hard_error('hard error msg from setup'))))
     self._check(
         arr_for_py3_source(test_case),
         Expectation(
             asrt_result.matches2(
                 PartialExeResultStatus.HARD_ERROR,
                 asrt_result.has_sds(),
                 asrt_result.has_no_action_to_check_outcome(),
                 ExpectedFailureForInstructionFailure.new_with_message(
                     phase_step.SETUP__MAIN,
                     test_case.the_extra(PartialPhase.SETUP)[0].source,
                     'hard error msg from setup'),
             ),
             atc_stdout_output=asrt.equals(''),
             atc_stderr_output=asrt.equals(''),
             step_recordings=
             [phase_step.ACT__PARSE] +
             SYMBOL_VALIDATION_STEPS__TWICE +
             PRE_SDS_VALIDATION_STEPS__TWICE +
             [phase_step.SETUP__MAIN,
              (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
              (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
              ],
         ))
예제 #8
0
 def test_hard_error_in_setup_main_step(self):
     test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \
         .add(PartialPhase.SETUP,
              test.setup_phase_instruction_that(
                  main=do_return(sh.new_sh_hard_error('hard error msg from setup'))))
     self._check(
         Arrangement(test_case),
         Expectation(
             asrt_result.matches2(
                 PartialExeResultStatus.HARD_ERROR,
                 asrt_result.has_sds(),
                 asrt_result.has_no_action_to_check_outcome(),
                 ExpectedFailureForInstructionFailure.new_with_message(
                     phase_step.SETUP__MAIN,
                     test_case.the_extra(PartialPhase.SETUP)[0].source,
                     'hard error msg from setup'),
             ),
             [phase_step.ACT__PARSE] +
             SYMBOL_VALIDATION_STEPS__TWICE +
             PRE_SDS_VALIDATION_STEPS__TWICE +
             [phase_step.SETUP__MAIN,
              (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
              (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
              ],
         ))
예제 #9
0
 def test_hard_error_in_setup_main_step(self):
     py_pgm_setup = PyProgramSetup('some output to stdout',
                                   'some output to stderr', 72)
     test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr(
         act_phase_source=py_pgm_setup.as_line_sequence()) \
         .add(PartialPhase.SETUP,
              test.setup_phase_instruction_that(
                  main=do_return(sh.new_sh_hard_error__str('hard error msg from setup'))))
     self._check(
         arr_for_py3_source(test_case),
         Expectation(
             asrt_result.matches2(
                 ExecutionFailureStatus.HARD_ERROR,
                 asrt_result.has_sds(),
                 asrt_result.has_no_action_to_check_outcome(),
                 ExpectedFailureForInstructionFailure.new_with_message(
                     phase_step.SETUP__MAIN,
                     test_case.the_extra(PartialPhase.SETUP)[0].source,
                     'hard error msg from setup'),
             ),
             atc_stdout_output=asrt.equals(''),
             atc_stderr_output=asrt.equals(''),
             step_recordings=[phase_step.ACT__PARSE] +
             SYMBOL_VALIDATION_STEPS__TWICE +
             PRE_SDS_VALIDATION_STEPS__TWICE + [
                 phase_step.SETUP__MAIN,
                 (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
                 (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
             ],
         ))
예제 #10
0
    def test_implementation_error_in_setup_main_step(self):
        test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \
            .add(PartialPhase.SETUP,
                 test.setup_phase_instruction_that(
                     main=do_raise(test.ImplementationErrorTestException())))
        self._check(
            Arrangement(test_case,
                        act_executor_execute=execute_action_that_returns_exit_code(5)),
            Expectation(
                asrt_result.matches2(
                    PartialExeResultStatus.IMPLEMENTATION_ERROR,
                    asrt_result.has_sds(),
                    asrt_result.has_no_action_to_check_outcome(),
                    ExpectedFailureForInstructionFailure.new_with_exception(
                        phase_step.SETUP__MAIN,
                        test_case.the_extra(PartialPhase.SETUP)[0].source,
                        test.ImplementationErrorTestException),
                ),
                [phase_step.ACT__PARSE] +

                SYMBOL_VALIDATION_STEPS__TWICE +
                PRE_SDS_VALIDATION_STEPS__TWICE +
                [phase_step.SETUP__MAIN,
                 (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
                 (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
                 ],
            ))
예제 #11
0
    def test_that_symbols_from_arrangement_exist_in_environment(self):
        symbol_name = 'symbol_name_in_setup_phase'
        symbol_value = 'the symbol value in setup phase'
        symbol_table_of_arrangement = data_symbol_utils.symbol_table_with_single_string_value(symbol_name,
                                                                                              symbol_value)
        expected_symbol_table = data_symbol_utils.symbol_table_with_single_string_value(symbol_name,
                                                                                        symbol_value)
        assertion_for_validation = do_fail_if_symbol_table_does_not_equal(
            self,
            expected_symbol_table,
            get_symbol_table_from_path_resolving_environment_that_is_first_arg)

        assertion_for_main = do_fail_if_symbol_table_does_not_equal(
            self,
            expected_symbol_table,
            get_symbol_table_from_instruction_environment_that_is_first_arg)

        self._check(
            utils.ParserThatGives(
                setup_phase_instruction_that(
                    validate_pre_sds_initial_action=assertion_for_validation,
                    validate_post_setup_initial_action=assertion_for_validation,
                    main_initial_action=assertion_for_main,
                )),
            utils.single_line_source(),
            sut.Arrangement(symbols=symbol_table_of_arrangement),
            sut.Expectation(),
        )
예제 #12
0
 def test_internal_error(self):
     test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \
         .add(PartialPhase.SETUP,
              test.setup_phase_instruction_that(
                  main=do_raise(test.ImplementationErrorTestException())))
     self._check(
         Arrangement(test_case,
                     atc_execute=execute_action_that_returns_exit_code(5)),
         Expectation(
             asrt_result.matches2(
                 ExecutionFailureStatus.INTERNAL_ERROR,
                 asrt_result.has_sds(),
                 asrt_result.has_no_action_to_check_outcome(),
                 ExpectedFailureForInstructionFailure.new_with_exception(
                     phase_step.SETUP__MAIN,
                     test_case.the_extra(PartialPhase.SETUP)[0].source,
                     test.ImplementationErrorTestException),
             ),
             [phase_step.ACT__PARSE] + SYMBOL_VALIDATION_STEPS__TWICE +
             PRE_SDS_VALIDATION_STEPS__TWICE + [
                 phase_step.SETUP__MAIN,
                 (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
                 (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
             ],
         ))
예제 #13
0
 def _test_case(self) -> test_case_doc.TestCase:
     return full_test_case_with_instructions(
         [configuration_phase_instruction_that(
             main_initial_action=_RecordCurrDir(self.recorder,
                                                phase_step.CONFIGURATION__MAIN))],
         [setup_phase_instruction_that(
             validate_post_setup_initial_action=_RecordCurrDir(self.recorder,
                                                               phase_step.SETUP__VALIDATE_POST_SETUP),
             main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder,
                                                                        phase_step.SETUP__MAIN))],
         [act_phase_instruction_with_source(LineSequence(1, ('not used',)))],
         [before_assert_phase_instruction_that(
             validate_post_setup_initial_action=_RecordCurrDir(self.recorder,
                                                               phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP),
             main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder,
                                                                        phase_step.BEFORE_ASSERT__MAIN))],
         [assert_phase_instruction_that(
             validate_post_setup_initial_action=_RecordCurrDir(self.recorder,
                                                               phase_step.ASSERT__VALIDATE_POST_SETUP),
             main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder,
                                                                        phase_step.ASSERT__MAIN))],
         [cleanup_phase_instruction_that(
             main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder,
                                                                        phase_step.CLEANUP__MAIN))],
     )
    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')
예제 #15
0
    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)
예제 #16
0
def setup_phase_instruction_that_records_property_of_env_for_each_step(
        property_recorder: PropertyRecorderBuilder) -> SetupPhaseInstruction:
    return setup_phase_instruction_that(
        validate_pre_sds_initial_action=property_recorder.of_first_arg(
            step.SETUP__VALIDATE_PRE_SDS),
        validate_post_setup_initial_action=property_recorder.of_first_arg(
            step.SETUP__VALIDATE_POST_SETUP),
        main_initial_action=property_recorder.of_first_arg(step.SETUP__MAIN))
예제 #17
0
def setup_phase_instruction_that_records_a_value_per_step(
        recorder_for) -> SetupPhaseInstruction:
    return setup_phase_instruction_that(
        validate_pre_sds_initial_action=recorder_for(
            step.SETUP__VALIDATE_PRE_SDS),
        main_initial_action=recorder_for(step.SETUP__MAIN),
        validate_post_setup_initial_action=recorder_for(
            step.SETUP__VALIDATE_POST_SETUP),
    )
    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')
예제 #19
0
 def _test_case(self) -> test_case_doc.TestCase:
     return full_test_case_with_instructions(
         [
             configuration_phase_instruction_that(
                 main_initial_action=
                 _ConfigurationPhaseActionThatSetsHdsCaseDirToParent()),
             configuration_phase_instruction_that(
                 main_initial_action=
                 _ConfigurationPhaseActionThatSetsHdsActDirToParentParent())
         ],
         [
             setup_phase_instruction_that(
                 validate_pre_sds_initial_action=_RecordEnvVars(
                     self.recorder,
                     phase_step.SETUP__VALIDATE_PRE_SDS).call,
                 validate_post_setup_initial_action=_RecordEnvVars(
                     self.recorder,
                     phase_step.SETUP__VALIDATE_POST_SETUP).call,
                 main_initial_action=_RecordEnvVars(
                     self.recorder, phase_step.SETUP__MAIN).setup_main)
         ],
         [],
         [
             before_assert_phase_instruction_that(
                 validate_pre_sds_initial_action=_RecordEnvVars(
                     self.recorder,
                     phase_step.BEFORE_ASSERT__VALIDATE_PRE_SDS).call,
                 validate_post_setup_initial_action=_RecordEnvVars(
                     self.recorder,
                     phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP).call,
                 main_initial_action=_RecordEnvVars(
                     self.recorder,
                     phase_step.BEFORE_ASSERT__MAIN).non_setup_main)
         ],
         [
             assert_phase_instruction_that(
                 validate_pre_sds_initial_action=_RecordEnvVars(
                     self.recorder,
                     phase_step.ASSERT__VALIDATE_PRE_SDS).call,
                 validate_post_setup_initial_action=_RecordEnvVars(
                     self.recorder,
                     phase_step.ASSERT__VALIDATE_POST_SETUP).call,
                 main_initial_action=_RecordEnvVars(
                     self.recorder, phase_step.ASSERT__MAIN).non_setup_main)
         ],
         [
             cleanup_phase_instruction_that(
                 validate_pre_sds_initial_action=_RecordEnvVars(
                     self.recorder,
                     phase_step.CLEANUP__VALIDATE_PRE_SDS).call,
                 main_initial_action=_RecordEnvVars(
                     self.recorder,
                     phase_step.CLEANUP__MAIN).non_setup_main)
         ],
     )
예제 #20
0
 def test_that_default_expectation_assumes_no_symbol_usages(self):
     with self.assertRaises(utils.TestError):
         unexpected_symbol_usages = [data_symbol_utils.symbol_reference('symbol_name')]
         self._check(
             utils.ParserThatGives(
                 setup_phase_instruction_that(
                     symbol_usages=do_return(unexpected_symbol_usages))),
             single_line_source(),
             sut.Arrangement(),
             sut.Expectation(),
         )
예제 #21
0
 def test_failure(self):
     with self.assertRaises(utils.TestError):
         self._check(
             utils.ParserThatGives(setup_phase_instruction_that()),
             single_line_source(),
             sut.Arrangement(
                 settings_builder=SetupSettingsBuilder.new_empty()),
             sut.Expectation(settings_builder=asrt.sub_component(
                 'stdin', lambda model: model.actual.stdin,
                 asrt.is_not_none)),
         )
예제 #22
0
 def new_setup_instruction(self,
                           value_for_symbol_usages,
                           value_for_validate_pre_sds,
                           value_for_main,
                           value_for_validate_post_sds,
                           ) -> SetupPhaseInstruction:
     return setup_phase_instruction_that(
         symbol_usages_initial_action=self._do_record_first_invokation(value_for_symbol_usages),
         validate_pre_sds=self._do_record_and_return_svh(value_for_validate_pre_sds),
         validate_post_setup=self._do_record_and_return_svh(
             value_for_validate_post_sds),
         main=self._do_record_and_return_sh(value_for_main))
예제 #23
0
 def test_that_fails_due_to_missing_symbol_reference(self):
     with self.assertRaises(utils.TestError):
         symbol_usages_of_instruction = []
         symbol_usages_of_expectation = [data_symbol_utils.symbol_reference('symbol_name')]
         self._check(
             utils.ParserThatGives(
                 setup_phase_instruction_that(
                     symbol_usages=do_return(symbol_usages_of_instruction))),
             single_line_source(),
             sut.Arrangement(),
             sut.Expectation(
                 symbol_usages=sym_asrt.equals_symbol_references(symbol_usages_of_expectation)),
         )
예제 #24
0
 def test_that_default_expectation_assumes_no_symbol_usages(self):
     with self.assertRaises(utils.TestError):
         unexpected_symbol_usages = [
             data_references.reference_to__on_direct_and_indirect(
                 'symbol_name')
         ]
         self._check(
             utils.ParserThatGives(
                 setup_phase_instruction_that(
                     symbol_usages=do_return(unexpected_symbol_usages))),
             single_line_source(),
             sut.Arrangement(),
             sut.Expectation(),
         )
예제 #25
0
 def new_setup_instruction(
     self,
     value_for_symbol_usages,
     value_for_validate_pre_sds,
     value_for_main,
     value_for_validate_post_sds,
 ) -> SetupPhaseInstruction:
     return setup_phase_instruction_that(
         symbol_usages_initial_action=self._do_record_first_invokation(
             value_for_symbol_usages),
         validate_pre_sds=self._do_record_and_return_svh(
             value_for_validate_pre_sds),
         validate_post_setup=self._do_record_and_return_svh(
             value_for_validate_post_sds),
         main=self._do_record_and_return_sh(value_for_main))
예제 #26
0
 def test_that_fails_due_to_missing_symbol_reference(self):
     with self.assertRaises(utils.TestError):
         symbol_usages_of_instruction = []
         self._check(
             utils.ParserThatGives(
                 setup_phase_instruction_that(symbol_usages=do_return(
                     symbol_usages_of_instruction))),
             single_line_source(),
             sut.Arrangement(),
             sut.Expectation(symbol_usages=asrt.matches_singleton_sequence(
                 matches_data_type_symbol_reference(
                     'symbol_name',
                     reference_restrictions.is_any_type_w_str_rendering()))
                             ),
         )
예제 #27
0
 def test_instruction_environment_specifies_correct_log_dir_for_each_phase(self):
     recorder = {}
     test_case = partial_test_case_with_instructions(
         [setup_phase_instruction_that(main_initial_action=RecordLogDirForPhase(PhaseEnum.SETUP, recorder))],
         [act_phase_instruction_with_source(LineSequence(1, ('line',)))],
         [before_assert_phase_instruction_that(main_initial_action=RecordLogDirForPhase(PhaseEnum.BEFORE_ASSERT,
                                                                                        recorder))],
         [assert_phase_instruction_that(main_initial_action=RecordLogDirForPhase(PhaseEnum.ASSERT, recorder))],
         [cleanup_phase_instruction_that(main_initial_action=RecordLogDirForPhase(PhaseEnum.CLEANUP, recorder))],
     )
     test(
         self,
         test_case,
         dummy_actor(),
         functools.partial(log_dir_is_correct_for_each_phase, recorder),
         is_keep_sandbox=False)
예제 #28
0
def instruction_set() -> InstructionsSetup:
    return InstructionsSetup(
        config_instruction_set=dict(
            [instruction_item('conf_instruction',
                              instr.configuration_phase_instruction_that())]),
        setup_instruction_set=dict(
            [instruction_item('setup_instruction',
                              instr.setup_phase_instruction_that())]),
        before_assert_instruction_set=dict(
            [instruction_item('before_assert_instruction',
                              instr.before_assert_phase_instruction_that())]),
        assert_instruction_set=dict(
            [instruction_item('assert_instruction',
                              instr.assert_phase_instruction_that())]),
        cleanup_instruction_set=dict(
            [instruction_item('cleanup_instruction',
                              instr.cleanup_phase_instruction_that())]),
    )
예제 #29
0
 def test_hard_error_exception(self):
     test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \
         .add(PartialPhase.SETUP,
              test.setup_phase_instruction_that(
                  main=do_raise(hard_error_ex('hard error exception msg from setup'))))
     self._check(
         Arrangement(test_case),
         Expectation(
             asrt_result.matches2(
                 ExecutionFailureStatus.HARD_ERROR,
                 asrt_result.has_sds(),
                 asrt_result.has_no_action_to_check_outcome(),
                 ExpectedFailureForInstructionFailure.new_with_message(
                     phase_step.SETUP__MAIN,
                     test_case.the_extra(PartialPhase.SETUP)[0].source,
                     'hard error exception msg from setup'),
             ),
             [phase_step.ACT__PARSE] + SYMBOL_VALIDATION_STEPS__TWICE +
             PRE_SDS_VALIDATION_STEPS__TWICE + [
                 phase_step.SETUP__MAIN,
                 (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
                 (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
             ],
         ))
예제 #30
0
    def test_set_environment_variable_in_phase_setup(self):
        recorder = _RecorderOfExistenceOfGlobalEnvVar(_unique_variable_name())

        test_case = partial_test_case_with_instructions(
            [setup_phase_instruction_that(
                main_initial_action=Sequence([SetEnvironmentVariableViaInstructionArguments(recorder.variable_name),
                                              recorder.for_step(step.SETUP__MAIN)]),
                validate_post_setup_initial_action=recorder.for_step(step.SETUP__VALIDATE_POST_SETUP))],
            _act_phase_instructions_that_are_not_relevant_to_this_test(),
            [before_assert_phase_instruction_that(
                validate_post_setup_initial_action=recorder.for_step(step.BEFORE_ASSERT__VALIDATE_POST_SETUP),
                main_initial_action=recorder.for_step(step.BEFORE_ASSERT__MAIN))],
            [assert_phase_instruction_that(
                validate_post_setup_initial_action=recorder.for_step(step.ASSERT__VALIDATE_POST_SETUP),
                main_initial_action=recorder.for_step(step.ASSERT__MAIN))],
            [cleanup_phase_instruction_that(
                main_initial_action=recorder.for_step(step.CLEANUP__MAIN))],
        )
        test__va(
            self,
            test_case,
            Arrangement(
                actor=_actor_that_records_existence_of_var_in_global_env(recorder)),
            AssertPhasesWhereTheEnvironmentVariableExistsInTheGlobalEnvironmentIsEmpty(recorder.recorded_steps))
예제 #31
0
    def test_that_symbols_from_arrangement_exist_in_environment(self):
        symbol = StringConstantSymbolContext(
            'symbol_name_in_setup_phase', 'the symbol value in setup phase')
        symbol_table_of_arrangement = symbol.symbol_table
        expected_symbol_table = symbol.symbol_table
        assertion_for_validation = do_fail_if_symbol_table_does_not_equal(
            self, expected_symbol_table,
            get_symbol_table_from_path_resolving_environment_that_is_first_arg)

        assertion_for_main = do_fail_if_symbol_table_does_not_equal(
            self, expected_symbol_table,
            get_symbol_table_from_instruction_environment_that_is_first_arg)

        self._check(
            utils.ParserThatGives(
                setup_phase_instruction_that(
                    validate_pre_sds_initial_action=assertion_for_validation,
                    validate_post_setup_initial_action=assertion_for_validation,
                    main_initial_action=assertion_for_main,
                )),
            utils.single_line_source(),
            sut.Arrangement(symbols=symbol_table_of_arrangement),
            sut.Expectation(),
        )
 def _test_case(self) -> test_case_doc.TestCase:
     return full_test_case_with_instructions(
         [
             configuration_phase_instruction_that(
                 main_initial_action=_ConfigurationPhaseActionThatSetsHomeCaseDirToParent()),
             configuration_phase_instruction_that(
                 main_initial_action=_ConfigurationPhaseActionThatSetsHomeActDirToParentParent())
         ],
         [setup_phase_instruction_that(
             validate_pre_sds_initial_action=_RecordEnvVars(self.recorder,
                                                            phase_step.SETUP__VALIDATE_PRE_SDS),
             validate_post_setup_initial_action=_RecordEnvVars(self.recorder,
                                                               phase_step.SETUP__VALIDATE_POST_SETUP),
             main_initial_action=_RecordEnvVars(self.recorder,
                                                phase_step.SETUP__MAIN))],
         [],
         [before_assert_phase_instruction_that(
             validate_pre_sds_initial_action=_RecordEnvVars(self.recorder,
                                                            phase_step.BEFORE_ASSERT__VALIDATE_PRE_SDS),
             validate_post_setup_initial_action=_RecordEnvVars(self.recorder,
                                                               phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP),
             main_initial_action=_RecordEnvVars(self.recorder,
                                                phase_step.BEFORE_ASSERT__MAIN))],
         [assert_phase_instruction_that(
             validate_pre_sds_initial_action=_RecordEnvVars(self.recorder,
                                                            phase_step.ASSERT__VALIDATE_PRE_SDS),
             validate_post_setup_initial_action=_RecordEnvVars(self.recorder,
                                                               phase_step.ASSERT__VALIDATE_POST_SETUP),
             main_initial_action=_RecordEnvVars(self.recorder,
                                                phase_step.ASSERT__MAIN))],
         [cleanup_phase_instruction_that(
             validate_pre_sds_initial_action=_RecordEnvVars(self.recorder,
                                                            phase_step.CLEANUP__VALIDATE_PRE_SDS),
             main_initial_action=_RecordEnvVars(self.recorder,
                                                phase_step.CLEANUP__MAIN))],
     )
예제 #33
0
    def test_one_symbol_is_predefined_and_one_symbol_is_defined_in_the_setup_phase(self):
        predefined_symbol = NameAndValue('predefined symbol',
                                         'predefined string constant symbol value')
        defined_symbol = NameAndValue('defined symbol',
                                      'value of symbol defined in the setup phase (not used in this test)')
        predefined_symbols_table = SymbolTable({
            predefined_symbol.name: symbol_utils.container(string_resolvers.str_constant(predefined_symbol.value))
        })
        predefined_symbols = frozenset((predefined_symbol.name,))
        predefined_and_defined_symbols = frozenset((predefined_symbol.name, defined_symbol.name))

        symbol_definition = data_symbol_utils.string_symbol_definition(defined_symbol.name, defined_symbol.value)

        symbol_usages_of_instruction_that_defines_symbol = [symbol_definition]

        expected_phase_2_step_2_names_set = {
            PhaseEnum.SETUP: {
                step.SETUP__VALIDATE_PRE_SDS.step: predefined_and_defined_symbols,
                step.SETUP__MAIN.step: predefined_symbols,
                step.SETUP__VALIDATE_POST_SETUP.step: predefined_and_defined_symbols,
            },
            PhaseEnum.ACT: {
                step.ACT__VALIDATE_PRE_SDS.step: predefined_and_defined_symbols,
                step.ACT__VALIDATE_POST_SETUP.step: predefined_and_defined_symbols,
                step.ACT__PREPARE.step: predefined_and_defined_symbols,
                step.ACT__EXECUTE.step: predefined_and_defined_symbols,
            },
            PhaseEnum.BEFORE_ASSERT: {
                step.BEFORE_ASSERT__VALIDATE_PRE_SDS.step: predefined_and_defined_symbols,
                step.BEFORE_ASSERT__VALIDATE_POST_SETUP.step: predefined_and_defined_symbols,
                step.BEFORE_ASSERT__MAIN.step: predefined_and_defined_symbols,

            },
            PhaseEnum.ASSERT: {
                step.ASSERT__VALIDATE_PRE_SDS.step: predefined_and_defined_symbols,
                step.ASSERT__VALIDATE_POST_SETUP.step: predefined_and_defined_symbols,
                step.ASSERT__MAIN.step: predefined_and_defined_symbols,
            },
            PhaseEnum.CLEANUP: {
                step.CLEANUP__VALIDATE_PRE_SDS.step: predefined_and_defined_symbols,
                step.CLEANUP__MAIN.step: predefined_and_defined_symbols,
            },
        }
        actual_phase_2_step_2_names_set = psr.new_phase_enum_2_empty_dict()

        def recorder_for(phase_step: SimplePhaseStep):
            return psr.StepRecordingAction(phase_step,
                                           actual_phase_2_step_2_names_set,
                                           get_symbols_name_set_from_instruction_environment)

        test_case = partial_test_case_with_instructions(
            [
                setup_phase_instruction_that(
                    symbol_usages=do_return(symbol_usages_of_instruction_that_defines_symbol),
                    validate_pre_sds_initial_action=recorder_for(step.SETUP__VALIDATE_PRE_SDS),
                    main_initial_action=Sequence([
                        recorder_for(step.SETUP__MAIN),
                        _ActionThatSetsSymbolInSymbolTable(symbol_definition),
                    ]),
                    validate_post_setup_initial_action=recorder_for(step.SETUP__VALIDATE_POST_SETUP),
                )
            ],
            psr.act_phase_instructions_that_does_nothing(),
            [
                psr.before_assert_phase_instruction_that_records_a_value_per_step(recorder_for)
            ],
            [
                psr.assert_phase_instruction_that_records_a_value_per_step(recorder_for)
            ],
            [
                psr.cleanup_phase_instruction_that_records_a_value_per_step(recorder_for)
            ],
        )
        test__va(
            self,
            test_case,
            Arrangement(
                actor=psr.actor_that_records_a_value_per_step(recorder_for,
                                                              recorder_for_parse_step=psr.no_recording),
                predefined_symbols=predefined_symbols_table),
            asrt.anything_goes())
        _check_result(self,
                      expected_phase_2_step_2_names_set,
                      actual_phase_2_step_2_names_set)
예제 #34
0
 def instruction_with_usage(self, symbol_usages: list) -> SetupPhaseInstruction:
     return setup_phase_instruction_that(symbol_usages=do_return(symbol_usages))
예제 #35
0
def mk_setup_phase_recording_instruction(main_action: SetupMainInitialAction) -> SetupPhaseInstruction:
    return setup_phase_instruction_that(main_initial_action=main_action)
예제 #36
0
 def setup_instr_setup(self) -> SingleInstructionSetup:
     return instr_setup(instr.setup_phase_instruction_that(
         main_initial_action=append_section_name_action(self.recording_output, phase_identifier.SETUP))
     )
예제 #37
0
 def setup_instr_setup(self) -> SingleInstructionSetup:
     return instr_setup(
         instr.setup_phase_instruction_that(
             main_initial_action=append_section_name_action(
                 self.recording_output, phase_identifier.SETUP)))
예제 #38
0
 def setup_instr_setup(self) -> SingleInstructionSetup:
     return instr_setup(instr.setup_phase_instruction_that(
         main_initial_action=do_raise(ImplementationError())
     ))
예제 #39
0
def setup_phase_instruction_that_records_a_value_per_step(recorder_for) -> SetupPhaseInstruction:
    return setup_phase_instruction_that(
        validate_pre_sds_initial_action=recorder_for(step.SETUP__VALIDATE_PRE_SDS),
        main_initial_action=recorder_for(step.SETUP__MAIN),
        validate_post_setup_initial_action=recorder_for(step.SETUP__VALIDATE_POST_SETUP),
    )
예제 #40
0
 def instruction_that_returns(self, return_value: svh.SuccessOrValidationErrorOrHardError) -> TestCaseInstruction:
     return test.setup_phase_instruction_that(
         validate_pre_sds=do_return(return_value))
예제 #41
0
    def test_one_symbol_is_defined_in_the_setup_phase(self):
        symbol = NameAndValue('symbol name', 'symbol value (not used in test)')
        all_defined_symbols = frozenset((symbol.name, ))
        symbol_definition = StringConstantSymbolContext(
            symbol.name, symbol.value).definition
        symbol_usages_of_instruction_that_defines_symbol = [symbol_definition]

        expected_phase_2_step_2_names_set = {
            PhaseEnum.SETUP: {
                step.SETUP__VALIDATE_PRE_SDS.step: all_defined_symbols,
                step.SETUP__MAIN.step: set(),
                step.SETUP__VALIDATE_POST_SETUP.step: all_defined_symbols,
            },
            PhaseEnum.ACT: {
                step.ACT__VALIDATE_PRE_SDS.step: all_defined_symbols,
                step.ACT__VALIDATE_POST_SETUP.step: all_defined_symbols,
                step.ACT__EXECUTE.step: all_defined_symbols,
                step.ACT__PREPARE.step: all_defined_symbols,
            },
            PhaseEnum.BEFORE_ASSERT:
            psr.same_value_for_all_steps(step.ALL_BEFORE_ASSERT_WITH_ENV_ARG,
                                         all_defined_symbols),
            PhaseEnum.ASSERT:
            psr.same_value_for_all_steps(step.ALL_ASSERT_WITH_ENV_ARG,
                                         all_defined_symbols),
            PhaseEnum.CLEANUP:
            psr.same_value_for_all_steps(step.ALL_CLEANUP_WITH_ENV_ARG,
                                         all_defined_symbols),
        }
        actual_phase_2_step_2_names_set = psr.new_phase_enum_2_empty_dict()

        def recorder_for(phase_step: SimplePhaseStep):
            return psr.StepRecordingAction(
                phase_step, actual_phase_2_step_2_names_set,
                get_symbols_name_set_from_instruction_environment)

        test_case = partial_test_case_with_instructions(
            [
                setup_phase_instruction_that(
                    symbol_usages=do_return(
                        symbol_usages_of_instruction_that_defines_symbol),
                    validate_pre_sds_initial_action=recorder_for(
                        step.SETUP__VALIDATE_PRE_SDS),
                    main_initial_action=sequence_of_actions([
                        recorder_for(step.SETUP__MAIN),
                        _ActionThatSetsSymbolInSymbolTable(symbol_definition),
                    ]),
                    validate_post_setup_initial_action=recorder_for(
                        step.SETUP__VALIDATE_POST_SETUP),
                )
            ],
            psr.act_phase_instructions_that_does_nothing(),
            [
                psr.
                before_assert_phase_instruction_that_records_a_value_per_step(
                    recorder_for)
            ],
            [
                psr.assert_phase_instruction_that_records_a_value_per_step(
                    recorder_for)
            ],
            [
                psr.cleanup_phase_instruction_that_records_a_value_per_step(
                    recorder_for)
            ],
        )
        test__va(
            self, test_case,
            Arrangement(
                psr.actor_that_records_a_value_per_step(
                    recorder_for, recorder_for_parse_step=psr.no_recording)),
            asrt.anything_goes())
        _check_result(self, expected_phase_2_step_2_names_set,
                      actual_phase_2_step_2_names_set)
예제 #42
0
def setup_phase_instruction_that_records_property_of_env_for_each_step(
        property_recorder: PropertyRecorderBuilder) -> SetupPhaseInstruction:
    return setup_phase_instruction_that(
        validate_pre_sds_initial_action=property_recorder.of_first_arg(step.SETUP__VALIDATE_PRE_SDS),
        validate_post_setup_initial_action=property_recorder.of_first_arg(step.SETUP__VALIDATE_POST_SETUP),
        main_initial_action=property_recorder.of_first_arg(step.SETUP__MAIN))
예제 #43
0
    def test_one_symbol_is_predefined_and_one_symbol_is_defined_in_the_setup_phase(
            self):
        predefined_symbol = StringSymbolContext.of_constant(
            'predefined symbol', 'predefined string constant symbol value')
        defined_symbol = StringConstantSymbolContext(
            'defined symbol',
            'value of symbol defined in the setup phase (not used in this test)'
        )
        predefined_symbols_table = predefined_symbol.symbol_table
        predefined_symbols = frozenset((predefined_symbol.name, ))
        predefined_and_defined_symbols = frozenset(
            (predefined_symbol.name, defined_symbol.name))

        symbol_definition = defined_symbol.definition

        symbol_usages_of_instruction_that_defines_symbol = [symbol_definition]

        expected_phase_2_step_2_names_set = {
            PhaseEnum.SETUP: {
                step.SETUP__VALIDATE_PRE_SDS.step:
                predefined_and_defined_symbols,
                step.SETUP__MAIN.step:
                predefined_symbols,
                step.SETUP__VALIDATE_POST_SETUP.step:
                predefined_and_defined_symbols,
            },
            PhaseEnum.ACT: {
                step.ACT__VALIDATE_PRE_SDS.step:
                predefined_and_defined_symbols,
                step.ACT__VALIDATE_POST_SETUP.step:
                predefined_and_defined_symbols,
                step.ACT__PREPARE.step: predefined_and_defined_symbols,
                step.ACT__EXECUTE.step: predefined_and_defined_symbols,
            },
            PhaseEnum.BEFORE_ASSERT: {
                step.BEFORE_ASSERT__VALIDATE_PRE_SDS.step:
                predefined_and_defined_symbols,
                step.BEFORE_ASSERT__VALIDATE_POST_SETUP.step:
                predefined_and_defined_symbols,
                step.BEFORE_ASSERT__MAIN.step: predefined_and_defined_symbols,
            },
            PhaseEnum.ASSERT: {
                step.ASSERT__VALIDATE_PRE_SDS.step:
                predefined_and_defined_symbols,
                step.ASSERT__VALIDATE_POST_SETUP.step:
                predefined_and_defined_symbols,
                step.ASSERT__MAIN.step: predefined_and_defined_symbols,
            },
            PhaseEnum.CLEANUP: {
                step.CLEANUP__VALIDATE_PRE_SDS.step:
                predefined_and_defined_symbols,
                step.CLEANUP__MAIN.step: predefined_and_defined_symbols,
            },
        }
        actual_phase_2_step_2_names_set = psr.new_phase_enum_2_empty_dict()

        def recorder_for(phase_step: SimplePhaseStep):
            return psr.StepRecordingAction(
                phase_step, actual_phase_2_step_2_names_set,
                get_symbols_name_set_from_instruction_environment)

        test_case = partial_test_case_with_instructions(
            [
                setup_phase_instruction_that(
                    symbol_usages=do_return(
                        symbol_usages_of_instruction_that_defines_symbol),
                    validate_pre_sds_initial_action=recorder_for(
                        step.SETUP__VALIDATE_PRE_SDS),
                    main_initial_action=sequence_of_actions([
                        recorder_for(step.SETUP__MAIN),
                        _ActionThatSetsSymbolInSymbolTable(symbol_definition),
                    ]),
                    validate_post_setup_initial_action=recorder_for(
                        step.SETUP__VALIDATE_POST_SETUP),
                )
            ],
            psr.act_phase_instructions_that_does_nothing(),
            [
                psr.
                before_assert_phase_instruction_that_records_a_value_per_step(
                    recorder_for)
            ],
            [
                psr.assert_phase_instruction_that_records_a_value_per_step(
                    recorder_for)
            ],
            [
                psr.cleanup_phase_instruction_that_records_a_value_per_step(
                    recorder_for)
            ],
        )
        test__va(
            self, test_case,
            Arrangement(actor=psr.actor_that_records_a_value_per_step(
                recorder_for, recorder_for_parse_step=psr.no_recording),
                        predefined_symbols=predefined_symbols_table),
            asrt.anything_goes())
        _check_result(self, expected_phase_2_step_2_names_set,
                      actual_phase_2_step_2_names_set)
예제 #44
0
파일: setup.py 프로젝트: emilkarlen/exactly
 def instruction_with_usage(self, symbol_usages: list) -> SetupPhaseInstruction:
     return setup_phase_instruction_that(symbol_usages=do_return(symbol_usages))
예제 #45
0
    def test_one_symbol_is_defined_in_the_setup_phase(self):
        symbol = NameAndValue('symbol name',
                              'symbol value (not used in test)')
        all_defined_symbols = frozenset((symbol.name,))
        symbol_definition = data_symbol_utils.string_symbol_definition(symbol.name, symbol.value)
        symbol_usages_of_instruction_that_defines_symbol = [symbol_definition]

        expected_phase_2_step_2_names_set = {
            PhaseEnum.SETUP: {
                step.SETUP__VALIDATE_PRE_SDS.step: all_defined_symbols,
                step.SETUP__MAIN.step: set(),
                step.SETUP__VALIDATE_POST_SETUP.step: all_defined_symbols,
            },
            PhaseEnum.ACT: {
                step.ACT__VALIDATE_PRE_SDS.step: all_defined_symbols,
                step.ACT__VALIDATE_POST_SETUP.step: all_defined_symbols,
                step.ACT__EXECUTE.step: all_defined_symbols,
                step.ACT__PREPARE.step: all_defined_symbols,
            },
            PhaseEnum.BEFORE_ASSERT: psr.same_value_for_all_steps(step.ALL_BEFORE_ASSERT_WITH_ENV_ARG,
                                                                  all_defined_symbols),
            PhaseEnum.ASSERT: psr.same_value_for_all_steps(step.ALL_ASSERT_WITH_ENV_ARG, all_defined_symbols),
            PhaseEnum.CLEANUP: psr.same_value_for_all_steps(step.ALL_CLEANUP_WITH_ENV_ARG, all_defined_symbols),
        }
        actual_phase_2_step_2_names_set = psr.new_phase_enum_2_empty_dict()

        def recorder_for(phase_step: SimplePhaseStep):
            return psr.StepRecordingAction(phase_step,
                                           actual_phase_2_step_2_names_set,
                                           get_symbols_name_set_from_instruction_environment)

        test_case = partial_test_case_with_instructions(
            [
                setup_phase_instruction_that(
                    symbol_usages=do_return(symbol_usages_of_instruction_that_defines_symbol),
                    validate_pre_sds_initial_action=recorder_for(step.SETUP__VALIDATE_PRE_SDS),
                    main_initial_action=Sequence([
                        recorder_for(step.SETUP__MAIN),
                        _ActionThatSetsSymbolInSymbolTable(symbol_definition),
                    ]),
                    validate_post_setup_initial_action=recorder_for(step.SETUP__VALIDATE_POST_SETUP),
                )
            ],
            psr.act_phase_instructions_that_does_nothing(),
            [
                psr.before_assert_phase_instruction_that_records_a_value_per_step(recorder_for)
            ],
            [
                psr.assert_phase_instruction_that_records_a_value_per_step(recorder_for)
            ],
            [
                psr.cleanup_phase_instruction_that_records_a_value_per_step(recorder_for)
            ],
        )
        test__va(
            self,
            test_case,
            Arrangement(psr.actor_that_records_a_value_per_step(recorder_for,
                                                                recorder_for_parse_step=psr.no_recording)),
            asrt.anything_goes())
        _check_result(self,
                      expected_phase_2_step_2_names_set,
                      actual_phase_2_step_2_names_set)
예제 #46
0
 def _setup_phase(self) -> list:
     return self._phase_elements(
         lambda main: setup_phase_instruction_that(main=main),
         PhaseEnum.SETUP)
예제 #47
0
 def setup_instr_setup(self) -> SingleInstructionSetup:
     return instr_setup(instr.setup_phase_instruction_that(
         validate_pre_sds=self.do_return_validation_error
     ))
예제 #48
0
        populated_dir_contents = DirContents([empty_file('sds-file.txt')])
        self._check(
            PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
            single_line_source(),
            sut.Arrangement(
                sds_contents_before_main=sds_populator.contents_in(
                    sds_populator.RelSdsOptionType.REL_TMP,
                    populated_dir_contents)),
            sut.Expectation(
                main_side_effects_on_sds=tmp_user_dir_contains_exactly(
                    populated_dir_contents)),
        )


PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION = utils.ParserThatGives(
    setup_phase_instruction_that())


class TestSymbols(TestCaseBase):
    def test_that_symbols_from_arrangement_exist_in_environment(self):
        symbol_name = 'symbol_name_in_setup_phase'
        symbol_value = 'the symbol value in setup phase'
        symbol_table_of_arrangement = data_symbol_utils.symbol_table_with_single_string_value(symbol_name,
                                                                                              symbol_value)
        expected_symbol_table = data_symbol_utils.symbol_table_with_single_string_value(symbol_name,
                                                                                        symbol_value)
        assertion_for_validation = do_fail_if_symbol_table_does_not_equal(
            self,
            expected_symbol_table,
            get_symbol_table_from_path_resolving_environment_that_is_first_arg)
예제 #49
0
 def setup_instr_setup(self) -> SingleInstructionSetup:
     return instr_setup(
         instr.setup_phase_instruction_that(
             main_initial_action=do_raise(ImplementationError())))
예제 #50
0
            sut.Arrangement(
                default_environ_getter=default_environ_getter,
                process_execution_settings=ProcessExecutionSettings.
                from_non_immutable(environ=default_environs),
            ),
            sut.Expectation(instruction_settings=asrt_instr_settings.matches(
                environ=asrt.equals(default_environs),
                return_value_from_default_getter=asrt.equals(
                    default_from_default_getter)),
                            proc_exe_settings=asrt_pes.matches(
                                environ=asrt.equals(default_environs))),
        )


PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION = utils.ParserThatGives(
    setup_phase_instruction_that())


class TestSymbols(TestCaseBase):
    def test_that_symbols_from_arrangement_exist_in_environment(self):
        symbol = StringConstantSymbolContext(
            'symbol_name_in_setup_phase', 'the symbol value in setup phase')
        symbol_table_of_arrangement = symbol.symbol_table
        expected_symbol_table = symbol.symbol_table
        assertion_for_validation = do_fail_if_symbol_table_does_not_equal(
            self, expected_symbol_table,
            get_symbol_table_from_path_resolving_environment_that_is_first_arg)

        assertion_for_main = do_fail_if_symbol_table_does_not_equal(
            self, expected_symbol_table,
            get_symbol_table_from_instruction_environment_that_is_first_arg)
예제 #51
0
 def setup_instr_setup(self) -> SingleInstructionSetup:
     return instr_setup(
         instr.setup_phase_instruction_that(
             validate_pre_sds=self.do_return_validation_error))
예제 #52
0
파일: basic.py 프로젝트: emilkarlen/exactly
 def _setup_phase(self) -> list:
     return self._phase_elements(lambda main: setup_phase_instruction_that(main=main),
                                 PhaseEnum.SETUP)
예제 #53
0
 def instruction_that_raises(self, exception: Exception) -> TestCaseInstruction:
     return test.setup_phase_instruction_that(symbol_usages=do_raise(exception))
예제 #54
0
 def instruction_that_returns(self, return_value: svh.SuccessOrValidationErrorOrHardError) -> TestCaseInstruction:
     return test.setup_phase_instruction_that(
         validate_pre_sds=do_return(return_value))
예제 #55
0
        raise SingleInstructionInvalidArgumentException('Not a symbol type: ' + type_ident)


def _ref_instruction_setup(instruction_name: str,
                           mk_instruction: Callable[[List[SymbolUsage]], model.Instruction]
                           ) -> SingleInstructionSetup:
    return instruction_setup.single_instruction_setup_for_parser(instruction_name,
                                                                 _ReferenceParser(mk_instruction))


INSTRUCTION_SETUP = InstructionsSetup(
    setup_instruction_set={
        DEF_INSTRUCTION_NAME: define_symbol__setup.setup(DEF_INSTRUCTION_NAME),
        REF_INSTRUCTION_NAME: _ref_instruction_setup(
            REF_INSTRUCTION_NAME,
            lambda usages: instrs.setup_phase_instruction_that(symbol_usages=do_return(usages))),
    },
    before_assert_instruction_set={
        DEF_INSTRUCTION_NAME: define_symbol__before_assert.setup(DEF_INSTRUCTION_NAME),
        REF_INSTRUCTION_NAME: _ref_instruction_setup(
            REF_INSTRUCTION_NAME,
            lambda usages: instrs.before_assert_phase_instruction_that(symbol_usages=do_return(usages))),
    },
    assert_instruction_set={
        DEF_INSTRUCTION_NAME: define_symbol__assert.setup(DEF_INSTRUCTION_NAME),
        REF_INSTRUCTION_NAME: _ref_instruction_setup(
            REF_INSTRUCTION_NAME,
            lambda usages: instrs.assert_phase_instruction_that(symbol_usages=do_return(usages))),
    },
    cleanup_instruction_set={
        DEF_INSTRUCTION_NAME: define_symbol__cleanup.setup(DEF_INSTRUCTION_NAME),
예제 #56
0
 def instruction_that_raises(self, exception: Exception) -> TestCaseInstruction:
     return test.setup_phase_instruction_that(validate_pre_sds=do_raise(exception))
예제 #57
0
 def instruction_that_raises(self, exception: Exception) -> TestCaseInstruction:
     return test.setup_phase_instruction_that(validate_pre_sds=do_raise(exception))
def mk_setup_phase_recording_instruction(main_action: Callable) -> SetupPhaseInstruction:
    return setup_phase_instruction_that(main_initial_action=main_action)
예제 #59
0
 def mk_instruction_with_main_action(self, main_action: Callable) -> Instruction:
     return setup_phase_instruction_that(main_initial_action=main_action)