Ejemplo n.º 1
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)
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def _do_check(
        self,
        program: ProgramAbsStx,
        process_execution_w_stdin_check: ProcessExecutionArrangement,
        program_symbols: Sequence[SymbolContext],
        tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(),
    ):
        # ARRANGE #
        string_matcher_const_true = StringMatcherSymbolContext.of_primitive(
            'CONSTANT_TRUE',
            ConstantMatcherWithCustomName('const true', True),
        )
        symbols = list(program_symbols) + [string_matcher_const_true]
        copy_stdin_and_check_via_matcher = StdoutErrFromProgramAbsStx(
            program,
            string_matcher_const_true.abstract_syntax,
        )

        checker = instruction_check.Checker(self.configuration.parser())
        # ACT & ASSERT #
        checker.check__abs_stx__source_variants(
            self,
            copy_stdin_and_check_via_matcher,
            ArrangementPostAct2(
                symbols=SymbolContext.symbol_table_of_contexts(symbols),
                tcds=TcdsArrangementPostAct(tcds_contents=tcds_contents),
                process_execution=process_execution_w_stdin_check,
            ),
            MultiSourceExpectation(symbol_usages=SymbolContext.
                                   usages_assertion_of_contexts(symbols)),
        )
Ejemplo n.º 5
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
Ejemplo n.º 6
0
 def arrangement_for_contents(self,
                              actual_contents: str,
                              post_sds_population_action: TcdsAction = TcdsAction(),
                              tcds_contents: tcds.TcdsPopulator = tcds.empty(),
                              symbols: SymbolTable = None,
                              ) -> instruction_check.ArrangementPostAct:
     raise NotImplementedError()
Ejemplo n.º 7
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
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
 def __init__(
         self,
         file_contents_cases: Sequence[NameAndValue[FileContentsAbsStx]],
         symbols: SymbolTable,
         pre_existing_files: TcdsPopulator = tcds_populators.empty(),
 ):
     self.file_contents_cases = file_contents_cases
     self.symbols = symbols
     self.pre_existing_files = pre_existing_files
Ejemplo n.º 10
0
 def arrangement_for_contents(self,
                              actual_contents: str,
                              post_sds_population_action: TcdsAction = TcdsAction(),
                              tcds_contents: tcds.TcdsPopulator = tcds.empty(),
                              symbols: SymbolTable = None,
                              ) -> instruction_check.ArrangementPostAct:
     return instruction_check.ArrangementPostAct(
         sds_contents=self._populator_for_actual(actual_contents),
         tcds_contents=tcds_contents,
         post_sds_population_action=post_sds_population_action,
         symbols=symbols,
     )
Ejemplo n.º 11
0
 def __init__(
     self,
     name: str,
     source_elements: Sequence[ArgumentAbsStx],
     expected_resolved_values: Callable[[TestCaseDs], List[str]],
     expected_symbol_references: List[Assertion[SymbolReference]],
     tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(),
 ):
     self.name = name
     self.source_elements = source_elements
     self.expected_resolved_values = expected_resolved_values
     self.expected_symbol_references = expected_symbol_references
     self.tcds_contents = tcds_contents
Ejemplo n.º 12
0
 def runTest(self):
     utils.check__abs_stx(
         self,
         self.configuration.executable,
         utils.Arrangement(tcds_pop.empty()),
         utils.Expectation(
             path_ddv=self.configuration.path_ddv,
             expected_symbol_references=self.configuration.
             expected_symbol_references,
             source=asrt_source.is_at_end_of_line(1),
             validation_result=self.configuration.validation_result,
         ),
     )
Ejemplo n.º 13
0
 def wo_tcds(name: str,
             pgm_and_args: PgmAndArgsAbsStx,
             expected_command_driver: Callable[[AssertionResolvingEnvironment], Assertion[CommandDriver]],
             symbols: Sequence[SymbolContext] = (),
             ) -> 'PgmAndArgsCase':
     return PgmAndArgsCase(
         name,
         pgm_and_args,
         expected_command_driver,
         symbols,
         tcds_populators.empty(),
         lambda sym_tbl: arrangement_wo_tcds(symbols=sym_tbl)
     )
Ejemplo n.º 14
0
 def __init__(self,
              name: str,
              pgm_and_args: PgmAndArgsAbsStx,
              expected_command_driver: Callable[[AssertionResolvingEnvironment], Assertion[CommandDriver]],
              symbols: Sequence[SymbolContext] = (),
              tcds: TcdsPopulator = tcds_populators.empty(),
              mk_arrangement: Callable[[SymbolTable], Arrangement] =
              lambda sym_tbl: arrangement_wo_tcds(symbols=sym_tbl),
              ):
     self.name = name
     self.pgm_and_args = pgm_and_args
     self.symbols = symbols
     self.expected_command_driver = expected_command_driver
     self.tcds = tcds
     self.mk_arrangement = mk_arrangement
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
 def runTest(self):
     instruction_argument = PgmAndArgsWArgumentsAbsStx(
         self.configuration.executable,
         [
             ArgumentOfRichStringAbsStx.of_str('arg1'),
             ArgumentOfRichStringAbsStx.of_str('-arg2'),
         ],
     )
     utils.check__abs_stx(
         self,
         instruction_argument,
         utils.Arrangement(tcds_pop.empty()),
         utils.Expectation(
             path_ddv=self.configuration.path_ddv,
             expected_symbol_references=self.configuration.
             expected_symbol_references,
             source=has_remaining_part_of_first_line__re('arg1[ \t]+-arg2'),
             validation_result=self.configuration.validation_result,
         ),
     )
Ejemplo n.º 17
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
Ejemplo n.º 18
0
def arrangement_w_tcds(
    tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(),
    hds_contents: hds_populators.HdsPopulator = hds_populators.empty(),
    non_hds_contents: non_hds_populator.NonHdsPopulator = non_hds_populator.
    empty(),
    act_result: Optional[ActResultProducer] = None,
    pre_population_action: PlainTcdsAction = PlainTcdsAction(),
    post_population_action: PlainTcdsAction = PlainTcdsAction(),
    symbols: Optional[SymbolTable] = None,
    process_execution:
    ProcessExecutionArrangement = ProcessExecutionArrangement(),
) -> Arrangement:
    """
    :return: An Arrangement with will create a TCDS
    """
    tcds = TcdsArrangement(
        hds_contents=hds_contents,
        non_hds_contents=non_hds_contents,
        tcds_contents=tcds_contents,
        act_result=act_result,
        pre_population_action=pre_population_action,
        post_population_action=post_population_action,
    )
    return Arrangement(symbols, tcds, process_execution)
Ejemplo n.º 19
0
    def test_existing_path(self):
        # ARRANGE #
        plain_file_name = 'path-name'
        symbol_name = 'symbol_name'

        relativity_cases = [
            PathCase(
                'default relativity SHOULD be CASE_HOME',
                rel_opts.default_conf_rel_hds(RelHdsOptionType.REL_HDS_CASE),
                list_element_for_path(RelOptionType.REL_HDS_CASE,
                                      plain_file_name),
            ),
            PathCase(
                'relativity in SDS should be validated post SDS',
                rel_opts.conf_rel_non_hds(RelNonHdsOptionType.REL_TMP),
                list_element_for_path(RelOptionType.REL_TMP, plain_file_name),
            ),
            PathCase(
                'rel symbol',
                rel_opts.symbol_conf_rel_hds(
                    RelHdsOptionType.REL_HDS_ACT, symbol_name,
                    sut.REL_OPTIONS_CONF.accepted_relativity_variants),
                list_sdvs.string_element(
                    string_sdvs.from_path_sdv(
                        path_sdvs.rel_symbol_with_const_file_name(
                            SymbolReference(
                                symbol_name,
                                reference_restrictions_for_path_symbol(
                                    sut.REL_OPTIONS_CONF.
                                    accepted_relativity_variants)),
                            plain_file_name))),
            ),
        ]
        for case in relativity_cases:
            with self.subTest(case.name):
                rel_opt_conf = case.relativity_variant
                assert isinstance(
                    rel_opt_conf,
                    RelativityOptionConfiguration)  # Type info for IDE

                _case = Case.of(
                    'default relativity SHOULD be CASE_HOME',
                    ArgumentOfExistingPathAbsStx(
                        rel_opt_conf.path_abs_stx_of_name(plain_file_name),
                        None,
                    ), Arrangement(rel_opt_conf.symbols.in_arrangement()),
                    Expectation(
                        elements=[case.expected_list_element],
                        references=asrt.matches_sequence(
                            rel_opt_conf.symbols.
                            reference_expectation_assertions()),
                        validators=is_single_validator_with([
                            NameAndValue(
                                'fail when file is missing',
                                validation_check.assert_with_files(
                                    arrangement=validation_check.Arrangement(
                                        dir_contents=tcds_populators.empty()),
                                    expectation=validation_check.fails_on(
                                        rel_opt_conf.
                                        directory_structure_partition),
                                )),
                            NameAndValue(
                                'fail when file is a broken sym link',
                                validation_check.assert_with_files(
                                    arrangement=validation_check.Arrangement(
                                        dir_contents=rel_opt_conf.
                                        populator_for_relativity_option_root(
                                            DirContents([
                                                sym_link(
                                                    plain_file_name,
                                                    'non-existing-target-file'
                                                ),
                                            ]))),
                                    expectation=validation_check.fails_on(
                                        rel_opt_conf.
                                        directory_structure_partition),
                                )),
                            NameAndValue(
                                'succeed when file exists (as regular file)',
                                validation_check.assert_with_files(
                                    arrangement=validation_check.Arrangement(
                                        dir_contents=rel_opt_conf.
                                        populator_for_relativity_option_root(
                                            DirContents([
                                                File.empty(plain_file_name)
                                            ]))),
                                    expectation=validation_check.is_success())
                            ),
                            NameAndValue(
                                'succeed when file exists (as symlink to regular file)',
                                validation_check.assert_with_files(
                                    arrangement=validation_check.Arrangement(
                                        dir_contents=rel_opt_conf.
                                        populator_for_relativity_option_root(
                                            DirContents([
                                                sym_link(
                                                    plain_file_name,
                                                    'target-file'),
                                                File.empty('target-file'),
                                            ]))),
                                    expectation=validation_check.is_success())
                            ),
                            NameAndValue(
                                'succeed when file exists (as a dir)',
                                validation_check.assert_with_files(
                                    arrangement=validation_check.Arrangement(
                                        dir_contents=rel_opt_conf.
                                        populator_for_relativity_option_root(
                                            DirContents([
                                                Dir.empty(plain_file_name),
                                            ]))),
                                    expectation=validation_check.is_success())
                            ),
                        ]),
                    ))