Пример #1
0
 def test_all_variables(self):
     # ARRANGE #
     with tcds_with_act_as_curr_dir() as path_resolving_env_pre_or_post_sds:
         tcds = path_resolving_env_pre_or_post_sds.tcds
         generator = ReplacedSymbolsFileContentsGeneratorWithAllReplacedVariables(
         )
         # ACT #
         actual = _transform_string_to_string(
             tcds, generator.contents_before_replacement(tcds))
         # ASSERT #
         expected = generator.expected_contents_after_replacement(tcds)
         self.assertEqual(expected, actual)
Пример #2
0
 def runTest(self):
     # ARRANGE #
     conf = self.configuration
     arguments_str = _exe_file_syntax_str(conf, 'file.exe',
                                          'remaining args')
     source = ParseSource(arguments_str)
     # ACT #
     exe_file = parse_executable_file_path.parser().parse(source)
     # ASSERT #
     source_assertion = has_remaining_part_of_first_line('remaining args')
     source_assertion.apply_with_message(self, source, 'source after parse')
     symbols = empty_symbol_table()
     self._check_existence_pre_sds(exe_file, symbols)
     with tcds_with_act_as_curr_dir(symbols=symbols) as environment:
         self._check_file_path('file.exe', exe_file, environment)
         self._assert_does_not_pass_validation(exe_file, environment)
Пример #3
0
 def _check(self, arguments_str: str,
            expected_source_after_parse: Assertion[ParseSource],
            expectation_on_exe_file: ExpectationOnExeFile,
            validator_expectation: validation.Expectation):
     # ARRANGE #
     source = ParseSource(arguments_str)
     # ACT #
     exe_file = sut.parser().parse(source)
     # ASSERT #
     utils.check_exe_file(self, expectation_on_exe_file, exe_file)
     expected_source_after_parse.apply_with_message(self, source,
                                                    'parse source')
     exe_file_command = command_sdvs.for_executable_file(exe_file)
     with tcds_with_act_as_curr_dir() as environment:
         actual_validator = ddv_validators.all_of(
             exe_file_command.resolve(environment.symbols).validators)
         assertion = ddv_assertions.DdvValidationAssertion.of_expectation(
             validator_expectation, environment.tcds)
         assertion.apply_with_message(self, actual_validator, 'validation')
Пример #4
0
def check(put: unittest.TestCase, instruction_argument_string: str,
          arrangement: Arrangement, expectation: Expectation):
    # ARRANGE #
    source = ParseSource(instruction_argument_string)
    # ACT #
    actual_exe_file = parse_executable_file_path.parser().parse(source)
    # ASSERT #
    exe_file_as_command = command_sdvs.for_executable_file(actual_exe_file)

    expectation.source.apply_with_message(put, source, 'parse source')
    check_exe_file(put, expectation.expectation_on_exe_file, actual_exe_file)
    with tcds_with_act_as_curr_dir(
            tcds_contents=arrangement.tcds_populator) as environment:
        os.mkdir('act-cwd')
        os.chdir('act-cwd')
        actual_validator = ddv_validators.all_of(
            exe_file_as_command.resolve(environment.symbols).validators)

        assertion = ddv_assertions.DdvValidationAssertion.of_expectation(
            expectation.validation_result, environment.tcds)
        assertion.apply_with_message(put, actual_validator, 'validation')
Пример #5
0
def check(put: unittest.TestCase, action: TcdsAction, arrangement: Arrangement,
          expectation: Expectation):
    with tcds_with_act_as_curr_dir(
            pre_contents_population_action=arrangement.
            pre_contents_population_action,
            hds_contents=arrangement.hds_contents_before,
            sds_contents=arrangement.sds_contents_before,
            symbols=arrangement.symbols,
    ) as environment:
        arrangement.pre_action_action.apply(environment)
        try:
            result = action.apply(environment)
        except HardErrorException as ex:
            if expectation.acton_raises_hard_error:
                text_doc_assertions.assert_is_valid_text_renderer(
                    put, ex.error)
        else:
            if expectation.acton_raises_hard_error:
                put.fail('action does not raise {}'.format(HardErrorException))

            expectation.expected_action_result.apply(put, result)

        expectation.expected_sds_contents_after.apply(put, environment.sds)
        expectation.post_action_check.apply(put, environment.tcds)
Пример #6
0
 def _tcds_and_test_as_curr_dir(
         self, file: File) -> PathResolvingEnvironmentPreOrPostSds:
     contents = self.configuration.file_installation(file)
     return tcds_with_act_as_curr_dir(tcds_contents=contents)
Пример #7
0
    def check(self, instruction: Instruction):
        self._check_instruction(CleanupPhaseInstruction, instruction)
        assert isinstance(instruction, CleanupPhaseInstruction)
        self.expectation.symbol_usages.apply_with_message(
            self.put, instruction.symbol_usages(), 'symbol-usages after parse')
        with tcds_with_act_as_curr_dir(
                pre_contents_population_action=self.arrangement.
                pre_contents_population_action,
                hds_contents=self.arrangement.hds_contents,
                sds_contents=self.arrangement.sds_contents,
                non_hds_contents=self.arrangement.non_hds_contents,
                tcds_contents=self.arrangement.tcds_contents,
                symbols=self.arrangement.symbols
        ) as path_resolving_environment:
            tcds = path_resolving_environment.tcds
            self.arrangement.post_sds_population_action.apply(
                path_resolving_environment)
            environment_builder = InstructionEnvironmentPostSdsBuilder.new_tcds(
                tcds,
                self.arrangement.symbols,
                self.arrangement.process_execution_settings,
            )

            with preserved_cwd():
                os.chdir(str(tcds.hds.case_dir))

                environment = environment_builder.build_pre_sds()

                result_of_validate_pre_sds = self._execute_pre_validate(
                    environment, instruction)
                self.expectation.symbol_usages.apply_with_message(
                    self.put, instruction.symbol_usages(),
                    'symbol-usages after ' + phase_step.STEP__VALIDATE_PRE_SDS)
                if not result_of_validate_pre_sds.is_success:
                    return

            environment = environment_builder.build_post_sds()
            instruction_settings = instr_settings.from_proc_exe_settings(
                self.arrangement.process_execution_settings,
                self.arrangement.default_environ_getter)

            result_of_main = self._execute_main(environment,
                                                instruction_settings,
                                                instruction)

            self.expectation.instruction_settings.apply_with_message(
                self.put, instruction_settings, 'instruction settings')
            self.expectation.proc_exe_settings.apply_with_message(
                self.put, environment.proc_exe_settings, 'proc exe settings')
            self.expectation.main_side_effects_on_sds.apply_with_message(
                self.put, environment.sds, 'SDS')
            self.expectation.main_side_effects_on_tcds.apply_with_message(
                self.put, tcds, 'TCDS')

        self.expectation.main_result.apply_with_message(
            self.put, result_of_main,
            'result of main (without access to TCDS)')

        self.expectation.symbol_usages.apply_with_message(
            self.put, instruction.symbol_usages(),
            'symbol-usages after ' + phase_step.STEP__MAIN)
Пример #8
0
    def execute(self):
        self.put.assertIsNotNone(self.instruction,
                                 'Result from parser cannot be None')
        self.put.assertIsInstance(
            self.instruction, SetupPhaseInstruction,
            'The instruction must be an instance of ' +
            str(SetupPhaseInstruction))
        assert isinstance(self.instruction, SetupPhaseInstruction)
        self.expectation.symbols_after_parse.apply_with_message(
            self.put, self.instruction.symbol_usages(),
            'symbol-usages after parse')

        with tcds_with_act_as_curr_dir(
                pre_contents_population_action=self.arrangement.
                pre_contents_population_action,
                hds_contents=self.arrangement.hds_contents,
                sds_contents=self.arrangement.sds_contents,
                non_hds_contents=self.arrangement.non_hds_contents,
                tcds_contents=self.arrangement.tcds_contents,
                symbols=self.arrangement.symbols
        ) as path_resolving_environment:

            self.arrangement.post_sds_population_action.apply(
                path_resolving_environment)

            environment_builder = InstructionEnvironmentPostSdsBuilder.new_tcds(
                path_resolving_environment.tcds,
                self.arrangement.symbols,
                self.arrangement.process_execution_settings,
            )

            with preserved_cwd():
                os.chdir(str(path_resolving_environment.hds.case_dir))

                environment = environment_builder.build_pre_sds()
                pre_validate_result = self._execute_pre_validate(
                    environment, self.instruction)
                self.expectation.symbols_after_parse.apply_with_message(
                    self.put, self.instruction.symbol_usages(),
                    'symbol-usages after ' + phase_step.STEP__VALIDATE_PRE_SDS)
                if not pre_validate_result.is_success:
                    return

            instruction_environment = environment_builder.build_post_sds()
            instruction_settings = instr_settings.from_proc_exe_settings(
                self.arrangement.process_execution_settings,
                self.arrangement.default_environ_getter)

            tcds = path_resolving_environment.tcds
            sds = tcds.sds

            main_result = self._execute_main(instruction_environment,
                                             instruction_settings,
                                             self.instruction)

            self.expectation.instruction_settings.apply_with_message(
                self.put, instruction_settings, 'instruction settings')
            self.expectation.main_side_effects_on_sds.apply(self.put, sds)
            self.expectation.symbols_after_main.apply_with_message(
                self.put, self.instruction.symbol_usages(),
                'symbol-usages after ' + phase_step.STEP__MAIN)
            if not main_result.is_success:
                return
            self.expectation.symbols_after_main.apply_with_message(
                self.put, instruction_environment.symbols,
                'symbols_after_main')
            self._execute_post_validate(instruction_environment,
                                        self.instruction)
            self.expectation.symbols_after_main.apply_with_message(
                self.put, self.instruction.symbol_usages(),
                'symbol-usages after ' + phase_step.STEP__VALIDATE_POST_SETUP)
            self.expectation.proc_exe_settings.apply_with_message(
                self.put, instruction_environment.proc_exe_settings,
                'proc exe settings')
            self.expectation.main_side_effects_on_tcds.apply_with_message(
                self.put, instruction_environment.tcds, 'TCDS')
            self.expectation.settings_builder.apply_with_message(
                self.put,
                SettingsBuilderAssertionModel(
                    self.arrangement.initial_settings_builder,
                    instruction_environment, self.arrangement.os_services),
                'settings builder')
        self.expectation.main_result.apply_with_message(
            self.put, main_result, 'main-result (wo access to TCDS)')