def test_value_ref__differs__symbol_name(self): # ARRANGE # path = arbitrary_path() expected = sdv_from_constants(path, [SymbolReference('expected_symbol_name', ReferenceRestrictionsOnDirectAndIndirect( ArbitraryValueWStrRenderingRestriction.of_any()))]) actual = sdv_from_constants(path, [SymbolReference('actual_symbol_name', ReferenceRestrictionsOnDirectAndIndirect( ArbitraryValueWStrRenderingRestriction.of_any()))]) assertion = sut.equals_path_sdv(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def __init__(self, name_of_referenced_sdv: str): self._name_of_referenced_sdv = name_of_referenced_sdv self._references = [ SymbolReference( name_of_referenced_sdv, ValueTypeRestriction.of_single(ValueType.STRING_TRANSFORMER)) ]
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)))
def _symbol_reference_of_path_with_accepted( value_name: str, accepted: RelOptionType) -> SymbolReference: return SymbolReference( value_name, ReferenceRestrictionsOnDirectAndIndirect( PathAndRelativityRestriction( _path_relativity_variants_with(accepted))))
def test_value_ref__invalid_type_of_value_restriction(self): # ARRANGE # path = arbitrary_path() expected = sdv_from_constants(path, [SymbolReference('reffed-name', ReferenceRestrictionsOnDirectAndIndirect( _relativity_restriction( {RelOptionType.REL_ACT}, False)))]) actual = sdv_from_constants(path, [SymbolReference('reffed-name', ReferenceRestrictionsOnDirectAndIndirect( ArbitraryValueWStrRenderingRestriction.of_any()))]) assertion = sut.equals_path_sdv(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def __init__(self, symbol_name: str, accumulated_elements: AccumulatedComponents): self._symbol_name = symbol_name self._accumulated_components = accumulated_elements self._symbol_reference = SymbolReference( symbol_name, ValueTypeRestriction.of_single(ValueType.PROGRAM))
def fragment_sdv_from_fragment(fragment: symbol_syntax.Fragment, reference_restrictions: ReferenceRestrictions) -> StringFragmentSdv: if fragment.is_constant: return string_sdvs.str_fragment(fragment.value) else: sr = SymbolReference(fragment.value, reference_restrictions) return string_sdvs.symbol_fragment(sr)
def single_symbol_reference( symbol_name: str, reference_restrictions: ReferenceRestrictions = None) -> StringSdv: if reference_restrictions is None: reference_restrictions = no_restrictions() fragments = (string_sdvs.symbol_fragment( SymbolReference(symbol_name, reference_restrictions)), ) return sut.StringSdv(fragments)
def test_fail__different_name(self): # ARRANGE # actual = SymbolReference('actual value name', r.ReferenceRestrictionsOnDirectAndIndirect( vr.ArbitraryValueWStrRenderingRestriction.of_any())) assertion = sut.matches_symbol_reference_with_restriction_on_direct_target('expected value name', asrt.is_instance( vr.ArbitraryValueWStrRenderingRestriction)) assert_that_assertion_fails(assertion, actual)
def reduce_left(self, x: SymbolName) -> PathSdv: return path_sdvs.reference( SymbolReference( x, path_or_string_reference_restrictions( self._rel_opt_conf.options.accepted_relativity_variants)), path_part_sdvs.empty(), self._rel_opt_conf.options.default_option, )
def test_WHEN_referenced_symbol_is_in_symbol_table_and_satisfies_value_restriction_THEN_no_error(self): # ARRANGE # symbol_table = StringSymbolContext.of_constant('val_name', 'value string').symbol_table symbol_reference = SymbolReference('val_name', ReferenceRestrictionsOnDirectAndIndirect( RestrictionThatIsAlwaysSatisfied())) # ACT # actual = sut.validate_symbol_usage(symbol_reference, symbol_table) self.assertIsNone(actual, 'result should indicate success')
def test_WHEN_referenced_symbol_not_in_symbol_table_THEN_validation_error(self): # ARRANGE # symbol_table = empty_symbol_table() symbol_usage = SymbolReference('undefined', reference_restrictions__unconditionally_satisfied()) # ACT # actual = sut.validate_symbol_usage(symbol_usage, symbol_table) self.assertIsNotNone(actual, 'result should indicate error') self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR, actual.status)
def fragment_sdv_from_fragment(fragment: Fragment) -> StringFragmentSdv: if fragment.is_constant: return string_sdvs.str_fragment(fragment.value) else: sr = SymbolReference( fragment.value, ReferenceRestrictionsOnDirectAndIndirect( direct=ArbitraryValueWStrRenderingRestriction.of_any(), indirect=None)) return string_sdvs.symbol_fragment(sr)
def test_fail__failing_assertion_on_value_restriction(self): # ARRANGE # common_name = 'actual value name' actual = SymbolReference(common_name, r.ReferenceRestrictionsOnDirectAndIndirect( vr.ArbitraryValueWStrRenderingRestriction.of_any())) assertion = sut.matches_symbol_reference_with_restriction_on_direct_target( common_name, asrt.is_instance(vr.PathAndRelativityRestriction)) assert_that_assertion_fails(assertion, actual)
def test_value_ref__differs__restriction_relativity_variants(self): # ARRANGE # def restriction_with_relativity(relativity: RelOptionType) -> ValueRestriction: return _relativity_restriction({relativity}, False) path = arbitrary_path() expected = sdv_from_constants( path, [SymbolReference('reffed-name', ReferenceRestrictionsOnDirectAndIndirect( restriction_with_relativity(RelOptionType.REL_ACT)))]) actual = sdv_from_constants( path, [SymbolReference('reffed-name', ReferenceRestrictionsOnDirectAndIndirect( restriction_with_relativity(RelOptionType.REL_HDS_CASE)))]) assertion = sut.equals_path_sdv(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def _extract_parts_that_can_act_as_path_and_suffix( self, string_fragments: list, ) -> Tuple[SymbolReference, PathPartSdv]: path_or_string_symbol = SymbolReference( string_fragments[0].value, path_or_string_reference_restrictions( self.conf.rel_opt_conf.options.accepted_relativity_variants), ) path_part_sdv = _path_suffix_sdv_from_fragments(string_fragments[1:]) return path_or_string_symbol, path_part_sdv
def test_pass(self): # ARRANGE # symbol_name = 'value name' symbol_reference = SymbolReference(symbol_name, r.ReferenceRestrictionsOnDirectAndIndirect( vr.ArbitraryValueWStrRenderingRestriction.of_any())) assertion = sut.matches_symbol_reference_with_restriction_on_direct_target(symbol_name, asrt.is_instance( vr.ArbitraryValueWStrRenderingRestriction)) # ACT & ASSERT # assertion.apply_without_message(self, symbol_reference)
def test_WHEN_referenced_symbol_is_in_symbol_table_but_does_not_satisfy_value_restriction_THEN_validation_error( self): # ARRANGE # symbol_table = StringSymbolContext.of_constant('val_name', 'symbol string').symbol_table symbol_usage = SymbolReference('val_name', reference_restrictions__unconditionally_unsatisfied()) # ACT # actual = sut.validate_symbol_usage(symbol_usage, symbol_table) self.assertIsNotNone(actual, 'result should indicate error') self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR, actual.status)