예제 #1
0
    def _check_cases_with_non_empty_file(self,
                                         get_assertion_part_function: Callable[
                                             [ExpectationType, LineMatcherSdv],
                                             FileContentsAssertionPart],
                                         actual_file_contents: str,
                                         matcher_cases: Sequence[Case]):

        environment = fake_post_sds_environment()
        os_services = new_for_current_os()

        with string_source_factory() as source_factory:
            # This test is expected to not create files using the above object,
            # but to be sure, one is used that creates and destroys temporary files.
            with tmp_file_containing(actual_file_contents) as actual_file_path:
                for case in matcher_cases:
                    for expectation_type in ExpectationType:
                        with self.subTest(case=case.name,
                                          expectation_type=expectation_type):
                            model = source_factory.of_file__poorly_described(
                                actual_file_path)
                            matcher_sdv = sdv_components.matcher_sdv_from_constant_primitive(
                                case.matcher)
                            assertion_part = get_assertion_part_function(
                                expectation_type, matcher_sdv)
                            # ACT #
                            actual = assertion_part.check_and_return_pfh(
                                environment, os_services, model)
                            # ASSERT #
                            pfh_assertion = pfh_expectation_type_config(
                                expectation_type).main_result(
                                    case.
                                    expected_result_for_positive_expectation)
                            pfh_assertion.apply_without_message(self, actual)
예제 #2
0
 def __init__(self,
              pre_contents_population_action: TcdsAction = TcdsAction(),
              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(),
              post_sds_population_action: TcdsAction = TcdsAction(),
              act_result_producer: ActResultProducer = ActResultProducerFromActResult(),
              os_services: OsServices = os_services_access.new_for_current_os(),
              process_execution_settings: ProcessExecutionSettings = ProcessExecutionSettings.null(),
              default_environ_getter: DefaultEnvironGetter = get_empty_environ,
              symbols: SymbolTable = None,
              fs_location_info: FileSystemLocationInfo = ARBITRARY_FS_LOCATION_INFO,
              ):
     super().__init__(pre_contents_population_action=pre_contents_population_action,
                      sds_contents=sds_contents,
                      hds_contents=hds_contents,
                      non_hds_contents=non_hds_contents,
                      tcds_contents=tcds_contents,
                      post_sds_population_action=post_sds_population_action,
                      os_services=os_services,
                      process_execution_settings=process_execution_settings,
                      default_environ_getter=default_environ_getter,
                      symbols=symbols,
                      fs_location_info=fs_location_info)
     self.act_result_producer = act_result_producer
예제 #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))
    def apply(
        self,
        put: unittest.TestCase,
        message_builder: MessageBuilder,
        primitive: Program,
        resolving_environment: FullResolvingEnvironment,
        input_: ProcOutputFile,
    ) -> ResultWithTransformationData:
        process_execution_settings = proc_exe_env_for_test(
            timeout_in_seconds=5)

        pgm_output_dir = resolving_environment.application_environment.tmp_files_space.new_path_as_existing_dir(
        )
        execution_result = pgm_execution.make_transformed_file_from_output(
            pgm_output_dir, process_execution_settings,
            os_services_access.new_for_current_os(),
            resolving_environment.application_environment.tmp_files_space,
            input_, primitive)
        proc_exe_result = execution_result.process_result
        stderr_contents = misc_utils.contents_of(
            proc_exe_result.files.path_of_std(ProcOutputFile.STDERR))
        stdout_contents = misc_utils.contents_of(
            proc_exe_result.files.path_of_std(ProcOutputFile.STDOUT))
        result_of_transformation = misc_utils.contents_of(
            execution_result.path_of_file_with_transformed_contents)
        proc_result_data = SubProcessResult(proc_exe_result.exit_code,
                                            stdout_contents, stderr_contents)
        return ResultWithTransformationData(proc_result_data,
                                            result_of_transformation)
예제 #5
0
    def _new_processor(
        self, recording_media: List[Recording],
        test_case_processor_constructor: TestCaseProcessorConstructor
    ) -> sut.Processor:
        test_case_definition = TestCaseDefinition(
            TestCaseParsingSetup(
                space_separator_instruction_name_extractor,
                self._phase_config().instructions_setup(
                    REGISTER_INSTRUCTION_NAME, recording_media),
                self._phase_config().act_phase_parser()),
            _predefined_properties.new_empty())

        default_case_configuration = processors.Configuration(
            test_case_definition,
            TestCaseHandlingSetup(
                ActPhaseSetup('recording actor',
                              self._phase_config().actor(recording_media)),
                IDENTITY_PREPROCESSOR),
            os_services_access.new_for_current_os(), 2**10, False,
            sandbox_dir_resolving.mk_tmp_dir_with_prefix('test-suite-'))

        return sut.Processor(
            default_case_configuration,
            suite_hierarchy_reading.Reader(
                suite_hierarchy_reading.Environment(
                    SectionElementParserThatRaisesUnrecognizedSectionElementSourceError(
                    ), test_case_definition.parsing_setup,
                    default_case_configuration.default_handling_setup)),
            ProcessingReporterThatDoesNothing(),
            enumeration.DepthFirstEnumerator(),
            test_case_processor_constructor,
        )
예제 #6
0
 def __init__(
     self,
     pre_contents_population_action: TcdsAction = TcdsAction(),
     hds_contents: hds_populators.HdsPopulator = hds_populators.empty(),
     sds_contents_before_main: sds_populator.SdsPopulator = sds_populator.
     empty(),
     non_hds_contents_before_main: non_hds_populator.
     NonHdsPopulator = non_hds_populator.empty(),
     tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(),
     os_services: OsServices = new_for_current_os(),
     process_execution_settings:
     ProcessExecutionSettings = ProcessExecutionSettings.null(),
     default_environ_getter: DefaultEnvironGetter = get_empty_environ,
     previous_phase: PreviousPhase = PreviousPhase.ASSERT,
     symbols: SymbolTable = None,
     fs_location_info: FileSystemLocationInfo = ARBITRARY_FS_LOCATION_INFO,
 ):
     super().__init__(
         pre_contents_population_action=pre_contents_population_action,
         hds_contents=hds_contents,
         sds_contents=sds_contents_before_main,
         non_hds_contents=non_hds_contents_before_main,
         tcds_contents=tcds_contents,
         os_services=os_services,
         process_execution_settings=process_execution_settings,
         default_environ_getter=default_environ_getter,
         symbols=symbols,
         fs_location_info=fs_location_info)
     self.previous_phase = previous_phase
예제 #7
0
def arrangement(
    pre_contents_population_action: TcdsAction = TcdsAction(),
    hds_contents: hds_populators.HdsPopulator = hds_populators.empty(),
    sds_contents_before_main: sds_populator.SdsPopulator = sds_populator.empty(
    ),
    non_hds_contents_before_main: non_hds_populator.
    NonHdsPopulator = non_hds_populator.empty(),
    tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(),
    act_result_producer: ActResultProducer = ActResultProducerFromActResult(),
    os_services: OsServices = new_for_current_os(),
    process_execution_settings:
    ProcessExecutionSettings = ProcessExecutionSettings.null(),
    default_environ_getter: DefaultEnvironGetter = get_empty_environ,
    symbols: SymbolTable = None,
) -> ArrangementPostAct:
    return ArrangementPostAct(
        pre_contents_population_action=pre_contents_population_action,
        hds_contents=hds_contents,
        sds_contents=sds_contents_before_main,
        non_hds_contents=non_hds_contents_before_main,
        tcds_contents=tcds_contents,
        act_result_producer=act_result_producer,
        os_services=os_services,
        process_execution_settings=process_execution_settings,
        default_environ_getter=default_environ_getter,
        symbols=symbols)
예제 #8
0
class TestIsExistingRegularFileAssertionPart(unittest.TestCase):
    the_os_services = oss.new_for_current_os()
    environment = fake_post_sds_environment()

    def test_model_is_returned_WHEN_file_is_existing_regular_file(self):
        # ARRANGE #

        assertion_part = sut.IsExistingRegularFileAssertionPart()

        existing_regular_file = File.empty('regular.txt')

        with tmp_dir(DirContents([existing_regular_file])) as path_of_existing_directory:
            path_of_existing_regular_file = path_of_existing_directory / existing_regular_file.name
            path_ddv = path_ddvs.absolute_path(path_of_existing_regular_file)
            path = path_ddv.value_of_any_dependency__d(fake_tcds())
            model = sut.ComparisonActualFile(path,
                                             True)
            # ACT #

            actual = assertion_part.check(self.environment, self.the_os_services,
                                          model)
            # ASSERT #

            self.assertIs(model, actual)

    def test_PfhHardError_SHOULD_be_raised_WHEN_file_does_not_exist(self):
        # ARRANGE #
        assertion_part = sut.IsExistingRegularFileAssertionPart()
        # ACT & ASSERT #
        with self.assertRaises(PfhHardErrorException):
            path = pathlib.Path('a file that does not exist')
            assertion_part.check(self.environment, self.the_os_services,
                                 sut.ComparisonActualFile(
                                     described_path.new_primitive(path),
                                     True,
                                 ))

    def test_PfhHardError_SHOULD_be_raised_WHEN_file_does_exist_but_is_not_a_regular_file(self):
        # ARRANGE #
        assertion_part = sut.IsExistingRegularFileAssertionPart()
        # ACT & ASSERT #
        with tmp_dir() as path_of_existing_directory:
            with self.assertRaises(PfhHardErrorException):
                assertion_part.check(self.environment, self.the_os_services,
                                     sut.ComparisonActualFile(
                                         described_path.new_primitive(path_of_existing_directory),
                                         True,
                                     )
                                     )

    def test_no_exception_SHOULD_be_not_raised_WHEN_file_does_not_exist_but_file_does_not_need_to_be_verified(self):
        # ARRANGE #
        assertion_part = sut.IsExistingRegularFileAssertionPart()
        # ACT & ASSERT #
        path = pathlib.Path('a file that does not exist')
        assertion_part.check(self.environment, self.the_os_services,
                             sut.ComparisonActualFile(
                                 described_path.new_primitive(path),
                                 False,
                             ))
예제 #9
0
def new_processor(
        setup_phase_instructions: Dict[str, InstructionParser],
        test_case_processor_constructor: TestCaseProcessorConstructor,
        predefined_properties: PredefinedProperties) -> sut.Processor:
    test_case_definition = TestCaseDefinition(
        TestCaseParsingSetup(space_separator_instruction_name_extractor,
                             instruction_setup(setup_phase_instructions),
                             ActPhaseParser()), predefined_properties)
    default_configuration = processors.Configuration(
        test_case_definition,
        test_case_handling_setup_with_identity_preprocessor(),
        os_services_access.new_for_current_os(), 2**10, False,
        sandbox_dir_resolving.mk_tmp_dir_with_prefix('test-suite-'))

    return sut.Processor(
        default_configuration,
        suite_hierarchy_reading.Reader(
            suite_hierarchy_reading.Environment(
                SectionElementParserThatRaisesRecognizedSectionElementSourceError(
                ), test_case_definition.parsing_setup,
                default_configuration.default_handling_setup)),
        ExecutionTracingProcessingReporter(),
        enumeration.DepthFirstEnumerator(),
        test_case_processor_constructor,
    )
예제 #10
0
 def __init__(
     self,
     pre_contents_population_action: TcdsAction = TcdsAction(),
     hds_contents: hds_populators.HdsPopulator = hds_populators.empty(),
     sds_contents_before_main: 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(),
     os_services: OsServices = os_services_access.new_for_current_os(),
     process_execution_settings:
     ProcessExecutionSettings = ProcessExecutionSettings.null(),
     default_environ_getter: DefaultEnvironGetter = get_empty_environ,
     settings_builder: Optional[SetupSettingsBuilder] = None,
     symbols: SymbolTable = None,
     fs_location_info: FileSystemLocationInfo = ARBITRARY_FS_LOCATION_INFO,
 ):
     super().__init__(
         pre_contents_population_action=pre_contents_population_action,
         hds_contents=hds_contents,
         sds_contents=sds_contents_before_main,
         non_hds_contents=non_hds_contents,
         tcds_contents=tcds_contents,
         os_services=os_services,
         process_execution_settings=process_execution_settings,
         default_environ_getter=default_environ_getter,
         symbols=symbols,
         fs_location_info=fs_location_info,
     )
     self.initial_settings_builder = settings_handlers.builder_from_optional(
         settings_builder)
예제 #11
0
    def test_main_method_arguments(self):
        # ARRANGE #
        the_environ = MappingProxyType({'the_env_var': 'the env var value'})
        the_timeout = 69
        the_os_services = os_services_access.new_for_current_os()

        def main_action_that_checks_arguments(environment: InstructionEnvironmentForPostSdsStep,
                                              instruction_settings: InstructionSettings,
                                              os_services: OsServices):
            self.assertIs(os_services, the_os_services, 'os_services')

            self.assertEqual(the_environ, environment.proc_exe_settings.environ,
                             'proc exe settings/environment')

            self.assertEqual(the_timeout, environment.proc_exe_settings.timeout_in_seconds,
                             'proc exe settings/timeout')

            self.assertEqual(the_environ, instruction_settings.environ(),
                             'instruction settings/environment')

        # ACT & ASSERT #
        self._check_source_and_exe_variants(
            ParserThatGives(instruction_embryo_that__phase_agnostic(
                main_initial_action=main_action_that_checks_arguments
            )),
            Arrangement.phase_agnostic(
                process_execution_settings=ProcessExecutionSettings(the_timeout, the_environ),
                os_services=the_os_services,
            ),
            MultiSourceExpectation.phase_agnostic(),
        )
예제 #12
0
    def _check_cases_for_no_lines(
            self, get_assertion_part_function: Callable[
                [ExpectationType, LineMatcherSdv],
                AssertionPart[StringSource, pfh.PassOrFailOrHardError]],
            expected_result_when_positive_expectation: PassOrFail):
        empty_file_contents = ''
        environment = fake_post_sds_environment()
        os_services = new_for_current_os()

        matchers = [
            ('unconditionally true', MatcherWithConstantResult(True)),
            ('unconditionally false', MatcherWithConstantResult(False)),
        ]
        with string_source_factory() as source_factory:
            # This test is expected to not create files using the above object,
            # but to be sure, one is used that creates and destroys temporary files.
            with tmp_file_containing(empty_file_contents) as actual_file_path:
                for expectation_type in ExpectationType:
                    for matcher_name, matcher in matchers:
                        with self.subTest(expectation_type=expectation_type,
                                          matcher_name=matcher_name):
                            model = source_factory.of_file__poorly_described(
                                actual_file_path)
                            matcher_sdv = sdv_components.matcher_sdv_from_constant_primitive(
                                matcher)
                            assertion_part = get_assertion_part_function(
                                expectation_type, matcher_sdv)
                            # ACT #
                            actual = assertion_part.check_and_return_pfh(
                                environment, os_services, model)
                            # ASSERT #
                            pfh_assertion = pfh_expectation_type_config(
                                expectation_type).main_result(
                                    expected_result_when_positive_expectation)
                            pfh_assertion.apply_without_message(self, actual)
예제 #13
0
 def __init__(self,
              pre_contents_population_action: TcdsAction = TcdsAction(),
              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(),
              os_services: OsServices = os_services_access.new_for_current_os(),
              process_execution_settings: ProcessExecutionSettings = proc_exe_env_for_test(),
              default_environ_getter: DefaultEnvironGetter = get_empty_environ,
              post_sds_population_action: TcdsAction = TcdsAction(),
              symbols: SymbolTable = None,
              fs_location_info: FileSystemLocationInfo = ARBITRARY_FS_LOCATION_INFO,
              ):
     super().__init__(hds_contents=hds_contents,
                      process_execution_settings=process_execution_settings,
                      default_environ_getter=default_environ_getter)
     self.pre_contents_population_action = pre_contents_population_action
     self.sds_contents = sds_contents
     self.non_hds_contents = non_hds_contents
     self.tcds_contents = tcds_contents
     self.post_sds_population_action = post_sds_population_action
     self.os_services = os_services
     self.process_execution_settings = process_execution_settings
     self.symbols = symbol_table_from_none_or_value(symbols)
     self.fs_location_info = fs_location_info
예제 #14
0
class TestAssertionPart(unittest.TestCase):
    the_os_services = oss.new_for_current_os()
    environment = fake_post_sds_environment()

    def test_return_pfh_pass_WHEN_no_exception_is_raised(self):
        # ARRANGE #
        assertion_part_that_not_raises = SuccessfulPartThatReturnsConstructorArgPlusOne()
        # ACT #
        actual = assertion_part_that_not_raises.check_and_return_pfh(self.environment,
                                                                     self.the_os_services,
                                                                     1)
        # ASSERT #
        assertion = asrt_pfh.is_pass()
        assertion.apply_without_message(self, actual)

    def test_return_pfh_fail_WHEN_PfhFailException_is_raised(self):
        # ARRANGE #
        assertion_part_that_raises = PartThatRaisesFailureExceptionIfArgumentIsEqualToOne()
        # ACT #
        actual = assertion_part_that_raises.check_and_return_pfh(self.environment,
                                                                 self.the_os_services,
                                                                 1)
        # ASSERT #
        assertion = asrt_pfh.is_fail(
            is_string_for_test(
                asrt.equals(PartThatRaisesFailureExceptionIfArgumentIsEqualToOne.ERROR_MESSAGE))
        )
        assertion.apply_without_message(self, actual)
예제 #15
0
def application_environment_for_test(
    tmp_file_space: DirFileSpace = DirFileSpaceThatMustNoBeUsed(),
    os_services_: OsServices = os_services_access.new_for_current_os(),
    process_execution_settings:
    ProcessExecutionSettings = ProcessExecutionSettings.null(),
    mem_buff_size: int = 2**10,
) -> ApplicationEnvironment:
    return ApplicationEnvironment(os_services_, process_execution_settings,
                                  tmp_file_space, mem_buff_size)
예제 #16
0
 def __init__(self,
              source: ParseSource,
              act_phase_source_lines: List[str],
              hds_contents: hds_populators.HdsPopulator = hds_populators.empty(),
              os_services: OsServices = os_services_access.new_for_current_os(),
              ):
     self.hds_contents = hds_contents
     self.source = source
     self.act_phase_source_lines = act_phase_source_lines
     self.os_services = os_services
예제 #17
0
    def test_main_method_arguments(self):
        # ARRANGE #
        the_environ = MappingProxyType({'an_env_var': 'an env var value'})

        the_timeout = 72
        the_os_services = os_services_access.new_for_current_os()

        setup_settings_cases = [
            NArrEx(
                'none',
                None,
                asrt.is_none,
            ),
            NArrEx(
                'not none',
                SetupSettingsArr(the_environ),
                _IsSettingsBuilderWoStdinWEnviron(asrt.equals(the_environ)),
            ),
        ]

        for setup_settings_case in setup_settings_cases:
            def main_action_that_checks_arguments(environment: InstructionEnvironmentForPostSdsStep,
                                                  instruction_settings: InstructionSettings,
                                                  settings_builder: Optional[SetupSettingsBuilder],
                                                  os_services: OsServices):
                self.assertIs(os_services, the_os_services, 'os_services')

                self.assertEqual(the_environ, environment.proc_exe_settings.environ,
                                 'proc exe settings/environment')

                self.assertEqual(the_timeout, environment.proc_exe_settings.timeout_in_seconds,
                                 'proc exe settings/timeout')

                self.assertEqual(the_environ, instruction_settings.environ(),
                                 'instruction settings/environment')

                setup_settings_case.expectation.apply_with_message(self, settings_builder,
                                                                   'setup settings passed to main')

            # ACT & ASSERT #
            self._check_source_and_exe_variants(
                ParserThatGives(instruction_embryo_that__setup_phase_aware(
                    main_initial_action=main_action_that_checks_arguments
                )),
                Arrangement.setup_phase_aware(
                    process_execution_settings=ProcessExecutionSettings(the_timeout, the_environ),
                    setup_settings=setup_settings_case.arrangement,
                    os_services=the_os_services,
                ),
                MultiSourceExpectation.setup_phase_aware(
                    setup_settings=asrt.anything_goes(),
                ),
            )
예제 #18
0
 def apply(self, environment: PathResolvingEnvironmentPreOrPostSds) -> ExecutionResultAndStderr:
     environment_builder = InstructionEnvironmentPostSdsBuilder.new_tcds(
         environment.tcds,
         process_execution_settings=ProcessExecutionSettings.with_environ(os.environ),
     )
     env__post_sds = environment_builder.build_post_sds()
     settings = optionally_from_proc_exe_settings(None, env__post_sds.proc_exe_settings)
     return self.instruction_embryo.main(
         env__post_sds,
         settings,
         os_services_access.new_for_current_os(),
     )
예제 #19
0
def application_environment_with_existing_dir(
    os_services: OsServices = os_services_access.new_for_current_os(),
    process_execution_settings:
    ProcessExecutionSettings = ProcessExecutionSettings.null(),
    mem_buff_size: int = 2**10,
) -> ContextManager[ApplicationEnvironment]:
    with tempfile.TemporaryDirectory(prefix='exactly') as tmp_dir_name:
        yield application_environment_for_test(
            tmp_dir_file_space_for_test(Path(tmp_dir_name)),
            os_services,
            process_execution_settings,
            mem_buff_size,
        )
예제 #20
0
def _resolve_os_services() -> OsServices:
    try:
        return os_services_access.new_for_current_os()
    except os_services_access.OsServicesError as ex:

        def print_ex_msg(environment: Environment):
            printer = environment.std_file_printers.get(ProcOutputFile.STDERR)
            printer.write_line(ex.msg)

        raise _StartupError(
            ProcessResultReporterWithInitialExitValueOutput(
                exit_values.EXECUTION__INTERNAL_ERROR, ProcOutputFile.STDOUT,
                print_ex_msg))
예제 #21
0
 def arrangement(
         self,
         pre_contents_population_action: TcdsAction = TcdsAction(),
         hds_contents: hds_populators.HdsPopulator = hds_populators.empty(),
         sds_contents_before_main: sds_populator.
     SdsPopulator = sds_populator.empty(),
         tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.
     empty(),
         environ: Optional[Dict[str, str]] = None,
         default_environ_getter: DefaultEnvironGetter = get_empty_environ,
         os_services: OsServices = new_for_current_os(),
         symbols: SymbolTable = None):
     raise NotImplementedError()
예제 #22
0
def resolving_helper(
    symbols: Optional[SymbolTable] = None,
    tcds: TestCaseDs = fake_tcds(),
    file_space: DirFileSpace = DirFileSpaceThatMustNoBeUsed(),
    os_services_: OsServices = os_services_access.new_for_current_os(),
    process_execution_settings:
    ProcessExecutionSettings = ProcessExecutionSettings.null(),
    mem_buff_size: int = 2**10,
) -> LogicTypeResolvingHelper:
    return LogicTypeResolvingHelper(
        (symbols if symbols is not None else empty_symbol_table()),
        tcds,
        ApplicationEnvironment(os_services_, process_execution_settings,
                               file_space, mem_buff_size),
    )
예제 #23
0
def configuration_for_instruction_set(
        instruction_set: InstructionsSetup) -> sut.Configuration:
    tc_parsing_setup = TestCaseParsingSetup(
        first_space_separated_string_extractor, instruction_set,
        ActPhaseParser())
    tc_definition = TestCaseDefinition(tc_parsing_setup,
                                       _predefined_properties.new_empty())
    tc_handling_setup = setup_with_null_act_phase_and_null_preprocessing()
    return sut.Configuration(
        tc_definition,
        tc_handling_setup,
        os_services_access.new_for_current_os(),
        2**10,
        is_keep_sandbox=False,
    )
예제 #24
0
 def app_env_for_freeze(
     self,
     put: unittest.TestCase,
     message_builder: MessageBuilder,
 ) -> ContextManager[ApplicationEnvironment]:
     default_os_services = os_services_access.new_for_current_os()
     os_services_w_check = os_services_access.new_for_cmd_exe(
         CommandExecutorWithMaxNumInvocations(
             put,
             1,
             default_os_services.command_executor,
             message_builder.apply(''),
         ))
     return application_environment.application_environment_with_existing_dir(
         os_services_w_check)
예제 #25
0
 def __init__(
     self,
     test_case: TestCase,
     actor: Actor,
     settings_handler: Optional[MkSetupSettingsHandler] = None,
     os_services: OsServices = os_services_access.new_for_current_os(),
     mem_buff_size: int = 2**10,
     timeout_in_seconds: Optional[int] = None,
 ):
     self.test_case = test_case
     self.actor = actor
     self.timeout_in_seconds = timeout_in_seconds
     self.settings_handler = settings_handlers.mk_from_optional(
         settings_handler)
     self.os_services = os_services
     self.mem_buff_size = mem_buff_size
예제 #26
0
 def __init__(
     self,
     test_case: test_case_doc.TestCase,
     configuration_builder: ConfigurationBuilder,
     settings_handler: Optional[SetupSettingsHandler] = None,
     predefined_properties: PredefinedProperties = _predefined_properties.
     new_empty(),
     os_services: OsServices = os_services_access.new_for_current_os(),
     mem_buff_size: int = 2**10,
 ):
     self.test_case = test_case
     self.predefined_properties = predefined_properties
     self.configuration_builder = configuration_builder
     self.settings_handler = settings_handlers.from_optional(
         settings_handler)
     self.os_services = os_services
     self.mem_buff_size = mem_buff_size
예제 #27
0
 def arrangement(self,
                 pre_contents_population_action: TcdsAction = TcdsAction(),
                 hds_contents: hds_populators.HdsPopulator = hds_populators.empty(),
                 sds_contents_before_main: sds_populator.SdsPopulator = sds_populator.empty(),
                 tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(),
                 environ: Optional[Dict[str, str]] = None,
                 default_environ_getter: DefaultEnvironGetter = get_empty_environ,
                 os_services: OsServices = new_for_current_os(),
                 symbols: SymbolTable = None):
     return ic.Arrangement(pre_contents_population_action=pre_contents_population_action,
                           hds_contents=hds_contents,
                           sds_contents_before_main=sds_contents_before_main,
                           tcds_contents=tcds_contents,
                           process_execution_settings=ProcessExecutionSettings.from_non_immutable(environ=environ),
                           default_environ_getter=default_environ_getter,
                           os_services=os_services,
                           symbols=symbols)
예제 #28
0
 def phase_agnostic(
         tcds: Optional[TcdsArrangement] = None,
         os_services: OsServices = os_services_access.new_for_current_os(),
         process_execution_settings: ProcessExecutionSettings = proc_exe_env_for_test(),
         default_environ_getter: DefaultEnvironGetter = get_empty_environ,
         symbols: Optional[SymbolTable] = None,
         fs_location_info: FileSystemLocationInfo = ARBITRARY_FS_LOCATION_INFO,
 ) -> 'Arrangement':
     return Arrangement(
         tcds,
         os_services,
         process_execution_settings,
         default_environ_getter,
         symbols,
         fs_location_info,
         None,
     )
예제 #29
0
 def __init__(self,
              unittest_case: unittest.TestCase,
              dbg_do_not_delete_dir_structure=False,
              actor: Actor = None,
              default_environ_getter: DefaultEnvironGetter = os_environ_getter,
              environ: Optional[Mapping[str, str]] = None,
              os_services: OsServices = os_services_access.new_for_current_os(),
              timeout_in_seconds: Optional[int] = None,
              ):
     self.__unittest_case = unittest_case
     self.__dbg_do_not_delete_dir_structure = dbg_do_not_delete_dir_structure
     self.__full_result = None
     self.__sandbox_directory_structure = None
     self.__initial_hds_dir_path = None
     self.__actor = actor
     self.__os_services = os_services
     self.__default_environ_getter = default_environ_getter
     self.__environ = environ
     self.__timeout_in_seconds = timeout_in_seconds
예제 #30
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,
         )