Esempio n. 1
0
 def test(self):
     with tmp_dir() as abs_path_of_dir_containing_last_file_base_name:
         fs_location_info = FileSystemLocationInfo(
             FileLocationInfo(
                 abs_path_of_dir_containing_last_file_base_name))
         instruction_argument = src2(ValueType.PATH, 'name',
                                     '{rel_source_file} component')
         for source in equivalent_source_variants__with_source_check__consume_last_line(
                 self, instruction_argument):
             expected_path_sdv = path_sdvs.constant(
                 path_ddvs.rel_abs_path(
                     abs_path_of_dir_containing_last_file_base_name,
                     path_ddvs.constant_path_part('component')))
             expected_symbol_value = PathSymbolValueContext.of_sdv(
                 expected_path_sdv)
             expected_symbol = PathSymbolContext('name',
                                                 expected_symbol_value)
             INSTRUCTION_CHECKER.check(
                 self, source,
                 Arrangement.phase_agnostic(
                     fs_location_info=fs_location_info),
                 Expectation.phase_agnostic(
                     symbol_usages=asrt.matches_singleton_sequence(
                         expected_symbol.assert_matches_definition_of_sdv),
                     symbols_after_main=assert_symbol_table_is_singleton(
                         'name', expected_symbol_value.
                         assert_matches_container_of_sdv)))
Esempio n. 2
0
 def test_source(self):
     self._check(
         PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
         single_line_source(),
         Arrangement.phase_agnostic(),
         Expectation.phase_agnostic(source=asrt.IsInstance(ParseSource)),
     )
Esempio n. 3
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(),
        )
Esempio n. 4
0
    def test_assignment_of_single_constant_line(self):
        value_str = 'value'
        symbol_name = 'name1'
        sb = SB.new_with(value_str=value_str,
                         symbol_name=symbol_name)

        source = sb.lines(
            here_doc_lines(first_line_start='{string_type} {symbol_name} = ',
                           marker='EOF',
                           contents_lines=['{value_str}']) +
            ['following line']
        )
        # EXPECTATION #
        expected_symbol = StringConstantSymbolContext(symbol_name, value_str + '\n')
        expectation = Expectation.phase_agnostic(
            symbol_usages=asrt.matches_sequence([
                expected_symbol.assert_matches_definition_of_sdv
            ]),
            symbols_after_main=assert_symbol_table_is_singleton(
                symbol_name,
                expected_symbol.value.assert_matches_container_of_sdv,
            ),
            source=asrt_source.is_at_beginning_of_line(4)
        )
        # ACT & ASSERT #
        INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Esempio n. 5
0
    def test_set_value_that_references_an_env_var(self):
        # ARRANGE #

        existing_env_var = NameAndValue('MY_VAR', 'MY_VAL')
        defined_env_var = NameAndValue('name', existing_env_var.value)

        environ__before = {
            existing_env_var.name: existing_env_var.value,
        }
        environ__after = {
            defined_env_var.name: defined_env_var.value,
            existing_env_var.name: existing_env_var.value,
        }

        # ACT & ASSERT #

        CHECKER.check__abs_stx__std_layouts_and_source_variants(
            self,
            SetVariableArgumentsAbsStx.of_str(defined_env_var.name,
                                              env_var_ref_syntax(
                                                  existing_env_var.name),
                                              phase_spec=None),
            arrangement=Arrangement.setup_phase_aware(
                process_execution_settings=ProcessExecutionSettings.
                with_environ(environ__before), ),
            expectation=MultiSourceExpectation.setup_phase_aware(
                main_side_effect_on_environment_variables=asrt.equals(
                    environ__after), ))
Esempio n. 6
0
    def test_assignment_of_list_with_symbol_references(self):
        # ARRANGE #
        referred_symbol_name = 'referred_symbol'
        expected_symbol_reference = references.reference_to__w_str_rendering(
            referred_symbol_name)
        symbol_to_assign = ListSymbolContext.of_sdv(
            'the_symbol_name',
            sdvs.from_elements(
                [sdvs.symbol_element(expected_symbol_reference)]))

        syntax = _syntax(symbol_to_assign,
                         ListSymbolReferenceAbsStx(referred_symbol_name))
        # ACT & ASSERT #
        INSTRUCTION_CHECKER.check__abs_stx__layout_and_source_variants(
            self,
            syntax,
            Arrangement.phase_agnostic(),
            MultiSourceExpectation.phase_agnostic(
                symbol_usages=asrt.matches_sequence(
                    [symbol_to_assign.assert_matches_definition_of_sdv]),
                symbols_after_main=assert_symbol_table_is_singleton(
                    symbol_to_assign.name,
                    symbol_to_assign.value.assert_matches_container_of_sdv,
                ),
            ),
        )
Esempio n. 7
0
    def runTest(self):
        string_72_plus = StringSymbolContext.of_constant(
            'SYMBOL_72_PLUS',
            '72+',
            default_restrictions=asrt_data_rest.
            is__string__w_all_indirect_refs_are_strings(),
        )
        string_5 = StringSymbolContext.of_constant(
            'SYMBOL_5',
            '5',
            default_restrictions=asrt_data_rest.
            is__string__w_all_indirect_refs_are_strings(),
        )
        expected = 72 + 5

        all_symbols = [string_72_plus, string_5]

        value_syntax = StringConcatAbsStx([
            string_72_plus.abstract_syntax,
            string_5.abstract_syntax,
        ])
        CHECKER.check__abs_stx__layout_and_source_variants(
            self,
            InstructionArgumentsAbsStx.of_int(value_syntax),
            Arrangement.phase_agnostic(
                symbols=SymbolContext.symbol_table_of_contexts(all_symbols), ),
            MultiSourceExpectation.phase_agnostic(
                symbol_usages=SymbolContext.usages_assertion_of_contexts(
                    all_symbols),
                instruction_settings=asrt_instr_settings.matches(
                    timeout=asrt.equals(expected))),
        )
Esempio n. 8
0
 def test_destination_already_exists__without_explicit_destination(self):
     # ARRANGE #
     file_name = 'existing-file'
     file_to_install = DirContents([(File(file_name,
                                          'contents'))])
     for parser_case in _EXECUTION_CHECKERS:
         with self.subTest(parser=parser_case.name):
             # ACT & ASSERT #
             parser_case.value.check(
                 self,
                 args.copy(
                     defs.DEFAULT_SRC_REL_OPT.path_argument_of_rel_name(file_name)
                 ).as_remaining_source,
                 Arrangement.phase_agnostic(
                     tcds=TcdsArrangement(
                         pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY,
                         hds_contents=defs.DEFAULT_SRC_REL_OPT.populator_for_relativity_option_root__hds(
                             file_to_install),
                         sds_contents=defs.DEFAULT_DST_REL_OPT.populator_for_relativity_option_root__sds(
                             DirContents([File.empty(file_name)])
                         ),
                     )
                 ),
                 Expectation.phase_agnostic_2(
                     main_result=asrt_text_doc.is_any_text(),
                 )
             )
Esempio n. 9
0
 def test_destination_already_exists_in_destination_directory(self):
     src = 'src-file-name'
     dst = 'dst-dir-name'
     home_dir_contents = DirContents([(File.empty(src))])
     cwd_dir_contents = DirContents([Dir(dst,
                                         [File.empty(src)])])
     for parser_case in _EXECUTION_CHECKERS:
         with self.subTest(parser=parser_case.name):
             # ACT & ASSERT #
             parser_case.value.check(
                 self,
                 args.copy(
                     defs.DEFAULT_SRC_REL_OPT.path_argument_of_rel_name(src),
                     defs.DEFAULT_DST_REL_OPT.path_argument_of_rel_name(dst)
                 ).as_remaining_source,
                 Arrangement.phase_agnostic(
                     tcds=TcdsArrangement(
                         pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY,
                         hds_contents=defs.DEFAULT_SRC_REL_OPT.populator_for_relativity_option_root__hds(
                             home_dir_contents),
                         sds_contents=defs.DEFAULT_DST_REL_OPT.populator_for_relativity_option_root__sds(
                             cwd_dir_contents
                         ),
                     )
                 ),
                 Expectation.phase_agnostic(
                     main_result=asrt_text_doc.is_any_text(),
                 ),
             )
Esempio n. 10
0
 def test_copy_directory(self):
     src_path_arg = defs.DEFAULT_SRC_REL_OPT.path_argument_of_rel_name('existing-dir')
     files_to_install = DirContents([Dir(src_path_arg.name,
                                         [File('a', 'a'),
                                          Dir('d', []),
                                          Dir('d2',
                                              [File('f', 'f')])
                                          ])])
     for execution_checker in _EXECUTION_CHECKERS:
         with self.subTest(parser=execution_checker.name):
             execution_checker.value.check(
                 self,
                 args.copy(src_path_arg).as_remaining_source,
                 Arrangement.phase_agnostic(
                     tcds=TcdsArrangement(
                         pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY,
                         hds_contents=defs.DEFAULT_SRC_REL_OPT.populator_for_relativity_option_root__hds(
                             files_to_install),
                     ),
                 ),
                 Expectation.phase_agnostic_2(
                     main_side_effects_on_sds=sds_contents_check.cwd_contains_exactly(
                         files_to_install)
                 )
             )
Esempio n. 11
0
 def test_copy_file__destination_is_existing_directory(self):
     # ARRANGE #
     src = 'src-file'
     dst = 'dst-dir'
     file_to_install = File(src, 'contents')
     home_dir_contents = [file_to_install]
     act_dir_contents = [Dir.empty(dst)]
     act_dir_contents_after = [Dir(dst, [file_to_install])]
     for parser_case in _EXECUTION_CHECKERS:
         with self.subTest(parser=parser_case.name):
             # ACT & ASSERT #
             parser_case.value.check__w_source_variants(
                 self,
                 args.copy(
                     defs.DEFAULT_SRC_REL_OPT.path_argument_of_rel_name(src),
                     defs.DEFAULT_DST_REL_OPT.path_argument_of_rel_name(dst)
                 ).as_str,
                 Arrangement.phase_agnostic(
                     tcds=TcdsArrangement(
                         pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY,
                         hds_contents=defs.DEFAULT_SRC_REL_OPT.populator_for_relativity_option_root__hds(
                             DirContents(home_dir_contents)
                         ),
                         sds_contents=defs.DEFAULT_DST_REL_OPT.populator_for_relativity_option_root__sds(
                             DirContents(act_dir_contents)
                         ),
                     ),
                 ),
                 MultiSourceExpectation.phase_agnostic(
                     main_side_effects_on_sds=sds_contents_check.cwd_contains_exactly(
                         DirContents(act_dir_contents_after))
                 ),
             )
Esempio n. 12
0
 def test_copy_file__src_rel_non_hds(self):
     for execution_checker in _EXECUTION_CHECKERS:
         for relativity_option in source_relativity_options__non_hds():
             with self.subTest(parser=execution_checker.name,
                               relativity=relativity_option.test_case_description):
                 file_arg = relativity_option.path_argument_of_rel_name('existing-file')
                 file_to_install = DirContents([(File(file_arg.name,
                                                      'contents'))])
                 execution_checker.value.check(
                     self,
                     args.copy(file_arg).as_remaining_source,
                     Arrangement.phase_agnostic(
                         tcds=TcdsArrangement(
                             pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY,
                             non_hds_contents=relativity_option.populator_for_relativity_option_root__non_hds(
                                 file_to_install
                             ),
                         ),
                         symbols=relativity_option.symbols.in_arrangement(),
                     ),
                     Expectation.phase_agnostic_2(
                         symbol_usages=relativity_option.symbols.usages_expectation(),
                         main_side_effects_on_sds=sds_contents_check.cwd_contains_exactly(file_to_install),
                     )
                 )
Esempio n. 13
0
    def test_reference_to_string_source(self):
        # ARRANGE #
        defined_name = symbol_syntax.A_VALID_SYMBOL_NAME

        referenced_symbol = StringSourceSymbolContextOfPrimitiveConstant('referenced_name',
                                                                         'contents of string source')
        syntax = _syntax_of(
            referenced_symbol.abstract_syntax,
            defined_name,
        )

        arrangement = Arrangement.phase_agnostic()

        # EXPECTATION #

        expectation = _expect_definition_of(
            defined_name,
            referenced_symbol.symbol_table,
            referenced_symbol.references_assertion,
            referenced_symbol.contents_str,
            may_depend_on_external_resources=False
        )

        # ACT & ASSERT #

        INSTRUCTION_CHECKER.check__abs_stx__std_layouts_and_source_variants(
            self,
            syntax,
            arrangement,
            expectation,
        )
Esempio n. 14
0
    def test(self):

        expected_defined_symbol = ConstantSuffixPathDdvSymbolContext(
            'name', RelOptionType.REL_ACT, 'component')
        argument_cases = [
            NameAndValue('value on same line', '{rel_act} {suffix}'),
            NameAndValue('value on following line',
                         '{new_line} {rel_act} {suffix}'),
        ]

        for argument_case in argument_cases:
            with self.subTest(arguments=argument_case.name):
                instruction_argument = src2(
                    ValueType.PATH,
                    expected_defined_symbol.name,
                    argument_case.value,
                    suffix=expected_defined_symbol.path_suffix)
                for source in equivalent_source_variants__with_source_check__consume_last_line(
                        self, instruction_argument):
                    INSTRUCTION_CHECKER.check(
                        self, source, Arrangement.phase_agnostic(),
                        Expectation.phase_agnostic(
                            symbol_usages=asrt.matches_singleton_sequence(
                                expected_defined_symbol.
                                assert_matches_definition_of_sdv),
                            symbols_after_main=assert_symbol_table_is_singleton(
                                expected_defined_symbol.name,
                                expected_defined_symbol.value.
                                assert_matches_container_of_sdv)))
Esempio n. 15
0
 def test_contents_from_here_doc(self):
     # ARRANGE #
     string_value = rich_str_abs_stx.HereDocAbsStx(
         'single line in here doc\n')
     expected_file = fs.File('a-file-name.txt', string_value.value)
     rel_opt_conf = ARBITRARY_ALLOWED_DST_FILE_RELATIVITY
     dst_path = rel_opt_conf.path_abs_stx_of_name(expected_file.name)
     instruction_syntax = instr_abs_stx.create_w_explicit_contents(
         dst_path,
         string_source_abs_stx.StringSourceOfStringAbsStx(string_value),
     )
     for phase_is_after_act in [False, True]:
         checker = integration_check.checker(phase_is_after_act)
         with self.subTest(phase_is_after_act=phase_is_after_act):
             # ACT & ASSERT #
             checker.check__abs_stx__std_layouts_and_source_variants(
                 self, instruction_syntax,
                 Arrangement.phase_agnostic(tcds=TcdsArrangement(
                     pre_population_action=
                     SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ), ),
                 MultiSourceExpectation.phase_agnostic(
                     main_result=IS_SUCCESS,
                     side_effects_on_hds=f_asrt.dir_is_empty(),
                     symbol_usages=asrt.is_empty_sequence,
                     main_side_effects_on_sds=non_hds_dir_contains_exactly(
                         rel_opt_conf.root_dir__non_hds,
                         fs.DirContents([expected_file])),
                 ))
Esempio n. 16
0
    def test_WHEN_program_is_non_non_existing_system_command_THEN_result_SHOULD_be_error_message(self):
        failing_program_builder = program_abs_stx.TransformableProgramAbsStxBuilder(
            program_abs_stx.ProgramOfSystemCommandLineAbsStx.of_str(NON_EXISTING_SYSTEM_PROGRAM)
        )
        transformer = TO_UPPER_TRANSFORMER_SYMBOL
        symbols = transformer.symbol_table

        cases = failing_program_builder.with_and_without_transformer_cases(transformer.abstract_syntax)

        for transformation_case in cases:
            instruction_syntax = instr_abs_stx.create_w_explicit_contents(
                path_abs_stx.DefaultRelPathAbsStx('dst-file'),
                string_source_abs_stx.StringSourceOfProgramAbsStx(
                    ProcOutputFile.STDOUT,
                    transformation_case.value,
                    ignore_exit_code=False)
            )
            for phase_is_after_act in [False, True]:
                checker = integration_check.checker(phase_is_after_act)
                with self.subTest(phase_is_after_act=phase_is_after_act,
                                  transformation=transformation_case.name):
                    checker.check__abs_stx__std_layouts_and_source_variants(
                        self,
                        instruction_syntax,
                        Arrangement.phase_agnostic(
                            symbols=symbols,
                            tcds=TcdsArrangement(),
                        ),
                        MultiSourceExpectation.phase_agnostic(
                            symbol_usages=asrt.anything_goes(),
                            main_result=IS_FAILURE,
                        )
                    )
Esempio n. 17
0
 def test_single_file_in_root_dir(self):
     # ARRANGE #
     expected_file = File.empty('file-name.txt')
     for phase_is_after_act in [False, True]:
         checker = integration_check.checker(phase_is_after_act)
         for rel_opt_conf in ALLOWED_DST_FILE_RELATIVITIES:
             with self.subTest(
                     relativity_option_string=rel_opt_conf.option_argument,
                     phase_is_after_act=phase_is_after_act):
                 instruction_syntax = abs_stx.without_contents(
                     rel_opt_conf.path_abs_stx_of_name(expected_file.name))
                 # ACT & ASSERT #
                 checker.check__abs_stx__std_layouts_and_source_variants(
                     self, instruction_syntax,
                     Arrangement.phase_agnostic(tcds=TcdsArrangement(
                         pre_population_action=
                         SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ),
                                                ),
                     MultiSourceExpectation.phase_agnostic(
                         main_result=IS_SUCCESS,
                         side_effects_on_hds=f_asrt.dir_is_empty(),
                         symbol_usages=asrt.is_empty_sequence,
                         main_side_effects_on_sds=
                         non_hds_dir_contains_exactly(
                             rel_opt_conf.root_dir__non_hds,
                             fs.DirContents([expected_file])),
                     ))
Esempio n. 18
0
 def test_with_explicit_non_cd_relativity_and_source_layout_variants(self):
     # ARRANGE #
     relativity = RelOptionType.REL_TMP
     for is_after_act_phase in [False, True]:
         checker = embryo_checker(is_after_act_phase)
         for case in path_name_variants.SOURCE_LAYOUT_CASES:
             path_argument = RelOptPathArgument(case.input_value,
                                                relativity)
             with self.subTest(case.name,
                               is_after_act_phase=is_after_act_phase):
                 with self.subTest(case.name):
                     # ACT & ASSERT #
                     checker.check__w_source_variants(
                         self, path_argument.as_str,
                         Arrangement.phase_agnostic(tcds=TcdsArrangement(
                             tcds_contents=tcds_populators.
                             TcdsPopulatorForRelOptionType(
                                 relativity,
                                 DirContents(
                                     [Dir.empty(case.expected_value)]))), ),
                         MultiSourceExpectation.phase_agnostic(
                             side_effects_on_tcds=CwdAssertion(
                                 relativity,
                                 case.expected_value,
                             )))
Esempio n. 19
0
    def test_assignment_of_list_with_multiple_constant_elements(self):
        # ARRANGE #
        value_without_space = 'value_without_space'
        value_with_space = 'value with space'

        symbol_to_assign = ListSymbolContext.of_sdv(
            'the_symbol_name',
            sdvs.from_str_constants([value_without_space, value_with_space]))

        syntax = _syntax(
            symbol_to_assign,
            NonEmptyListAbsStx([
                ListElementStringAbsStx.of_str(value_without_space),
                ListElementStringAbsStx.of_str(value_with_space,
                                               QuoteType.SOFT),
            ]))

        expectation = MultiSourceExpectation.phase_agnostic(
            symbol_usages=asrt.matches_sequence(
                [symbol_to_assign.assert_matches_definition_of_sdv]),
            symbols_after_main=assert_symbol_table_is_singleton(
                symbol_to_assign.name,
                symbol_to_assign.value.assert_matches_container_of_sdv,
            ),
        )
        # ACT & ASSERT #
        INSTRUCTION_CHECKER.check__abs_stx__layout_and_source_variants(
            self,
            syntax,
            Arrangement.phase_agnostic(),
            expectation,
        )
Esempio n. 20
0
    def test_validate_should_fail_when_executable_does_not_exist(self):
        existing_file_to_interpret = 'existing-file-to-interpret.src'
        home_dir_contents = fs.DirContents(
            [File.empty(existing_file_to_interpret)])
        for relativity_option_conf in RELATIVITY_OPTIONS:
            argument = '{relativity_option} non-existing-file {interpret_option}' \
                       ' {rel_hds_case_option} {existing_file}'.format(
                relativity_option=relativity_option_conf.option_argument,
                interpret_option=syntax_elements.EXISTING_FILE_OPTION_NAME,
                rel_hds_case_option=REL_HDS_CASE_OPTION,
                existing_file=existing_file_to_interpret,
            )

            expectation = _expect_validation_error_and_symbol_usages_of(
                relativity_option_conf)

            arrangement = Arrangement.phase_agnostic(
                symbols=relativity_option_conf.symbols.in_arrangement(),
                tcds=TcdsArrangement(
                    hds_contents=hds_case_dir_contents(home_dir_contents), ),
            )
            with self.subTest(msg='option=' +
                              relativity_option_conf.test_case_description):
                EXECUTION_CHECKER.check__w_source_variants(
                    self, argument, arrangement, expectation)
Esempio n. 21
0
 def test_assignment_of_symbols_and_constant_text_within_soft_quotes(self):
     # ARRANGE #
     referred_symbol1 = SymbolWithReferenceSyntax('referred_symbol_1')
     referred_symbol2 = SymbolWithReferenceSyntax('referred_symbol_2')
     assigned_symbol = StringSymbolContext.of_sdv(
         'defined_symbol',
         string_sdv_from_fragments([
             symbol(referred_symbol1.name),
             constant(' between '),
             symbol(referred_symbol2.name),
         ]))
     source = single_line_source('{string_type} {name} = {soft_quote}{sym_ref1} between {sym_ref2}{soft_quote}',
                                 soft_quote=SOFT_QUOTE_CHAR,
                                 name=assigned_symbol.name,
                                 sym_ref1=referred_symbol1,
                                 sym_ref2=referred_symbol2)
     expectation = Expectation.phase_agnostic(
         symbol_usages=asrt.matches_sequence([
             assigned_symbol.assert_matches_definition_of_sdv,
         ]),
         symbols_after_main=assert_symbol_table_is_singleton(
             assigned_symbol.name,
             assigned_symbol.value.assert_matches_container_of_sdv,
         )
     )
     # ACT & ASSERT #
     INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Esempio n. 22
0
 def test_check_non_zero_exit_code(self):
     EXECUTION_CHECKER.check__w_source_variants(
         self,
         pgm_args.interpret_py_source_line('exit(1)').as_str,
         Arrangement.phase_agnostic(tcds=TcdsArrangement(), ),
         MultiSourceExpectation.phase_agnostic(
             main_result=result_assertions.equals(1, '')))
Esempio n. 23
0
    def test_assignment_of_single_symbol_reference(self):
        # ARRANGE #
        referred_symbol = SymbolWithReferenceSyntax('referred_symbol')
        expected_sdv = string_sdv_from_fragments([symbol(referred_symbol.name),
                                                  constant('\n')])
        assigned_symbol = StringSymbolContext.of_sdv(
            'defined_symbol',
            expected_sdv,
        )
        sb = SB.new_with(referred_symbol=referred_symbol,
                         name_of_defined_symbol=assigned_symbol.name)

        source = sb.lines(
            here_doc_lines(first_line_start='{string_type} {name_of_defined_symbol} = ',
                           marker='EOF',
                           contents_lines=[str(referred_symbol)])
        )
        # EXPECTATION #
        expectation = Expectation.phase_agnostic(
            symbol_usages=asrt.matches_sequence([
                assigned_symbol.assert_matches_definition_of_sdv,
            ]),
            symbols_after_main=assert_symbol_table_is_singleton(
                assigned_symbol.name,
                assigned_symbol.value.assert_matches_container_of_sdv,
            )
        )
        # ACT & ASSERT #
        INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Esempio n. 24
0
    def test_success_when_executable_does_exist(self):
        for relativity_option_conf in RELATIVITY_OPTIONS:
            argument = '{relativity_option} {executable_file}'.format(
                relativity_option=relativity_option_conf.option_argument,
                executable_file=EXECUTABLE_FILE_THAT_EXITS_WITH_CODE_0.
                file_name,
            )

            expectation = MultiSourceExpectation.phase_agnostic(
                symbol_usages=asrt.matches_sequence(
                    relativity_option_conf.symbols.
                    usage_expectation_assertions()), )

            arrangement = Arrangement.phase_agnostic(
                tcds=TcdsArrangement(
                    tcds_contents=relativity_option_conf.
                    populator_for_relativity_option_root(
                        fs.DirContents(
                            [EXECUTABLE_FILE_THAT_EXITS_WITH_CODE_0])), ),
                symbols=relativity_option_conf.symbols.in_arrangement(),
            )
            with self.subTest(
                    option=relativity_option_conf.test_case_description):
                EXECUTION_CHECKER.check__w_source_variants(
                    self, argument, arrangement, expectation)
Esempio n. 25
0
    def test_a_references_to_a_non_existing_env_var_SHOULD_be_replaced_with_empty_string(
            self):
        # ARRANGE #
        existing_var = NameAndValue('existing', 'EXISTING')
        non_existing_var__name = 'non_existing'
        new_var_to_set__name = 'new_var_to_set'

        source = SetVariableArgumentsAbsStx.of_str(
            new_var_to_set__name,
            env_var_ref_syntax(non_existing_var__name),
            phase_spec=None,
        )
        # ACT & ASSERT #

        CHECKER.check__abs_stx__std_layouts_and_source_variants(
            self, source,
            Arrangement.setup_phase_aware(
                process_execution_settings=proc_exe_env_for_test(
                    environ={existing_var.name: existing_var.value})),
            MultiSourceExpectation.setup_phase_aware(
                main_result=asrt.is_none,
                main_side_effect_on_environment_variables=asrt.equals({
                    existing_var.name:
                    existing_var.value,
                    new_var_to_set__name:
                    '',
                })))
Esempio n. 26
0
    def _check_cases_for_dst_file_setup__expect_pre_sds_validation_failure(
            self,
            dst_file_name: str,
            additional_symbols: Iterable[Entry] = (),
    ):
        dst_file = path_abs_stx.DefaultRelPathAbsStx(dst_file_name)
        cases_data = self._file_contents_cases()

        for file_contents_case in cases_data.file_contents_cases:
            instruction_syntax = instr_abs_stx.InstructionAbsStx(
                dst_file,
                file_contents_case.value,
            )

            symbols = cases_data.symbols.copy()
            symbols.add_all(additional_symbols)
            for phase_is_after_act in [False, True]:
                checker = integration_check.checker(phase_is_after_act)

                with self.subTest(
                        file_contents_variant=file_contents_case.name,
                        phase_is_after_act=phase_is_after_act):
                    # ACT & ASSERT #
                    checker.check__abs_stx(
                        self, instruction_syntax,
                        Arrangement.phase_agnostic(symbols=symbols, ),
                        Expectation.phase_agnostic_2(
                            validation=ValidationAssertions.
                            pre_sds_fails__w_any_msg(),
                            symbol_usages=asrt.anything_goes(),
                        ))
Esempio n. 27
0
    def test_successful_step_sequence(self):
        validate_pre_sds = 'validate_pre_sds'
        validate_post_sds = 'validate_post_sds'
        main = 'main'

        expected_recordings = [
            validate_pre_sds,
            validate_post_sds,
            main,
        ]
        recorder = []

        def recording_of(s: str) -> Callable[[InstructionEnvironmentForPostSdsStep,
                                              InstructionSettings,
                                              OsServices],
                                             None]:
            def ret_val(*args):
                recorder.append(s)

            return ret_val

        instruction_that_records_steps = instruction_embryo_that__phase_agnostic(
            validate_pre_sds_initial_action=recording_of(validate_pre_sds),
            validate_post_sds_initial_action=recording_of(validate_post_sds),
            main_initial_action=recording_of(main))
        self._check(
            ParserThatGives(instruction_that_records_steps),
            single_line_source(),
            Arrangement.phase_agnostic(),
            Expectation.phase_agnostic())

        self.assertEqual(expected_recordings,
                         recorder,
                         'step execution sequence')
Esempio n. 28
0
    def test_symbol_reference_in_dst_file_argument(self):
        dst_path_symbol = ConstantSuffixPathDdvSymbolContext(
            'dst_path_symbol', RelOptionType.REL_ACT, 'dst-file.txt',
            ACCEPTED_DST_RELATIVITY_VARIANTS)
        string_value = rich_str_abs_stx.HereDocAbsStx(
            'single line in here doc\n')
        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            dst_path_symbol.abstract_syntax,
            string_source_abs_stx.StringSourceOfStringAbsStx(string_value),
        )

        expected_file = fs.File(dst_path_symbol.path_suffix,
                                string_value.value)
        integration_check.CHECKER__BEFORE_ACT.check__abs_stx(
            self, instruction_syntax,
            Arrangement.phase_agnostic(
                tcds=TcdsArrangement(
                    pre_population_action=
                    SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ),
                symbols=dst_path_symbol.symbol_table,
            ),
            Expectation.phase_agnostic(
                main_result=IS_SUCCESS,
                symbol_usages=asrt.matches_singleton_sequence(
                    dst_path_symbol.reference_assertion),
                main_side_effects_on_sds=dir_contains_exactly(
                    dst_path_symbol.rel_option_type,
                    fs.DirContents([expected_file])),
            ))
Esempio n. 29
0
 def runTest(self):
     # ARRANGE #
     cases = [
         NameAndValue(
             'pre sds',
             (
                 RelOptionType.REL_HDS_CASE,
                 ValidationAssertions.pre_sds_fails__w_any_msg(),
             ),
         ),
         NameAndValue(
             'post sds',
             (
                 RelOptionType.REL_ACT,
                 ValidationAssertions.post_sds_fails__w_any_msg(),
             ),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             CHECKER.check__w_source_variants(
                 self,
                 command_line(
                     'program',
                     program_arguments.existing_path(
                         path_arguments.RelOptPathArgument('name', case.value[0]),
                     )
                 ).as_str,
                 Arrangement.phase_agnostic(),
                 MultiSourceExpectation.phase_agnostic(
                     validation=case.value[1],
                 ),
             )
Esempio n. 30
0
 def test(self):
     instruction_argument = src2(
         ValueType.PATH, 'ASSIGNED_NAME',
         '{rel_symbol} REFERENCED_SYMBOL component')
     for source in equivalent_source_variants__with_source_check__consume_last_line(
             self, instruction_argument):
         expected_path_sdv = path_sdvs.rel_symbol(
             SymbolReference(
                 'REFERENCED_SYMBOL',
                 ReferenceRestrictionsOnDirectAndIndirect(
                     PathAndRelativityRestriction(
                         type_parser.REL_OPTIONS_CONFIGURATION.
                         accepted_relativity_variants))),
             path_part_sdvs.from_constant_str('component'))
         expected_symbol_value = PathSymbolValueContext.of_sdv(
             expected_path_sdv)
         expected_symbol = PathSymbolContext('ASSIGNED_NAME',
                                             expected_symbol_value)
         INSTRUCTION_CHECKER.check(
             self, source, Arrangement.phase_agnostic(),
             Expectation.phase_agnostic(
                 symbol_usages=asrt.matches_sequence(
                     [expected_symbol.assert_matches_definition_of_sdv]),
                 symbols_after_main=assert_symbol_table_is_singleton(
                     expected_symbol.name, expected_symbol_value.
                     assert_matches_container_of_sdv)))