Esempio n. 1
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. 2
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. 3
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)))
Esempio n. 4
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. 5
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. 6
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. 7
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. 8
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. 9
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. 10
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. 11
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. 12
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. 13
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. 14
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. 15
0
 def test_fail_if_instruction_is_not_setup_phase_aware(self):
     with self.assertRaises(utils.TestError):
         self._check(
             ParserThatGives(instruction_embryo_that__phase_agnostic()),
             single_line_source(),
             Arrangement.setup_phase_aware(),
             Expectation.setup_phase_aware(),
         )
Esempio n. 16
0
 def test_that_default_expectation_assumes_no_symbol_usages(self):
     unexpected_symbol_usages = [
         data_references.reference_to__on_direct_and_indirect('symbol_name')]
     self._check_source_and_exe_variants__failing_assertions(
         ParserThatGives(
             instruction_embryo_that__phase_agnostic(
                 symbol_usages=do_return(unexpected_symbol_usages))),
         Arrangement.phase_agnostic(),
         Expectation.phase_agnostic(),
     )
Esempio n. 17
0
    def _test_symbol_reference_in_dst_file_and_contents(
            self, symbol_ref_syntax_2_contents_arguments: Callable[
                [str], StringSourceAbsStx],
            symbol_value_2_expected_contents: Callable[[str], str]):
        sub_dir_symbol = ConstantSuffixPathDdvSymbolContext(
            'sub_dir_symbol',
            RelOptionType.REL_ACT,
            'sub-dir',
            ACCEPTED_DST_RELATIVITY_VARIANTS,
        )
        contents_symbol = StringConstantSymbolContext(
            'contents_symbol_name',
            'contents symbol value',
            default_restrictions=asrt_rest.is__w_str_rendering(),
        )

        expected_file_contents = symbol_value_2_expected_contents(
            contents_symbol.str_value)

        expected_file = fs.File('a-file-name.txt', expected_file_contents)

        symbols = [sub_dir_symbol, contents_symbol]
        expected_symbol_references = SymbolContext.references_assertion_of_contexts(
            symbols)
        symbol_table = SymbolContext.symbol_table_of_contexts(symbols)

        contents_arguments = symbol_ref_syntax_2_contents_arguments(
            symbol_reference_syntax_for_name(contents_symbol.name))

        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            path_abs_stx.PathStringAbsStx.of_plain_components(
                [sub_dir_symbol.name__sym_ref_syntax, expected_file.name]),
            contents_arguments,
        )

        integration_check.CHECKER__AFTER_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=symbol_table,
            ),
            Expectation.phase_agnostic(
                main_result=IS_SUCCESS,
                symbol_usages=expected_symbol_references,
                main_side_effects_on_sds=dir_contains_exactly(
                    sub_dir_symbol.rel_option_type,
                    fs.DirContents(
                        [fs.Dir(sub_dir_symbol.path_suffix,
                                [expected_file])])),
            ))
Esempio n. 18
0
 def runTest(self):
     # ARRANGE #
     test_setup = StdinCheckWithProgramWExitCode0ForSuccess()
     # ACT & ASSERT #
     EXECUTION_CHECKER.check__abs_stx(
         self,
         test_setup.program_that_checks_stdin__syntax(
             'the contents of stdin'),
         Arrangement.phase_agnostic(tcds=TcdsArrangement(
             tcds_contents=test_setup.tcds_contents, ), ),
         Expectation.phase_agnostic(main_result=result_assertions.equals(
             test_setup.exit_code_of_successful_application, None)),
     )
Esempio n. 19
0
    def test_symbol_references(self):
        file_to_interpret = fs.File(
            'python-logic_symbol_utils.py',
            python_program_that_exits_with_code_given_as_first_cl_arg)
        file_to_interpret_symbol = StringConstantSymbolContext(
            'file_to_interpret_symbol', file_to_interpret.file_name)
        python_interpreter_symbol = StringConstantSymbolContext(
            'python_interpreter_symbol', sys.executable)
        exit_code_symbol = StringIntConstantSymbolContext(
            'exit_code_symbol', 72)

        argument = ' {python_interpreter} {interpret_option} {file_to_interpret}  "{exit_code}"'.format(
            python_interpreter=python_interpreter_symbol.name__sym_ref_syntax,
            interpret_option=args.option(
                syntax_elements.EXISTING_FILE_OPTION_NAME).as_str,
            file_to_interpret=file_to_interpret_symbol.name__sym_ref_syntax,
            exit_code=exit_code_symbol.name__sym_ref_syntax,
        )

        following_line = 'following line'
        source = remaining_source(argument, [following_line])

        arrangement = Arrangement.phase_agnostic(
            tcds=TcdsArrangement(tcds_contents=TcdsPopulatorForRelOptionType(
                path_relativities.ALL_REL_OPTIONS_ARG_CONFIG.options.
                default_option, fs.DirContents([file_to_interpret])), ),
            symbols=SymbolContext.symbol_table_of_contexts([
                python_interpreter_symbol,
                file_to_interpret_symbol,
                exit_code_symbol,
            ]),
        )

        expectation = Expectation.phase_agnostic(
            source=assert_source(current_line_number=asrt.equals(2),
                                 column_index=asrt.equals(0)),
            symbol_usages=asrt.matches_sequence([
                python_interpreter_symbol.usage_assertion__path_or_string(
                    syntax_elements.EXE_FILE_REL_OPTION_ARG_CONF.options.
                    accepted_relativity_variants),
                file_to_interpret_symbol.usage_assertion__path_or_string(
                    path_relativities.ALL_REL_OPTIONS_ARG_CONFIG.options.
                    accepted_relativity_variants),
                exit_code_symbol.usage_assertion__w_str_rendering,
            ]),
            main_result=result_assertions.equals(exit_code_symbol.int_value,
                                                 ''),
        )

        parser = sut.embryo_parser('instruction-name')
        embryo_check.check(self, parser, source, arrangement, expectation)
Esempio n. 20
0
    def test_successful_parse_and_application_of_non_trivial_matcher(self):
        # ARRANGE #

        defined_name = 'defined_name'

        expected_container = matches_container(
            asrt.equals(ValueType.FILES_MATCHER),
            type_sdv_assertions.matches_sdv_of_files_matcher()
        )

        not_num_files_beginning_with_a_eq_1_arg = self._not_num_files_beginning_with_a_eq_1_arg()

        cases = [
            NEA('should match',
                expected=matcher_assertions.is_matching_success(),
                actual=DirContents([
                    File.empty('a.x'),
                    File.empty('a.y'),
                    File.empty('b.x'),
                    File.empty('b.y'),
                ])
                ),
            NEA('should not match',
                expected=matcher_assertions.is_arbitrary_matching_failure(),
                actual=DirContents([
                    File.empty('a.x'),
                    File.empty('b.y'),
                    File.empty('b.x'),
                ])
                ),
        ]

        for case in cases:
            source = single_line_source(
                src2(ValueType.FILES_MATCHER, defined_name, not_num_files_beginning_with_a_eq_1_arg),
            )
            expectation = Expectation.phase_agnostic(
                symbol_usages=asrt.matches_sequence([
                    asrt_sym_usage.matches_definition(asrt.equals(defined_name),
                                                      expected_container)
                ]),
                symbols_after_main=assert_symbol_table_is_singleton(
                    defined_name,
                    expected_container,
                ),
                instruction_environment=
                AssertApplicationOfMatcherInSymbolTable(defined_name,
                                                        actual_dir_contents=case.actual,
                                                        expected_matcher_result=case.expected),
            )
Esempio n. 21
0
 def test_that_fails_due_to_missing_symbol_reference(self):
     symbol_usages_of_instruction = []
     self._check_source_and_exe_variants__failing_assertions(
         ParserThatGives(
             instruction_embryo_that__phase_agnostic(
                 symbol_usages=do_return(symbol_usages_of_instruction))),
         Arrangement.phase_agnostic(),
         Expectation.phase_agnostic(
             symbol_usages=asrt.matches_singleton_sequence(
                 matches_data_type_symbol_reference(
                     'symbol_name',
                     reference_restrictions.is_any_type_w_str_rendering()
                 )
             )),
     )
Esempio n. 22
0
class TestSuccessfulScenarios(unittest.TestCase):
    def test_successful_parse_of_arbitrary_matcher(self):
        defined_name = 'defined_name'
        file_name = 'the-file-name'

        # ARRANGE #

        argument_cases = [
            NameAndValue('value on same line',
                         '{files_condition}'
                         ),
            NameAndValue('value on following line',
                         '{new_line} {files_condition}'
                         ),
        ]

        for case in argument_cases:
            with self.subTest(case.name):
                source = remaining_source(
                    src2(ValueType.FILES_CONDITION, defined_name, case.value,
                         files_condition=arg_syntax.FilesCondition([arg_syntax.FileCondition(file_name)])),
                )

                # EXPECTATION #

                expected_container = matches_container(
                    asrt.equals(ValueType.FILES_CONDITION),
                    type_sdv_assertions.matches_sdv_of_files_condition_constant(
                        primitive_value=asrt_primitive.files_matches({
                            PurePosixPath(file_name): asrt.is_none
                        })
                    )
                )

                expectation = Expectation.phase_agnostic(
                    symbol_usages=asrt.matches_sequence([
                        asrt_sym_usage.matches_definition(asrt.equals(defined_name),
                                                          expected_container)
                    ]),
                    symbols_after_main=assert_symbol_table_is_singleton(
                        defined_name,
                        expected_container,
                    )
                )

                # ACT & ASSERT #

                INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Esempio n. 23
0
    def _check_cases_for_dst_file_setup__w_relativity_options(
        self,
        dst_file_name: str,
        dst_root_contents_before_execution: DirContents,
    ):

        cases_data = self._file_contents_cases()

        dst_file_relativity_cases = [
            conf_rel_non_hds(RelNonHdsOptionType.REL_CWD),
            conf_rel_non_hds(RelNonHdsOptionType.REL_ACT),
        ]

        for rel_opt_conf in dst_file_relativity_cases:
            non_hds_contents = rel_opt_conf.populator_for_relativity_option_root__non_hds(
                dst_root_contents_before_execution)
            dst_file = rel_opt_conf.path_abs_stx_of_name(dst_file_name)

            for file_contents_case in cases_data.file_contents_cases:
                instruction_syntax = instr_abs_stx.InstructionAbsStx(
                    dst_file,
                    file_contents_case.value,
                )
                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,
                            dst_file_variant=rel_opt_conf.name,
                            phase_is_after_act=phase_is_after_act):
                        # ACT & ASSERT #
                        checker.check__abs_stx(
                            self, instruction_syntax,
                            Arrangement.phase_agnostic(
                                tcds=TcdsArrangement(
                                    pre_population_action=
                                    SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN,
                                    tcds_contents=cases_data.
                                    pre_existing_files,
                                    non_hds_contents=non_hds_contents,
                                ),
                                symbols=cases_data.symbols,
                            ),
                            Expectation.phase_agnostic_2(
                                main_result=IS_FAILURE,
                                symbol_usages=asrt.anything_goes(),
                            ))
Esempio n. 24
0
    def runTest(self):
        # ARRANGE #
        dst_file_name = 'dst-file_name-file.txt'
        src_file = File('src-file_name-file.txt', 'contents')
        home_dir_contents = DirContents([src_file])
        expected_destination_dir_contents = DirContents([File(dst_file_name, src_file.contents)])

        dst_rel_option = rel_opt_conf.symbol_conf_rel_non_hds(
            defs.ARBITRARY_LEGAL_RELATIVITY__DST__NON_HDS,
            'DST_SYMBOL',
            defs.PATH_RELATIVITY_VARIANTS__DST,
        )
        for phase_is_after_act in [False, True]:
            with self.subTest(phase_is_after_act=phase_is_after_act):
                checker = instruction_embryo_check.Checker(sut.EmbryoParser(phase_is_after_act))
                src_rel_option = rel_opt_conf.symbol_conf_rel_hds(
                    defs.ARBITRARY_LEGAL_RELATIVITY__SRC__HDS,
                    'SRC_SYMBOL',
                    defs.path_relativity_variants__src(phase_is_after_act),
                )
                # ACT & ASSERT #
                checker.check(
                    self,
                    args.copy(src_rel_option.path_argument_of_rel_name(src_file.name),
                              dst_rel_option.path_argument_of_rel_name(dst_file_name)
                              ).as_remaining_source,
                    Arrangement.phase_agnostic(
                        tcds=TcdsArrangement(
                            hds_contents=src_rel_option.populator_for_relativity_option_root__hds(home_dir_contents),
                        ),
                        symbols=SymbolContext.symbol_table_of_contexts(
                            src_rel_option.symbols.contexts_for_arrangement() +
                            dst_rel_option.symbols.contexts_for_arrangement()
                        )
                    ),
                    Expectation.phase_agnostic_2(
                        symbol_usages=asrt.matches_sequence(
                            src_rel_option.symbols.usage_expectation_assertions() +
                            dst_rel_option.symbols.usage_expectation_assertions()
                        ),
                        main_side_effects_on_sds=sds_contents_check.non_hds_dir_contains_exactly(
                            dst_rel_option.root_dir__non_hds,
                            expected_destination_dir_contents),

                    ),
                )
Esempio n. 25
0
    def test_symbol_references(self):
        python_interpreter_symbol = StringConstantSymbolContext(
            'python_interpreter_symbol', sys.executable)
        execute_program_option_symbol = StringConstantSymbolContext(
            'execute_program_option', '-c')
        exit_code_symbol = StringIntConstantSymbolContext(
            'exit_code_symbol', 87)

        argument = ' {python_interpreter} {execute_program_option} {source_option}   exit({exit_code})  '.format(
            python_interpreter=python_interpreter_symbol.name__sym_ref_syntax,
            execute_program_option=execute_program_option_symbol.
            name__sym_ref_syntax,
            source_option=syntax_elements.
            REMAINING_PART_OF_CURRENT_LINE_AS_LITERAL_MARKER,
            exit_code=exit_code_symbol.name__sym_ref_syntax,
        )

        arrangement = Arrangement.phase_agnostic(
            symbols=SymbolContext.symbol_table_of_contexts([
                python_interpreter_symbol,
                execute_program_option_symbol,
                exit_code_symbol,
            ]),
            tcds=TcdsArrangement(),
        )

        source = remaining_source(argument, ['following line'])

        expectation = Expectation.phase_agnostic(
            source=assert_source(current_line_number=asrt.equals(2),
                                 column_index=asrt.equals(0)),
            symbol_usages=asrt.matches_sequence([
                python_interpreter_symbol.usage_assertion__path_or_string(
                    syntax_elements.EXE_FILE_REL_OPTION_ARG_CONF.options.
                    accepted_relativity_variants),
                execute_program_option_symbol.usage_assertion__w_str_rendering,
                exit_code_symbol.usage_assertion__w_str_rendering,
            ]),
            main_result=result_assertions.equals(exit_code_symbol.int_value,
                                                 ''),
        )

        parser = sut.embryo_parser('instruction-name')
        embryo_check.check(self, parser, source, arrangement, expectation)
Esempio n. 26
0
 def test_assignment_of_single_symbol_reference(self):
     # ARRANGE #
     referred_symbol = SymbolWithReferenceSyntax('referred_symbol')
     assigned_symbol = StringSymbolContext.of_sdv('defined_symbol',
                                                  string_sdv_from_fragments([symbol(referred_symbol.name)]))
     source = single_line_source('{string_type} {name} = {symbol_reference}',
                                 name=assigned_symbol.name,
                                 symbol_reference=referred_symbol)
     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. 27
0
 def test_ERROR_when_file_does_not_exist__without_explicit_destination__hds(self):
     for execution_checker in _EXECUTION_CHECKERS:
         for relativity_option in source_relativity_options__hds():
             with self.subTest(parser=execution_checker.name,
                               relativity=relativity_option.test_case_description):
                 execution_checker.value.check(
                     self,
                     args.copy(
                         relativity_option.path_argument_of_rel_name('source-that-do-not-exist')
                     ).as_remaining_source,
                     Arrangement.phase_agnostic(
                         tcds=TcdsArrangement(),
                         symbols=relativity_option.symbols.in_arrangement(),
                     ),
                     Expectation.phase_agnostic_2(
                         validation=ValidationAssertions.pre_sds_fails__w_any_msg(),
                         symbol_usages=relativity_option.symbols.usages_expectation(),
                     ),
                 )
Esempio n. 28
0
class TestSuccessfulScenarios(unittest.TestCase):
    def test_successful_parse_of_arbitrary_matcher(self):
        defined_name = 'defined_name'

        # ARRANGE #

        argument_cases = [
            NameAndValue('value on same line',
                         '{matcher_argument}'
                         ),
            NameAndValue('value on following line',
                         '{new_line} {matcher_argument}'
                         ),
        ]

        for case in argument_cases:
            with self.subTest(case.name):
                source = single_line_source(
                    src2(ValueType.FILES_MATCHER, defined_name, case.value,
                         matcher_argument=arg_syntax.arbitrary_single_line_value_that_must_not_be_quoted()),
                )

                # EXPECTATION #

                expected_container = matches_container(
                    asrt.equals(ValueType.FILES_MATCHER),
                    type_sdv_assertions.matches_sdv_of_files_matcher()
                )

                expectation = Expectation.phase_agnostic(
                    symbol_usages=asrt.matches_sequence([
                        asrt_sym_usage.matches_definition(asrt.equals(defined_name),
                                                          expected_container)
                    ]),
                    symbols_after_main=assert_symbol_table_is_singleton(
                        defined_name,
                        expected_container,
                    )
                )

                # ACT & ASSERT #

                INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Esempio n. 29
0
def _expect_definition_of(
        defined_name: str,
        symbols_for_evaluation: SymbolTable,
        references: Assertion[Sequence[SymbolReference]],
        expected_contents: str,
        may_depend_on_external_resources: bool,
) -> Expectation[None]:
    sdv_expectation = type_sdv_assertions.matches_sdv(
        asrt.is_instance(StringSourceSdv),
        references=references,
        symbols=symbols_for_evaluation,
        resolved_value=asrt.anything_goes(),
        custom=asrt.is_instance_with(
            StringSourceSdv,
            str_src_check.execution_assertion(
                intgr_arr_exp.Arrangement(
                    symbols=symbols_for_evaluation,
                    tcds=TcdsArrangement(),
                ),
                primitive=str_src_check.primitive__const(
                    asrt_string_source.pre_post_freeze__matches_str__const(
                        expected_contents,
                        may_depend_on_external_resources=may_depend_on_external_resources
                    )
                )
            )
        )
    )
    expected_container = matches_container(
        asrt.equals(ValueType.STRING_SOURCE),
        sdv_expectation,
    )
    return Expectation.phase_agnostic(
        symbol_usages=asrt.matches_sequence([
            asrt_sym_usage.matches_definition(asrt.equals(defined_name),
                                              expected_container),
        ]),
        symbols_after_main=assert_symbol_table_is_singleton(
            defined_name,
            expected_container,
        )
    )
Esempio n. 30
0
    def test_successful_parse_and_application_of_non_trivial_matcher(self):
        defined_name = 'defined_name'

        expected_container = matches_container(
            asrt.equals(ValueType.STRING_MATCHER),
            matches_sdv_of_string_matcher())

        not_num_lines_eq_1_matcher_arg = self._not_num_lines_eq_1_matcher_arg()

        cases = [
            NEA('should match',
                expected=matcher_assertions.is_matching_success(),
                actual=lines_content([
                    '1st line',
                    '2nd line',
                ])),
            NEA('should not match',
                expected=matcher_assertions.is_arbitrary_matching_failure(),
                actual='a single line'),
        ]

        for case in cases:
            source = single_line_source(
                src2(ValueType.STRING_MATCHER, defined_name,
                     not_num_lines_eq_1_matcher_arg), )
            expectation = Expectation.phase_agnostic(
                symbol_usages=asrt.matches_sequence([
                    asrt_sym_usage.matches_definition(
                        asrt.equals(defined_name), expected_container)
                ]),
                symbols_after_main=assert_symbol_table_is_singleton(
                    defined_name,
                    expected_container,
                ),
                instruction_environment=AssertApplicationOfMatcherInSymbolTable(
                    self,
                    defined_name,
                    actual_model_contents=case.actual,
                    expected_matcher_result=case.expected),
            )

            with self.subTest(case.name):