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])),
            ))
示例#2
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)))
示例#3
0
    def test_possibility_to_have_sds_path_references_in_argument(self):
        file_name_of_referenced_file = 'file-name.txt'
        symbol = ConstantSuffixPathDdvSymbolContext(
            'symbol_name', RelOptionType.REL_TMP, file_name_of_referenced_file)

        executable = 'the-executable'

        command_line = '{executable} {symbol}'.format(
            executable=executable,
            symbol=symbol.name__sym_ref_syntax,
        )

        arrangement = arrangement_w_tcds(
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([
                    fs.python_executable_file(
                        executable,
                        PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES
                    )
                ])),
            symbol_table=symbol.symbol_table)

        expectation = Expectation(
            execute=eh_assertions.is_exit_code(0),
            symbol_usages=asrt.matches_singleton_sequence(
                symbol.reference_assertion__w_str_rendering),
            post_sds=PostSdsExpectation.constant(
                sub_process_result_from_execute=pr.stdout(
                    str_asrt.contains(file_name_of_referenced_file))),
        )

        check_execution(self, sut.actor(), [instr([command_line])],
                        arrangement, expectation)
示例#4
0
    def test_file_path(self):
        relativity_test_cases = [
            (RelOptionType.REL_HDS_CASE, True),
            (RelOptionType.REL_ACT, False),
        ]
        path_suffix_str = 'path-suffix-file.txt'
        path_suffix_test_cases = [
            (path_part_sdvs.from_constant_str(path_suffix_str), ()),
            (path_part_sdvs.from_string(
                string_sdv_of_single_symbol_reference(
                    'path_suffix_symbol',
                    reference_restrictions.is_any_type_w_str_rendering())),
             (StringConstantSymbolContext('path_suffix_symbol',
                                          path_suffix_str).entry, )),
        ]
        for rel_option, exists_pre_sds in relativity_test_cases:
            # ARRANGE #
            path_component_from_referenced_path = 'path-component-from-referenced-file-ref'
            referenced_sym = ConstantSuffixPathDdvSymbolContext(
                'path_symbol', rel_option, path_component_from_referenced_path)

            for path_suffix, symbol_table_entries in path_suffix_test_cases:
                fr_sdv_to_check = sut.PathSdvRelSymbol(
                    path_suffix,
                    _symbol_reference_of_path_with_accepted(
                        referenced_sym.name, rel_option))
                symbol_table = referenced_sym.symbol_table
                symbol_table.add_all(symbol_table_entries)
                tcds = fake_tcds()
                expected_root_path = _root_path_of_option(rel_option, tcds)
                expected_path = expected_root_path / path_component_from_referenced_path / path_suffix_str
                expected_path_str = str(expected_path)
                environment = PathResolvingEnvironmentPreOrPostSds(
                    tcds, symbol_table)
                with self.subTest(msg=str(rel_option)):
                    # ACT #
                    path_to_check = fr_sdv_to_check.resolve(
                        environment.symbols)
                    if exists_pre_sds:
                        tested_path_msg = 'value_pre_sds'
                        actual_path = path_to_check.value_pre_sds(
                            environment.hds)
                    else:
                        tested_path_msg = 'value_post_sds'
                        actual_path = path_to_check.value_post_sds(
                            environment.sds)
                    actual_path_pre_or_post_sds = path_to_check.value_of_any_dependency(
                        environment.tcds)
                    # ASSERT #
                    self.assertEqual(expected_path_str, str(actual_path),
                                     tested_path_msg)
                    self.assertEqual(expected_path_str,
                                     str(actual_path_pre_or_post_sds),
                                     'value_of_any_dependency')
    def runTest(self):
        # ARRANGE #
        text_printed_by_program = StringSymbolContext.of_constant('STRING_TO_PRINT_SYMBOL', 'hello world')

        dst_file_symbol = ConstantSuffixPathDdvSymbolContext(
            'DST_FILE_SYMBOL',
            RelOptionType.REL_ACT,
            'dst-file-name.txt',
            sut.REL_OPT_ARG_CONF.options.accepted_relativity_variants,
        )

        to_upper_transformer = TO_UPPER_TRANSFORMER_SYMBOL

        transformed_program_output_contents_syntax = string_source_abs_stx.StringSourceOfProgramAbsStx(
            ProcOutputFile.STDOUT,
            program_abs_stx.FullProgramAbsStx(
                program_abs_stx.ProgramOfPythonInterpreterAbsStx.of_execute_python_src_string(
                    py_programs.single_line_pgm_that_prints_to(
                        ProcOutputFile.STDOUT,
                        text_printed_by_program.name__sym_ref_syntax
                    )
                ),
                transformation=to_upper_transformer.abstract_syntax,
            )
        )
        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            dst_file_symbol.abstract_syntax,
            transformed_program_output_contents_syntax
        )
        symbols = SymbolContext.symbol_table_of_contexts([
            dst_file_symbol,
            text_printed_by_program,
            to_upper_transformer,
        ])

        # ACT & ASSERT #
        checker = integration_check.checker(False)
        checker.check__abs_stx__std_layouts_and_source_variants(
            self,
            instruction_syntax,
            Arrangement.phase_agnostic(
                symbols=symbols,
                tcds=TcdsArrangement(),
            ),
            MultiSourceExpectation.phase_agnostic(
                main_result=IS_SUCCESS,
                symbol_usages=asrt.matches_sequence([
                    dst_file_symbol.reference_assertion__path_or_string,
                    text_printed_by_program.reference_assertion__w_str_rendering,
                    to_upper_transformer.reference_assertion,
                ]),
            )
        )
示例#6
0
    def runTest(self):
        # ARRANGE #

        to_upper_transformer = StringTransformerSymbolContext.of_primitive(
            'TRANSFORMER_SYMBOL',
            string_transformers.to_uppercase(),
        )

        src_file = fs.File('src-file.txt', 'contents of source file')
        src_file_rel_conf = conf_rel_hds(RelHdsOptionType.REL_HDS_CASE)

        expected_contents = src_file.contents.upper()

        path_relativity_variants = PathRelativityVariants({src_file_rel_conf.relativity}, True)
        checker = integration_check.checker(RelOptionsConfiguration(path_relativity_variants,
                                                                    src_file_rel_conf.relativity))

        src_file_symbol = ConstantSuffixPathDdvSymbolContext(
            'SRC_FILE_SYMBOL',
            src_file_rel_conf.relativity,
            src_file.name,
            path_relativity_variants,
        )
        string_source_syntax = string_source_abs_stx.TransformedStringSourceAbsStx(
            string_source_abs_stx.StringSourceOfFileAbsStx(src_file_symbol.abstract_syntax),
            to_upper_transformer.abstract_syntax,
        )
        symbol_table = SymbolContext.symbol_table_of_contexts([
            src_file_symbol,
            to_upper_transformer,
        ])

        # ACT & ASSERT #
        checker.check__abs_stx__layouts__std_source_variants__wo_input(
            self,
            OptionallyOnNewLine(string_source_syntax),
            arrangement_w_tcds(
                symbols=symbol_table,
                hds_contents=src_file_rel_conf.populator_for_relativity_option_root__hds(
                    DirContents([src_file]))
            ),
            MultiSourceExpectation.of_prim__const(
                asrt_string_source.pre_post_freeze__matches_str__const(
                    expected_contents,
                    may_depend_on_external_resources=True,
                ),
                symbol_references=asrt.matches_sequence([
                    src_file_symbol.reference_assertion__path_or_string,
                    to_upper_transformer.reference_assertion,
                ]),
            ),
        )
    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])])),
            ))
示例#8
0
 def test_resolve_of_path_symbol_SHOULD_give_string_constant(self):
     # ARRANGE #
     symbol = ConstantSuffixPathDdvSymbolContext('the_symbol_name',
                                                 RelOptionType.REL_ACT,
                                                 'file-name')
     fragment = impl.SymbolStringFragmentSdv(
         symbol.reference__w_str_rendering)
     symbol_table = symbol.symbol_table
     # ACT #
     actual = fragment.resolve(symbol_table)
     # ASSERT #
     self.assertIsInstance(actual, csv.PathFragmentDdv)
     assertion = equals_string_fragment_ddv(csv.PathFragmentDdv(symbol.ddv))
     assertion.apply_without_message(self, actual)
示例#9
0
 def test_exists_pre_sds(self):
     # ARRANGE #
     relativity_test_cases = [
         (
             RelOptionType.REL_HDS_CASE,
             True,
         ),
         (
             RelOptionType.REL_TMP,
             False,
         ),
     ]
     path_suffix_test_cases = [
         (path_part_sdvs.from_constant_str('file.txt'), []),
         (
             path_part_sdvs.from_string(
                 string_sdv_of_single_symbol_reference(
                     'path_suffix_symbol_name',
                     reference_restrictions.is_any_type_w_str_rendering()),
             ),
             [
                 StringConstantSymbolContext('path_suffix_symbol_name',
                                             'path-suffix').entry
             ],
         ),
     ]
     for rel_option_type_of_referenced_symbol, expected_exists_pre_sds in relativity_test_cases:
         referenced_path = ConstantSuffixPathDdvSymbolContext(
             'SYMBOL_NAME', rel_option_type_of_referenced_symbol,
             'referenced-file-name')
         for path_suffix, sym_tbl_entries in path_suffix_test_cases:
             symbol_table = referenced_path.symbol_table
             symbol_table.add_all(sym_tbl_entries)
             with self.subTest(
                     msg='rel_option_type={} ,path_suffix_type={}'.format(
                         rel_option_type_of_referenced_symbol,
                         path_suffix)):
                 path_sdv_to_check = sut.PathSdvRelSymbol(
                     path_suffix,
                     _symbol_reference_of_path_with_accepted(
                         referenced_path.name,
                         rel_option_type_of_referenced_symbol))
                 # ACT #
                 actual = path_sdv_to_check.resolve(
                     symbol_table).exists_pre_sds()
                 # ASSERT #
                 self.assertEqual(expected_exists_pre_sds, actual,
                                  'existence pre SDS')
示例#10
0
    def runTest(self):
        sub_dir_of_home = 'sub-dir'
        dir_symbol = ConstantSuffixPathDdvSymbolContext('dir_symbol_name',
                                                        RelOptionType.REL_HDS_ACT,
                                                        sub_dir_of_home,
                                                        PATH_RELATIVITY_VARIANTS_FOR_FILE_TO_RUN)

        source_file_name_symbol = StringConstantSymbolContext('source_file_name_symbol_name',
                                                              'the-source-file.py')

        argument = 'argument_string'

        expected_output = lines_content([argument])

        command_line = '{dir}/{file_name}  {argument} '.format(
            dir=dir_symbol.name__sym_ref_syntax,
            file_name=source_file_name_symbol.name__sym_ref_syntax,
            argument=argument,
        )

        executable_file = fs.File(
            source_file_name_symbol.str_value,
            PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES)

        arrangement = arrangement_w_tcds(
            hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, fs.DirContents([
                fs.Dir(sub_dir_of_home, [executable_file])
            ])),
            symbol_table=SymbolContext.symbol_table_of_contexts([
                dir_symbol,
                source_file_name_symbol,
            ])
        )

        expectation = Expectation(
            symbol_usages=asrt.matches_sequence([
                dir_symbol.reference_assertion__path_or_string,
                source_file_name_symbol.reference_assertion__path_component,
            ]),
            execute=eh_assertions.is_exit_code(0),
            post_sds=PostSdsExpectation.constant(
                sub_process_result_from_execute=pr.stdout(asrt.Equals(expected_output,
                                                                      'CLI arguments, one per line'))
            ),
        )
        self._check(command_line,
                    arrangement,
                    expectation)
示例#11
0
    def test_multiple_symbol_references_in_executable(self):
        sub_dir_of_home = 'sub-dir'
        dir_symbol = ConstantSuffixPathDdvSymbolContext(
            'dir_symbol_name', RelOptionType.REL_HDS_ACT, sub_dir_of_home,
            PATH_RELATIVITY_VARIANTS_FOR_FILE_TO_RUN)

        executable_file_name_symbol = StringConstantSymbolContext(
            'executable_file_name_symbol_name', 'the-executable-file')

        argument = 'argument_string'

        expected_output = lines_content([argument])

        command_line = '{dir}/{file_name}  {argument} '.format(
            dir=dir_symbol.name__sym_ref_syntax,
            file_name=executable_file_name_symbol.name__sym_ref_syntax,
            argument=argument,
        )

        executable_file = fs.python_executable_file(
            executable_file_name_symbol.str_value,
            PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES
        )

        arrangement = arrangement_w_tcds(
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([fs.Dir(sub_dir_of_home, [executable_file])])),
            symbol_table=SymbolContext.symbol_table_of_contexts([
                dir_symbol,
                executable_file_name_symbol,
            ]))

        expectation = Expectation(
            symbol_usages=asrt.matches_sequence([
                dir_symbol.reference_assertion__path_or_string,
                executable_file_name_symbol.
                reference_assertion__string__w_all_indirect_refs_are_strings,
            ]),
            execute=eh_assertions.is_exit_code(0),
            post_sds=PostSdsExpectation.
            constant(sub_process_result_from_execute=pr.stdout(
                asrt.Equals(expected_output, 'CLI arguments, one per line'))),
        )
        check_execution(self, sut.actor(), [instr([command_line])],
                        arrangement, expectation)
示例#12
0
 def test(self):
     file_symbol = ConstantSuffixPathDdvSymbolContext(
         'file_symbol', RelOptionType.REL_TMP, 'first_path_component')
     string_symbol = StringConstantSymbolContext('string_symbol',
                                                 'string symbol value')
     reference_of_relativity_symbol = SymbolReference(
         file_symbol.name,
         path_relativity_restriction(
             syntax_elements.EXE_FILE_REL_OPTION_ARG_CONF.options.
             accepted_relativity_variants))
     reference_of_path_string_symbol_as_path_component = SymbolReference(
         string_symbol.name,
         ReferenceRestrictionsOnDirectAndIndirect(
             direct=value_restrictions.is_string(),
             indirect=value_restrictions.is_string()),
     )
     symbols = SymbolContext.symbol_table_of_contexts([
         file_symbol,
         string_symbol,
     ])
     cases = [
         Case.of(
             'symbol references in file',
             RelSymbolPathAbsStx(file_symbol.name,
                                 string_symbol.name__sym_ref_syntax),
             arguments=(),
             expectation=ExpectationOnExeFile(
                 path_ddv=path_ddvs.stacked(
                     file_symbol.ddv,
                     path_ddvs.constant_path_part(string_symbol.str_value)),
                 expected_symbol_references=[
                     reference_of_relativity_symbol,
                     reference_of_path_string_symbol_as_path_component
                 ],
                 symbol_for_value_checks=symbols,
             ),
             source_after_parse=asrt_source.is_at_end_of_line(1),
         ),
     ]
     for case in cases:
         with self.subTest(name=case.name):
             _parse_and_check(self, case)
    def runTest(self):
        symbol = ConstantSuffixPathDdvSymbolContext('symbol_name',
                                                    RelOptionType.REL_ACT,
                                                    'the-path-suffix')

        program_that_prints_value_of_symbol = 'print("{symbol}")'

        single_source_line = program_that_prints_value_of_symbol.format(
            symbol=symbol.name__sym_ref_syntax, )

        self._check(
            single_source_line,
            arrangement_w_tcds(symbol_table=symbol.symbol_table),
            Expectation(
                symbol_usages=asrt.matches_singleton_sequence(
                    symbol.reference_assertion__w_str_rendering),
                post_sds=PostSdsExpectation.constant(
                    sub_process_result_from_execute=asrt_pr.stdout(
                        str_asrt.contains(symbol.path_suffix))),
            ))
示例#14
0
    def test(self):
        expected_defined_symbol = ConstantSuffixPathDdvSymbolContext(
            'name', type_parser.REL_OPTIONS_CONFIGURATION.default_option,
            'component')

        instruction_argument = src2(ValueType.PATH,
                                    expected_defined_symbol.name,
                                    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(
                        'name', expected_defined_symbol.value.
                        assert_matches_container_of_sdv)))
def _path_case(contents_transformation: Callable[[str], str]) -> Case:
    relativity = RelOptionType.REL_TMP
    path_suffix = 'the path suffix'

    def get_assertion_on_primitive(
            env: AssertionResolvingEnvironment) -> Assertion[StringSource]:
        path_as_str = str(env.tcds.sds.user_tmp_dir / path_suffix)
        return asrt_string_source.pre_post_freeze__matches_str__const(
            contents_transformation(path_as_str),
            may_depend_on_external_resources=False)

    symbol_context = ConstantSuffixPathDdvSymbolContext(
        'PATH_SYMBOL',
        relativity,
        path_suffix,
        ARBITRARY_FILE_RELATIVITIES.accepted_relativity_variants,
    )
    return Case(
        StringSourceOfStringAbsStx.of_plain(
            StringLiteralAbsStx(symbol_context.name__sym_ref_syntax,
                                QuoteType.SOFT)),
        symbol_context,
        get_assertion_on_primitive,
    )
示例#16
0
    def test_resolve(self):
        string_constant_1 = 'string constant 1'
        string_constant_2 = 'string constant 2'
        string_symbol = StringConstantSymbolContext('string_symbol_name',
                                                    'string symbol value')
        path_symbol = ConstantSuffixPathDdvSymbolContext(
            'path_symbol_name', RelOptionType.REL_ACT, 'file-name')
        list_symbol = ListConstantSymbolContext(
            'list_symbol_name', ['list element 1', 'list element 2'])

        cases = [
            (
                'no fragments',
                sut.StringSdv(()),
                empty_symbol_table(),
                csv.StringDdv(()),
            ),
            (
                'single string constant fragment',
                sut.StringSdv(
                    (impl.ConstantStringFragmentSdv(string_constant_1), )),
                empty_symbol_table(),
                csv.StringDdv((csv.ConstantFragmentDdv(string_constant_1), )),
            ),
            (
                'multiple single string constant fragments',
                sut.StringSdv(
                    (impl.ConstantStringFragmentSdv(string_constant_1),
                     impl.ConstantStringFragmentSdv(string_constant_2))),
                empty_symbol_table(),
                csv.StringDdv((csv.ConstantFragmentDdv(string_constant_1),
                               csv.ConstantFragmentDdv(string_constant_2))),
            ),
            (
                'single symbol fragment/symbol is a string',
                sut.StringSdv((impl.SymbolStringFragmentSdv(
                    string_symbol.reference__w_str_rendering), )),
                string_symbol.symbol_table,
                csv.StringDdv(
                    (csv.ConstantFragmentDdv(string_symbol.str_value), )),
            ),
            (
                'single symbol fragment/symbol is a path',
                sut.StringSdv((impl.SymbolStringFragmentSdv(
                    path_symbol.reference__w_str_rendering), )),
                path_symbol.symbol_table,
                csv.StringDdv((csv.PathFragmentDdv(path_symbol.ddv), )),
            ),
            (
                'single symbol fragment/symbol is a list',
                sut.StringSdv((impl.SymbolStringFragmentSdv(
                    list_symbol.reference__w_str_rendering), )),
                list_symbol.symbol_table,
                csv.StringDdv((csv.ListFragmentDdv(list_symbol.ddv), )),
            ),
            (
                'multiple fragments of different types',
                sut.StringSdv((
                    impl.SymbolStringFragmentSdv(
                        string_symbol.reference__w_str_rendering),
                    impl.ConstantStringFragmentSdv(string_constant_1),
                    impl.SymbolStringFragmentSdv(
                        path_symbol.reference__w_str_rendering),
                    impl.SymbolStringFragmentSdv(
                        list_symbol.reference__w_str_rendering),
                )),
                SymbolContext.symbol_table_of_contexts([
                    string_symbol,
                    path_symbol,
                    list_symbol,
                ]),
                csv.StringDdv((
                    csv.ConstantFragmentDdv(string_symbol.str_value),
                    csv.ConstantFragmentDdv(string_constant_1),
                    csv.PathFragmentDdv(path_symbol.ddv),
                    csv.ListFragmentDdv(list_symbol.ddv),
                )),
            ),
        ]
        for test_name, string_value, symbol_table, expected in cases:
            with self.subTest(test_name=test_name):
                actual = string_value.resolve(symbol_table)
                assertion = equals_string_ddv(expected)
                assertion.apply_without_message(self, actual)
示例#17
0
    def test_symbol_usages(self):
        # ARRANGE #

        to_upper_transformer = StringTransformerSymbolContext.of_primitive(
            'TRANSFORMER_SYMBOL',
            string_transformers.to_uppercase(),
        )

        src_file = fs.File('src-file.txt', 'contents of source file')
        src_file_rel_conf = conf_rel_hds(RelHdsOptionType.REL_HDS_CASE)

        expected_dst_file = fs.File('dst-file-name.txt',
                                    src_file.contents.upper())

        dst_file_symbol = ConstantSuffixPathDdvSymbolContext(
            'DST_FILE_SYMBOL',
            RelOptionType.REL_TMP,
            expected_dst_file.name,
            sut.REL_OPT_ARG_CONF.options.accepted_relativity_variants,
        )

        for phase_is_after_act in [False, True]:
            checker = integration_check.checker(phase_is_after_act)
            src_file_rel_opt_conf = src_rel_opt_arg_conf_for_phase(
                phase_is_after_act)

            src_file_symbol = ConstantSuffixPathDdvSymbolContext(
                'SRC_FILE_SYMBOL',
                src_file_rel_conf.relativity_option,
                src_file.name,
                src_file_rel_opt_conf.options.accepted_relativity_variants,
            )
            transformed_file_contents = string_source_abs_stx.TransformedStringSourceAbsStx(
                string_source_abs_stx.StringSourceOfFileAbsStx(
                    src_file_symbol.abstract_syntax),
                StringTransformerSymbolReferenceAbsStx(
                    to_upper_transformer.name))
            instruction_syntax = instr_abs_stx.create_w_explicit_contents(
                dst_file_symbol.abstract_syntax,
                transformed_file_contents,
            )
            symbols = SymbolContext.symbol_table_of_contexts([
                dst_file_symbol,
                src_file_symbol,
                to_upper_transformer,
            ])

            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(
                        symbols=symbols,
                        tcds=TcdsArrangement(
                            hds_contents=src_file_rel_conf.
                            populator_for_relativity_option_root__hds(
                                DirContents([src_file]))),
                    ),
                    MultiSourceExpectation.phase_agnostic(
                        main_result=IS_SUCCESS,
                        symbol_usages=asrt.matches_sequence([
                            dst_file_symbol.
                            reference_assertion__path_or_string,
                            src_file_symbol.
                            reference_assertion__path_or_string,
                            is_reference_to_string_transformer__usage(
                                to_upper_transformer.name),
                        ]),
                    ),
                )