Пример #1
0
def execute_and_check(put: unittest.TestCase, arrangement: Arrangement,
                      expectation: Expectation):
    with home_directory_structure() as hds:
        with preserved_cwd():
            partial_result = sut.execute(
                arrangement.test_case,
                ExecutionConfiguration(os_environ_getter, None,
                                       arrangement.timeout_in_seconds,
                                       arrangement.os_services,
                                       sandbox_root_name_resolver.for_test(),
                                       arrangement.mem_buff_size),
                ConfPhaseValues(NameAndValue('the actor', arrangement.actor),
                                hds),
                arrangement.settings_handler,
                is_keep_sandbox=True)

            expectation.phase_result.apply_with_message(
                put, partial_result, 'phase_result')
            result = Result(hds, partial_result)
            expectation.assertion_on_sds.apply_with_message(
                put, result.partial_result.sds, 'Sandbox Directory Structure')
    # CLEANUP #
    if result is not None and result.sds is not None:
        if result.sds.root_dir.exists():
            shutil.rmtree(str(result.sds.root_dir))
Пример #2
0
    def execute(self):
        # SETUP #
        with preserved_cwd():
            with home_directory_structure() as hds:
                # ACT #
                partial_result = sut.execute(
                    self._test_case(),
                    ExecutionConfiguration(
                        os_environ_getter, None, None,
                        os_services_access.new_for_current_os(),
                        sandbox_root_name_resolver.for_test(), 2**10),
                    ConfPhaseValues(NameAndValue('the actor', self.__actor),
                                    hds), self._mk_settings_handler,
                    self.__dbg_do_not_delete_dir_structure)

                # ASSERT #
                self.__partial_result = partial_result
                self._assertions()
        # CLEANUP #
        if not self.__dbg_do_not_delete_dir_structure and self.sds:
            if self.sds.root_dir.exists():
                shutil.rmtree(str(self.sds.root_dir), ignore_errors=True)
        else:
            if self.sds:
                print(str(self.sds.root_dir))
Пример #3
0
def tcds_with_act_as_curr_dir_2(
    hds_contents: hds_populators.HdsPopulator = hds_populators.empty(),
    sds_contents: sds_populator.SdsPopulator = sds_populator.empty(),
    non_hds_contents: non_hds_populator.NonHdsPopulator = non_hds_populator.
    empty(),
    tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(),
    act_result: Optional[ActResultProducer] = None,
    pre_contents_population_action: PlainTcdsAction = PlainTcdsAction(),
    post_contents_population_action: PlainTcdsAction = PlainTcdsAction(),
) -> ContextManager[TestCaseDs]:
    prefix = strftime(program_info.PROGRAM_NAME + '-test-%Y-%m-%d-%H-%M-%S',
                      localtime())
    with home_directory_structure(prefix=prefix + '-home') as hds:
        with sandbox_directory_structure(prefix=prefix + "-sds-") as sds:
            tcds = TestCaseDs(hds, sds)
            with preserved_cwd():
                os.chdir(str(sds.act_dir))
                pre_contents_population_action.apply(tcds)
                hds_contents.populate_hds(hds)
                sds_contents.populate_sds(sds)
                non_hds_contents.populate_non_hds(sds)
                tcds_contents.populate_tcds(tcds)
                if act_result:
                    actual_act_result = act_result.apply(ActEnvironment(tcds))
                    write_act_result(tcds.sds, actual_act_result)
                post_contents_population_action.apply(tcds)
                yield tcds
 def _do_parse_and_validate_pre_sds(
     self,
     instructions: Sequence[ActPhaseInstruction],
     home_dir_contents: DirContents = empty_dir_contents()):
     with home_directory_structure(
             contents=hds_case_dir_contents(home_dir_contents)) as hds:
         pre_sds_env = InstructionEnvironmentPreSdsBuilder.of_empty_env(
             hds=hds).build
         executor = self.actor.parse(instructions)
         return executor.validate_pre_sds(pre_sds_env)
Пример #5
0
    def test_populate_hds(self):
        # ARRANGE #
        populator = sut.empty()
        expectation = f_asrt.dir_is_empty()

        with home_directory_structure() as hds:
            # ACT #
            populator.populate_hds(hds)
            # ASSERT #
            expectation.apply_with_message(self, hds.case_dir,
                                           'contents of HDS/case dir')
Пример #6
0
    def test_that_populator_is_applied(self):
        # ARRANGE #
        expected_dir_contents = fs.DirContents([fs.File('file-name.txt', 'file contents')])
        populator = hds_populators.hds_case_dir_contents(expected_dir_contents)
        expectation = f_asrt.dir_contains_exactly(expected_dir_contents)

        # ACT #
        with home_directory_structure(contents=populator) as hds:
            # ASSERT #
            expectation.apply_with_message(self, hds.case_dir,
                                           'contents of home/case dir')
Пример #7
0
    def test_populate_hds(self):
        # ARRANGE #
        expected_dir_contents = fs.DirContents([fs.File('file-name.txt', 'file contents')])
        populator = sut.hds_case_dir_contents(expected_dir_contents)
        expectation = f_asrt.dir_contains_exactly(expected_dir_contents)

        with home_directory_structure() as hds:
            # ACT #
            populator.populate_hds(hds)
            # ASSERT #
            expectation.apply_with_message(self, hds.case_dir,
                                           'contents of HDS/case dir')
Пример #8
0
    def test_no_populators_populate_hds(self):
        # ARRANGE #
        expected_dir_contents = fs.DirContents([])
        populator = sut.multiple([])
        expectation = f_asrt.dir_contains_exactly(expected_dir_contents)

        with home_directory_structure() as hds:
            # ACT #
            populator.populate_hds(hds)
            # ASSERT #
            expectation.apply_with_message(self, hds.case_dir,
                                           'contents of HDS/case dir')
 def runTest(self):
     act_phase_instructions = [instr(['system-under-test'])]
     with home_directory_structure(contents=contents_in(
             RelHdsOptionType.REL_HDS_ACT,
             fs.DirContents([fs.executable_file('system-under-test')
                             ]))) as hds:
         environment = InstructionEnvironmentPreSdsBuilder.of_empty_env(
             hds=hds).build
         executor = self.actor.parse(act_phase_instructions)
         actual = executor.validate_pre_sds(environment)
     self.assertIs(svh.SuccessOrValidationErrorOrHardErrorEnum.SUCCESS,
                   actual.status, 'Validation result')
Пример #10
0
    def test_populate_tcds(self):
        # ARRANGE #
        expected_dir_contents = fs.DirContents([fs.File('a-file-name.txt', 'the file contents')])
        populator = sut.contents_in(RelHdsOptionType.REL_HDS_CASE,
                                    expected_dir_contents)
        expectation = f_asrt.dir_contains_exactly(expected_dir_contents)

        sds = fake_sds()
        with home_directory_structure() as hds:
            tcds = TestCaseDs(hds, sds)
            # ACT #
            populator.populate_tcds(tcds)
            # ASSERT #
            expectation.apply_with_message(self, hds.case_dir,
                                           'contents of HDS/case dir')
Пример #11
0
    def test_two_populators_populate_hds(self):
        # ARRANGE #
        expected_dir_contents = fs.DirContents([self.first_file,
                                                self.second_file])
        first_populator = sut.hds_case_dir_contents(fs.DirContents([self.first_file]))
        second_populator = sut.hds_case_dir_contents(fs.DirContents([self.second_file]))
        populator = sut.multiple([first_populator,
                                  second_populator])
        expectation = f_asrt.dir_contains_exactly(expected_dir_contents)

        with home_directory_structure() as hds:
            # ACT #
            populator.populate_hds(hds)
            # ASSERT #
            expectation.apply_with_message(self, hds.case_dir,
                                           'contents of HDS/case dir')
Пример #12
0
 def action(std_files: StdOutputFiles) -> PartialExeResult:
     exe_conf = ExecutionConfiguration(
         os_environ_getter,
         None,
         arrangement.timeout_in_seconds,
         os_services_access.new_for_current_os(),
         sandbox_root_name_resolver.for_test(),
         arrangement.mem_buff_size,
         exe_atc_and_skip_assertions=std_files)
     with home_directory_structure() as hds:
         conf_phase_values = ConfPhaseValues(
             NameAndValue('the actor', actor), hds)
         return sut.execute(
             arrangement.test_case_generator.test_case,
             exe_conf,
             conf_phase_values,
             MkSetupSettingsHandlerThatRecordsValidation(
                 arrangement.test_case_generator.recorder).make,
             False,
         )
Пример #13
0
def tcds_with_act_as_curr_dir(
        hds_contents: hds_populators.HdsPopulator = hds_populators.empty(),
        sds_contents: sds_populator.SdsPopulator = sds_populator.empty(),
        non_hds_contents: non_hds_populator.NonHdsPopulator = non_hds_populator.empty(),
        tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(),
        pre_contents_population_action: TcdsAction = TcdsAction(),
        symbols: SymbolTable = None) -> ContextManager[PathResolvingEnvironmentPreOrPostSds]:
    symbols = symbol_table_from_none_or_value(symbols)
    prefix = strftime(program_info.PROGRAM_NAME + '-test-%Y-%m-%d-%H-%M-%S', localtime())
    with home_directory_structure(prefix=prefix + '-home') as hds:
        with sandbox_directory_structure(prefix=prefix + "-sds-") as sds:
            tcds = TestCaseDs(hds, sds)
            ret_val = PathResolvingEnvironmentPreOrPostSds(tcds, symbols)
            with preserved_cwd():
                os.chdir(str(sds.act_dir))
                pre_contents_population_action.apply(ret_val)
                hds_contents.populate_hds(hds)
                sds_contents.populate_sds(sds)
                non_hds_contents.populate_non_hds(sds)
                tcds_contents.populate_tcds(tcds)
                yield ret_val
Пример #14
0
def _execute(
    actor: Actor,
    test_case: TestCase,
    setup_settings_handler: Optional[MkSetupSettingsHandler] = None,
    is_keep_sandbox: bool = False,
    current_directory: pathlib.Path = None,
    mem_buff_size: int = 2**10,
) -> PartialExeResult:
    if current_directory is None:
        current_directory = pathlib.Path.cwd()
    with home_directory_structure() as hds:
        with preserved_cwd():
            os.chdir(str(current_directory))
            return sut.execute(
                test_case,
                ExecutionConfiguration(os_environ_getter, None, None,
                                       os_services_access.new_for_current_os(),
                                       sandbox_root_name_resolver.for_test(),
                                       mem_buff_size),
                ConfPhaseValues(NameAndValue('the actor', actor), hds),
                settings_handlers.mk_from_optional(setup_settings_handler),
                is_keep_sandbox)