예제 #1
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)))
예제 #2
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')
예제 #3
0
 def test_WHEN_defined_symbol_not_in_symbol_table_but_referenced_symbols_not_in_table_THEN_validation_error(self):
     # ARRANGE #
     symbol_table = StringSymbolContext.of_constant('OTHER', 'value').symbol_table
     symbol = PathSymbolContext.of_sdv(
         'UNDEFINED',
         path_sdvs.rel_symbol(SymbolReference('REFERENCED',
                                              ReferenceRestrictionsOnDirectAndIndirect(
                                                  RestrictionThatIsAlwaysSatisfied())),
                              path_part_sdvs.from_constant_str('file-name')))
     # ACT #
     actual = sut.validate_symbol_usage(symbol.definition, symbol_table)
     self.assertIsNotNone(actual, 'return value for indicating error')
예제 #4
0
 def test_WHEN_defined_symbol_not_in_table_but_referenced_symbol_in_table_does_not_satisfy_restriction_THEN_error(
         self):
     # ARRANGE #
     symbol_table = StringSymbolContext.of_constant('REFERENCED', 'value').symbol_table
     symbol = PathSymbolContext.of_sdv(
         'UNDEFINED',
         path_sdvs.rel_symbol(SymbolReference('REFERENCED',
                                              reference_restrictions__unconditionally_unsatisfied()),
                              path_part_sdvs.from_constant_str('file-name')))
     # ACT #
     actual = sut.validate_symbol_usage(symbol.definition, symbol_table)
     # ASSERT #
     self.assertIsNotNone(actual, 'return value for indicating error')
예제 #5
0
 def _with_explicit_relativity(
         self, path_argument: Token,
         path_part_2_path_sdv: Callable[[PathPartSdv], PathSdv]) -> PathSdv:
     string_sdv = _parse_string_sdv(path_argument)
     if string_sdv.is_string_constant:
         path_argument_str = string_sdv.string_constant
         path_argument_path = pathlib.PurePosixPath(path_argument_str)
         if path_argument_path.is_absolute():
             return path_sdvs.constant(
                 path_ddvs.absolute_file_name(path_argument_str))
         path_suffix = path_part_sdvs.from_constant_str(path_argument_str)
         return path_part_2_path_sdv(path_suffix)
     else:
         path_suffix = path_part_sdvs.from_string(string_sdv)
         return path_part_2_path_sdv(path_suffix)
예제 #6
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')
예제 #7
0
 def test_WHEN_defined_symbol_not_in_symbol_table_and_referenced_symbol_is_in_table_and_satisfies_restriction_THEN_ok(
         self):
     # ARRANGE #
     referenced_symbol = StringSymbolContext.of_constant('REFERENCED', 'value')
     symbol_table = referenced_symbol.symbol_table
     symbol = PathSymbolContext.of_sdv('UNDEFINED',
                                       path_sdvs.rel_symbol(
                                           SymbolReference('REFERENCED',
                                                           ReferenceRestrictionsOnDirectAndIndirect(
                                                               RestrictionThatIsAlwaysSatisfied())),
                                           path_part_sdvs.from_constant_str('file-name')))
     # ACT #
     actual = sut.validate_symbol_usage(symbol.definition, symbol_table)
     # ASSERT #
     self.assertIsNone(actual, 'return value for indicating success')
     self.assertTrue(symbol_table.contains('UNDEFINED'),
                     'definition should have been added')
예제 #8
0
 def test_symbol_references(self):
     # ARRANGE #
     expected_restriction = PathAndRelativityRestriction(
         PathRelativityVariants(
             {RelOptionType.REL_ACT, RelOptionType.REL_HDS_CASE}, True))
     symbol_name_of_rel_path = 'symbol_name_of_rel_path'
     symbol_name_of_path_suffix = 'symbol_name_of_path_suffix'
     restrictions_on_path_suffix_symbol = ReferenceRestrictionsOnDirectAndIndirect(
         ArbitraryValueWStrRenderingRestriction.of_any())
     expected_mandatory_references = [
         asrt_sym_ref.
         matches_symbol_reference_with_restriction_on_direct_target(
             symbol_name_of_rel_path,
             asrt_val_rest.equals__path_w_relativity(expected_restriction))
     ]
     symbol_ref_of_path = SymbolReference(
         symbol_name_of_rel_path,
         ReferenceRestrictionsOnDirectAndIndirect(expected_restriction))
     path_suffix_test_cases = [
         (
             path_part_sdvs.from_constant_str('file.txt'),
             [],
         ),
         (
             path_part_sdvs.from_string(
                 string_sdv_of_single_symbol_reference(
                     symbol_name_of_path_suffix,
                     restrictions_on_path_suffix_symbol)),
             [
                 asrt_sym_usage.matches_reference_2(
                     symbol_name_of_path_suffix,
                     asrt_w_str_rend_rest.matches__on_direct_and_indirect())
             ],
         ),
     ]
     for path_suffix_sdv, additional_expected_references in path_suffix_test_cases:
         path_sdv = sut.PathSdvRelSymbol(path_suffix_sdv,
                                         symbol_ref_of_path)
         # ACT #
         actual = path_sdv.references
         # ASSERT #
         expected_references = expected_mandatory_references + additional_expected_references
         assertion = asrt.matches_sequence(expected_references)
         assertion.apply_with_message(self, actual, 'symbol references')
예제 #9
0
def rel_symbol_with_const_file_name(symbol_reference: SymbolReference,
                                    file_name: str) -> PathSdv:
    return _with_symbol.PathSdvRelSymbol(
        path_part_sdvs.from_constant_str(file_name), symbol_reference)