Example #1
0
    def execute(self):
        # SETUP #
        with preserved_cwd():
            with home_directory_structure() as hds:
                # ACT #
                partial_result = sut.execute(
                    self._test_case(),
                    ExecutionConfiguration(dict(os.environ),
                                           DEFAULT_ATC_OS_PROCESS_EXECUTOR,
                                           sandbox_root_name_resolver.for_test()),
                    ConfPhaseValues(self.__actor,
                                    hds),
                    setup.default_settings(),
                    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))
def execute_main_program(arguments: List[str],
                         the_test_case_handling_setup: TestCaseHandlingSetup,
                         instructions_setup: InstructionsSetup = EMPTY_INSTRUCTIONS_SETUP,
                         name_and_argument_splitter=first_char_is_name_and_rest_is_argument__splitter,
                         builtin_symbols: Sequence[BuiltinSymbol] = (),
                         test_suite_def: TestSuiteDefinition = test_suite_definition()
                         ) -> SubProcessResult:
    program = main_program.MainProgram(the_test_case_handling_setup,
                                       sandbox_root_name_resolver.for_test(),
                                       os_services.DEFAULT_ATC_OS_PROCESS_EXECUTOR,
                                       TestCaseDefinitionForMainProgram(
                                           TestCaseParsingSetup(name_and_argument_splitter,
                                                                instructions_setup,
                                                                ActPhaseParser()),
                                           list(builtin_symbols),
                                       ),
                                       test_suite_def)

    def action_with_stdout_files(stdout_files: StdOutputFiles) -> int:
        return program.execute(arguments, stdout_files)

    std_out_files, exit_code = capture_stdout_err(action_with_stdout_files)
    return SubProcessResult(exit_code,
                            std_out_files.out,
                            std_out_files.err)
Example #3
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))
Example #4
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(dict(os.environ),
                                       arrangement.atc_os_process_executor,
                                       sandbox_root_name_resolver.for_test()),
                ConfPhaseValues(arrangement.actor,
                                hds),
                arrangement.initial_setup_settings,
                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))
Example #5
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))
Example #6
0
    def execute(self):
        # SETUP #
        self.__initial_hds_dir_path = pathlib.Path().resolve()
        # ACT #
        initial_hds_dir_path = self.initial_hds_dir_path.resolve()
        exe_conf = ExecutionConfiguration(self.__default_environ_getter,
                                          self.__environ,
                                          self.__timeout_in_seconds,
                                          self.__os_services,
                                          sandbox_root_name_resolver.for_test(),
                                          2 ** 10,
                                          SymbolTable())
        configuration_builder = ConfigurationBuilder(initial_hds_dir_path,
                                                     initial_hds_dir_path,
                                                     NameAndValue('the actor',
                                                                  self._actor()))
        full_result = execution.execute(
            exe_conf,
            configuration_builder,
            True,
            self._test_case())

        # ASSERT #
        self.__full_result = full_result
        self._assertions()
        # CLEANUP #
        os.chdir(str(self.initial_hds_dir_path))
        if not self.__dbg_do_not_delete_dir_structure and self.sds:
            shutil.rmtree(str(self.sds.root_dir))
        else:
            if self.sds:
                print(str(self.sds.root_dir))
Example #7
0
 def _expect_raise_argument_parsing_error(self,
                                          cwd_contents: DirContents,
                                          arguments: List[str]):
     with tmp_dir_as_cwd(cwd_contents):
         with self.assertRaises(ArgumentParsingError):
             sut.parse(self.TEST_CASE_HANDLING_SETUP,
                       sandbox_root_name_resolver.for_test(),
                       arguments,
                       {})
def main_program_of(test_case_definition: TestCaseDefinitionForMainProgram,
                    test_suite_definition: TestSuiteDefinition,
                    default_test_case_handling_setup: TestCaseHandlingSetup,
                    sandbox_root_dir_name_resolver: SandboxRootDirNameResolver =
                    sandbox_root_name_resolver.for_test()) -> main_program.MainProgram:
    return main_program.MainProgram(
        default_test_case_handling_setup,
        sandbox_root_dir_name_resolver,
        os_services.DEFAULT_ATC_OS_PROCESS_EXECUTOR,
        test_case_definition,
        test_suite_definition,
    )
 def __init__(self,
              default_test_case_handling_setup: TestCaseHandlingSetup,
              atc_os_process_executor: AtcOsProcessExecutor,
              test_case_definition: TestCaseDefinitionForMainProgram,
              test_suite_definition: TestSuiteDefinition,
              sandbox_root_dir_name_resolver: SandboxRootDirNameResolver = sandbox_root_name_resolver.for_test()
              ):
     self.default_test_case_handling_setup = default_test_case_handling_setup
     self.atc_os_process_executor = atc_os_process_executor
     self.test_case_definition = test_case_definition
     self.test_suite_definition = test_suite_definition
     self.sandbox_root_dir_name_resolver = sandbox_root_dir_name_resolver
Example #10
0
 def test_resolve_hds_directory(self):
     # ARRANGE #
     with tmp_file_containing('') as file_path:
         argv = [str(file_path)]
         expected_hds_path = file_path.parent.resolve()
         # ACT #
         result = sut.parse(test_case_handling_setup(),
                            sandbox_root_name_resolver.for_test(),
                            argv, {})
     # ASSERT #
     self.assertEqual(expected_hds_path,
                      result.initial_hds_dir_path,
                      'Initial Home Directory')
Example #11
0
 def test_resolve_home_directory(self):
     # ARRANGE #
     with tmp_file_containing('') as file_path:
         argv = [str(file_path)]
         expected_home_path = file_path.parent.resolve()
         # ACT #
         result = sut.parse(test_case_handling_setup(),
                            sandbox_root_name_resolver.for_test(),
                            argv, {})
     # ASSERT #
     self.assertEqual(expected_home_path,
                      result.initial_home_dir_path,
                      'Initial Home Directory')
Example #12
0
def check(put: unittest.TestCase,
          arrangement: Arrangement,
          expectation: Expectation,
          is_keep_sandbox: bool = False):
    exe_conf = ExecutionConfiguration(dict(os.environ),
                                      arrangement.atc_os_process_executor,
                                      sandbox_root_name_resolver.for_test(),
                                      arrangement.predefined_properties.predefined_symbols)
    result = execution.execute(
        exe_conf,
        arrangement.configuration_builder,
        is_keep_sandbox,
        arrangement.test_case)
    expectation.full_result.apply(put, result, asrt.MessageBuilder('FullExeResult'))
 def __init__(
     self,
     default_test_case_handling_setup: TestCaseHandlingSetup,
     test_case_definition: TestCaseDefinitionForMainProgram,
     test_suite_definition: TestSuiteDefinition,
     sandbox_root_dir_name_resolver:
     SandboxRootDirNameResolver = sandbox_root_name_resolver.for_test(),
     mem_buff_size: int = 2**10,
 ):
     self.default_test_case_handling_setup = default_test_case_handling_setup
     self.test_case_definition = test_case_definition
     self.test_suite_definition = test_suite_definition
     self.sandbox_root_dir_name_resolver = sandbox_root_dir_name_resolver
     self.mem_buff_size = mem_buff_size
 def action(std_files: StdOutputFiles) -> PartialExeResult:
     exe_conf = ExecutionConfiguration(dict(os.environ),
                                       DEFAULT_ATC_OS_PROCESS_EXECUTOR,
                                       sandbox_root_name_resolver.for_test(),
                                       exe_atc_and_skip_assertions=std_files)
     with home_directory_structure() as hds:
         conf_phase_values = ConfPhaseValues(actor,
                                             hds,
                                             timeout_in_seconds=arrangement.timeout_in_seconds)
         return sut.execute(arrangement.test_case_generator.test_case,
                            exe_conf,
                            conf_phase_values,
                            setup.default_settings(),
                            False,
                            )
Example #15
0
def check(put: unittest.TestCase,
          arrangement: Arrangement,
          expectation: Expectation,
          is_keep_sandbox: bool = False):
    exe_conf = ExecutionConfiguration(
        arrangement.predefined_properties.default_environ_getter,
        arrangement.predefined_properties.environ,
        arrangement.predefined_properties.timeout_in_seconds,
        arrangement.os_services, sandbox_root_name_resolver.for_test(),
        arrangement.mem_buff_size,
        arrangement.predefined_properties.predefined_symbols)
    result = execution.execute(exe_conf, arrangement.configuration_builder,
                               is_keep_sandbox, arrangement.test_case)
    expectation.full_result.apply(put, result,
                                  asrt.MessageBuilder('FullExeResult'))
def main_program_of(
    test_case_definition: TestCaseDefinitionForMainProgram,
    test_suite_definition: TestSuiteDefinition,
    default_test_case_handling_setup: TestCaseHandlingSetup,
    sandbox_root_dir_name_resolver:
    SandboxRootDirNameResolver = sandbox_root_name_resolver.for_test(),
    mem_buff_size: int = 2**10,
) -> main_program.MainProgram:
    return main_program.MainProgram(
        default_test_case_handling_setup,
        sandbox_root_dir_name_resolver,
        test_case_definition,
        test_suite_definition,
        mem_buff_size,
    )
Example #17
0
def _execute(test_case: TestCase,
             arrangement: Arrangement,
             is_keep_sandbox: bool = True) -> Result:
    partial_result = sut.execute(
        test_case,
        ExecutionConfiguration(arrangement.default_environ_getter,
                               arrangement.environ,
                               arrangement.timeout_in_seconds,
                               arrangement.os_services,
                               sandbox_root_name_resolver.for_test(),
                               arrangement.mem_buff_size,
                               arrangement.predefined_symbols_or_none,
                               exe_atc_and_skip_assertions=arrangement.
                               exe_atc_and_skip_assertions),
        ConfPhaseValues(NameAndValue('the actor', arrangement.actor),
                        arrangement.hds),
        StandardSetupSettingsHandler.new_from_environ, is_keep_sandbox)
    return Result(arrangement.hds, partial_result)
 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,
         )
Example #19
0
def _execute(test_case: TestCase,
             arrangement: Arrangement,
             is_keep_sandbox: bool = True) -> Result:
    environ = arrangement.environ
    if environ is None:
        environ = {}
    partial_result = sut.execute(
        test_case,
        ExecutionConfiguration(environ,
                               arrangement.act_phase_os_process_executor,
                               sandbox_root_name_resolver.for_test(),
                               arrangement.predefined_symbols_or_none,
                               exe_atc_and_skip_assertions=arrangement.exe_atc_and_skip_assertions),
        ConfPhaseValues(arrangement.actor,
                        arrangement.hds,
                        timeout_in_seconds=arrangement.timeout_in_seconds),
        setup.default_settings(),
        is_keep_sandbox)
    return Result(arrangement.hds,
                  partial_result)
Example #20
0
def _execute(actor: Actor,
             test_case: TestCase,
             setup_settings: SetupSettingsBuilder = setup.default_settings(),
             is_keep_sandbox: bool = False,
             current_directory: pathlib.Path = None,
             ) -> 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(dict(os.environ),
                                       DEFAULT_ATC_OS_PROCESS_EXECUTOR,
                                       sandbox_root_name_resolver.for_test()),
                ConfPhaseValues(actor,
                                hds),
                setup_settings,
                is_keep_sandbox)
Example #21
0
def execute_main_program(
    arguments: List[str],
    the_test_case_handling_setup: TestCaseHandlingSetup,
    instructions_setup: InstructionsSetup = EMPTY_INSTRUCTIONS_SETUP,
    name_and_argument_splitter=first_char_is_name_and_rest_is_argument__splitter,
    builtin_symbols: Sequence[BuiltinSymbol] = (),
    test_suite_def: TestSuiteDefinition = test_suite_definition()
) -> SubProcessResult:
    program = main_program.MainProgram(
        the_test_case_handling_setup, sandbox_root_name_resolver.for_test(),
        TestCaseDefinitionForMainProgram(
            TestCaseParsingSetup(name_and_argument_splitter,
                                 instructions_setup, ActPhaseParser()),
            list(builtin_symbols),
        ), test_suite_def, 2**10)

    def action_with_stdout_files(stdout_files: StdOutputFiles) -> int:
        return program.execute(arguments, stdout_files)

    std_out_files, exit_code = capture_stdout_err(action_with_stdout_files)
    return SubProcessResult(exit_code, std_out_files.out, std_out_files.err)
Example #22
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)