Ejemplo n.º 1
0
    def runTest(self):
        to_upper_transformer = NameAndValue(
            'TRANSFORMER_SYMBOL',
            StringTransformerSdvConstantTestImpl(to_uppercase()))

        src_file = fs.File('src-file.txt', 'contents of source file')
        src_file_symbol = NameAndValue('SRC_FILE_SYMBOL', src_file.name)

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

        transformed_file_syntax = string_source_abs_stx.TransformedStringSourceAbsStx(
            string_source_abs_stx.StringSourceOfFileAbsStx(
                PathSymbolReferenceAbsStx(src_file_symbol.name)),
            str_trans_abs_stx.StringTransformerSymbolReferenceAbsStx(
                to_upper_transformer.name))
        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            PathSymbolReferenceAbsStx(dst_file_symbol.name),
            transformed_file_syntax,
        )

        # ACT #
        for layout_case in tokens_layout.STANDARD_LAYOUT_SPECS:
            with self.subTest(layout_case.name):
                instruction = self.conf.parse_checker.parse__abs_stx(
                    self, instruction_syntax, layout_case.value)
                assert isinstance(
                    instruction,
                    TestCaseInstructionWithSymbols)  # Sanity check

                # ASSERT #

                expected_symbol_usages = [
                    asrt_sym_ref.matches_reference_2(
                        dst_file_symbol.name,
                        asrt_w_str_rend_rest.equals__w_str_rendering(
                            path_or_string_reference_restrictions(
                                new_file.REL_OPT_ARG_CONF.options.
                                accepted_relativity_variants))),
                    asrt_sym_ref.matches_reference_2(
                        src_file_symbol.name,
                        asrt_w_str_rend_rest.equals__w_str_rendering(
                            path_or_string_reference_restrictions(
                                src_rel_opt_arg_conf_for_phase(
                                    self.conf.phase_is_after_act()).options.
                                accepted_relativity_variants))),
                    is_reference_to_string_transformer__usage(
                        to_upper_transformer.name),
                ]
                expected_symbol_references = asrt.matches_sequence(
                    expected_symbol_usages)
                expected_symbol_references.apply_without_message(
                    self, instruction.symbol_usages())
Ejemplo n.º 2
0
 def expected_symbols(self) -> Sequence[Assertion[SymbolReference]]:
     return [
         asrt_sym_ref.matches_reference_2(
             self.min_depth.name,
             asrt_data_rest.equals__w_str_rendering(
                 reference_restrictions.
                 is_string__all_indirect_refs_are_strings())),
         asrt_sym_ref.matches_reference_2(
             self.max_depth.name,
             asrt_data_rest.equals__w_str_rendering(
                 reference_restrictions.
                 is_string__all_indirect_refs_are_strings())),
         self._helper.files_matcher_sym_assertion(),
     ]
Ejemplo n.º 3
0
 def test_symbol_usages_of_object_returned_by_parser_SHOULD_be_reported(
         self):
     # ARRANGE #
     symbol_reference = NameAndValue(
         'symbol_name',
         reference_restrictions.is_any_type_w_str_rendering())
     expected_symbol_references = [
         SymbolReference(symbol_reference.name, symbol_reference.value)
     ]
     actor = sut.ActorFromParts(
         ParserWithConstantResult(
             SymbolUserWithConstantSymbolReferences(
                 expected_symbol_references)),
         sut.UnconditionallySuccessfulValidatorConstructor(),
         _ExecutorConstructorForConstant(
             UnconditionallySuccessfulExecutor()),
     )
     # ACT & ASSERT #
     check_execution(
         self, actor, [], arrangement_w_tcds(),
         Expectation(symbol_usages=asrt.matches_sequence([
             asrt_sym_ref.matches_reference_2(
                 symbol_reference.name,
                 data_restrictions_assertions.equals__w_str_rendering(
                     symbol_reference.value))
         ])))
Ejemplo n.º 4
0
def is_reference_to__path_or_string(symbol_name: str,
                                    accepted_relativities: PathRelativityVariants,
                                    ) -> Assertion[SymbolReference]:
    return asrt_sym_ref.matches_reference_2(
        symbol_name,
        asrt_data_ref_restriction.equals__w_str_rendering(
            path_or_string_reference_restrictions(accepted_relativities))
    )
Ejemplo n.º 5
0
def equals_data_type_symbol_reference(expected: SymbolReference) -> Assertion[SymbolReference]:
    restrictions = expected.restrictions
    if not isinstance(restrictions, WithStrRenderingTypeRestrictions):
        raise ValueError('Restrictions must be {}. Found {}'.format(
            WithStrRenderingTypeRestrictions,
            restrictions,
        ))
    return asrt_sym_ref.matches_reference_2(expected.name,
                                            asrt_w_str_rend_rest.equals__w_str_rendering(restrictions))
Ejemplo n.º 6
0
def equals_list_sdv_element(expected: list_sdv.ElementSdv,
                            symbols: SymbolTable = None) -> Assertion[list_sdv.ElementSdv]:
    if symbols is None:
        symbols = symbol_table_with_values_matching_references(list(expected.references))
    expected_resolved_value_list = expected.resolve(symbols)
    assertion_on_resolved_value = asrt.matches_sequence(
        [equals_string_ddv(sv) for sv in expected_resolved_value_list])
    component_assertions = [
        asrt.sub_component('references',
                           lambda x: list(x.references),
                           equals_symbol_references__w_str_rendering(list(expected.references))),
        asrt.sub_component('resolved value',
                           lambda x: x.resolve(symbols),
                           assertion_on_resolved_value),

    ]
    symbol_reference_assertion = asrt.is_none
    reference = expected.symbol_reference_if_is_symbol_reference
    if reference is not None:
        reference_restrictions = reference.restrictions
        if not isinstance(reference_restrictions, WithStrRenderingTypeRestrictions):
            raise ValueError('A list element must reference a data type value')
        assert isinstance(reference_restrictions, WithStrRenderingTypeRestrictions)  # Type info for IDE

        symbol_reference_assertion = equals_data_type_symbol_reference(reference)

        asrt_sym_ref.matches_reference_2(
            reference.name,
            data_restrictions_assertions.equals__w_str_rendering(
                reference_restrictions)
        )

    symbol_reference_component_assertion = asrt.sub_component('symbol_reference_if_is_symbol_reference',
                                                              lambda x: x.symbol_reference_if_is_symbol_reference,
                                                              symbol_reference_assertion)
    component_assertions.append(symbol_reference_component_assertion)
    return asrt.is_instance_with(
        list_sdv.ElementSdv,
        asrt.and_(component_assertions))
Ejemplo n.º 7
0
def is_reference_restrictions__glob_pattern_string(
) -> Assertion[ReferenceRestrictions]:
    return asrt_data_rest.equals__w_str_rendering(
        reference_restrictions.is_any_type_w_str_rendering())
Ejemplo n.º 8
0
from exactly_lib.symbol.sdv_structure import SymbolUsage, SymbolReference
from exactly_lib.type_val_deps.sym_ref.w_str_rend_restrictions.reference_restrictions import \
    is_string__all_indirect_refs_are_strings
from exactly_lib_test.symbol.test_resources import symbol_usage_assertions as asrt_sym_usage
from exactly_lib_test.test_resources.value_assertions import value_assertion as asrt
from exactly_lib_test.test_resources.value_assertions.value_assertion import Assertion
from exactly_lib_test.type_val_deps.test_resources.w_str_rend import data_restrictions_assertions as asrt_rest

IS_REFERENCE__STRING__W_ALL_INDIRECT_REFS_ARE_STRINGS = (
    asrt_rest.equals__w_str_rendering(
        is_string__all_indirect_refs_are_strings()))


def is_sym_ref_to_string__w_all_indirect_refs_are_strings__usage(
        name_of_symbol: str) -> Assertion[SymbolUsage]:
    return asrt_sym_usage.matches_reference(
        asrt.equals(name_of_symbol),
        IS_REFERENCE__STRING__W_ALL_INDIRECT_REFS_ARE_STRINGS)


def is_sym_ref_to_string__w_all_indirect_refs_are_strings(
    name_of_symbol: str, ) -> Assertion[SymbolReference]:
    return asrt_sym_usage.matches_reference__ref(
        asrt.equals(name_of_symbol),
        IS_REFERENCE__STRING__W_ALL_INDIRECT_REFS_ARE_STRINGS)
Ejemplo n.º 9
0
 def reference_assertion__path(
         self, symbol_name: str) -> Assertion[SymbolReference]:
     return asrt_sym_ref.matches_reference_2(
         symbol_name,
         asrt_data_ref_restriction.equals__w_str_rendering(
             self.reference_restriction__path))
Ejemplo n.º 10
0
def matches_data_type_symbol_reference(symbol_name: str,
                                       restrictions: WithStrRenderingTypeRestrictions) -> Assertion[
    SymbolReference]:
    return asrt_sym_ref.matches_reference_2(symbol_name,
                                            asrt_w_str_rend_rest.equals__w_str_rendering(restrictions))