Пример #1
0
 def test_references(self):
     reference_1 = TypeWithStrRenderingSymbolReference('symbol_1_name', is_any_type_w_str_rendering())
     reference_2 = TypeWithStrRenderingSymbolReference('symbol_2_name', OrReferenceRestrictions([]))
     cases = [
         (
             'no elements',
             sut.ListSdv([]),
             asrt.is_empty_sequence,
         ),
         (
             'single string constant element',
             sut.ListSdv([list_sdvs.str_element('string value')]),
             asrt.is_empty_sequence,
         ),
         (
             'multiple elements with multiple references',
             sut.ListSdv([
                 list_sdvs.symbol_element(reference_1.reference),
                 list_sdvs.str_element('constant value'),
                 list_sdvs.symbol_element(reference_2.reference),
             ]),
             asrt.matches_sequence([
                 reference_1.reference_assertion,
                 reference_2.reference_assertion,
             ]),
         ),
     ]
     for test_name, list_sdv, expected_references_assertion in cases:
         with self.subTest(test_name=test_name):
             actual = list_sdv.references
             expected_references_assertion.apply_without_message(self, actual)
Пример #2
0
 def test_references(self):
     string_constant_1 = 'string constant 1'
     reference_1 = TypeWithStrRenderingSymbolReference(
         'symbol_1_name', is_any_type_w_str_rendering())
     reference_2 = TypeWithStrRenderingSymbolReference(
         'symbol_2_name', OrReferenceRestrictions([]))
     cases = [
         (
             'no fragments',
             sut.StringSdv(()),
             asrt.is_empty_sequence,
         ),
         (
             'single string constant fragment',
             sut.StringSdv((impl.ConstantStringFragmentSdv(' value'), )),
             asrt.is_empty_sequence,
         ),
         (
             'multiple fragments of different types',
             sut.StringSdv((
                 impl.SymbolStringFragmentSdv(reference_1.reference),
                 impl.ConstantStringFragmentSdv(string_constant_1),
                 impl.SymbolStringFragmentSdv(reference_2.reference),
             )),
             asrt.matches_sequence([
                 reference_1.reference_assertion,
                 reference_2.reference_assertion,
             ]),
         ),
     ]
     for test_name, string_sdv, expected_references_assertion in cases:
         with self.subTest(test_name=test_name):
             actual = string_sdv.references
             expected_references_assertion.apply_without_message(
                 self, actual)
Пример #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))
         ])))
Пример #4
0
def string_sdv_from_fragments(fragments: Sequence[symbol_syntax.Fragment],
                              reference_restrictions: Optional[ReferenceRestrictions] = None,
                              ) -> StringSdv:
    if reference_restrictions is None:
        reference_restrictions = _reference_restrictions.is_any_type_w_str_rendering()
    return StringSdv(tuple([fragment_sdv_from_fragment(f, reference_restrictions)
                            for f in fragments]))
Пример #5
0
def string_sdv_of_single_symbol_reference(
        symbol_name: str,
        restrictions: ReferenceRestrictions = reference_restrictions.is_any_type_w_str_rendering(),
) -> StringSdv:
    symbol_reference = SymbolReference(symbol_name,
                                       restrictions)
    fragments = [
        string_sdvs.symbol_fragment(symbol_reference)
    ]
    return StringSdv(tuple(fragments))
Пример #6
0
 def test_should_have_exactly_one_references(self):
     # ARRANGE #
     symbol_reference = TypeWithStrRenderingSymbolReference(
         'the_symbol_name', is_any_type_w_str_rendering())
     fragment = impl.SymbolStringFragmentSdv(symbol_reference.reference)
     # ACT #
     actual = list(fragment.references)
     # ASSERT #
     assertion = asrt.matches_singleton_sequence(
         symbol_reference.reference_assertion)
     assertion.apply_without_message(self, actual)
Пример #7
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')
Пример #8
0
 def test_that_fails_due_to_missing_symbol_reference(self):
     with self.assertRaises(utils.TestError):
         symbol_usages_of_instruction = []
         self._check(
             utils.ParserThatGives(
                 cleanup_phase_instruction_that(symbol_usages=do_return(
                     symbol_usages_of_instruction))),
             utils.single_line_source(),
             sut.Arrangement(),
             sut.Expectation(symbol_usages=asrt.matches_singleton_sequence(
                 matches_data_type_symbol_reference(
                     'symbol_name',
                     reference_restrictions.is_any_type_w_str_rendering()))
                             ),
         )
Пример #9
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()
                 )
             )),
     )
Пример #10
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')
Пример #11
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())
Пример #12
0
def _symbol_reference(symbol_name: str) -> SymbolReference:
    return SymbolReference(
        symbol_name,
        reference_restrictions.is_any_type_w_str_rendering(),
    )
Пример #13
0
from exactly_lib.definitions.entity import syntax_elements
from exactly_lib.impls.types.string_ import parse_string
from exactly_lib.section_document.element_parsers.token_stream_parser import TokenParser, from_parse_source, \
    ParserFromTokens
from exactly_lib.section_document.parse_source import ParseSource
from exactly_lib.symbol.sdv_structure import SymbolReference, SymbolName
from exactly_lib.type_val_deps.sym_ref.w_str_rend_restrictions import reference_restrictions
from exactly_lib.type_val_deps.types.list_ import list_sdvs as lrs
from exactly_lib.type_val_deps.types.list_.list_sdv import ListSdv
from exactly_lib.type_val_deps.types.string_.string_sdv import StringSdv
from exactly_lib.util import either
from . import generic_parser

_STRING_ELEMENT_PARSE_CONFIGURATION = parse_string.Configuration(
    syntax_elements.STRING_SYNTAX_ELEMENT.singular_name,
    reference_restrictions.is_any_type_w_str_rendering(),
)


def parse_list(source: ParseSource) -> ListSdv:
    with from_parse_source(source) as token_parser:
        return parse_list_from_token_parser(token_parser)


def parse_list_from_token_parser(token_parser: TokenParser) -> ListSdv:
    return lrs.from_elements(_consume_elements_from_token_parser(token_parser))


def _consume_elements_from_token_parser(token_parser: TokenParser) -> List[lrs.ElementSdv]:
    return _ELEMENT_SEQUENCE_PARSER.parse(token_parser)
Пример #14
0
def is__w_str_rendering() -> Assertion[ReferenceRestrictions]:
    return equals__w_str_rendering(
        reference_restrictions.is_any_type_w_str_rendering())
Пример #15
0
 def reference__w_str_rendering(self) -> SymbolReference:
     return SymbolReference(
         self.name, reference_restrictions.is_any_type_w_str_rendering())