Пример #1
0
 def test_equals(self):
     test_cases = [
         ArbitraryValueWStrRenderingRestriction.of_any(),
         ArbitraryValueWStrRenderingRestriction(tuple(WithStrRenderingType)),
     ]
     for restriction in test_cases:
         with self.subTest(restriction.accepted):
             sut.is__w_str_rendering().apply_without_message(
                 self, restriction)
Пример #2
0
    def test_not_equals(self):
        expected_string = 'expected value'
        cases = [
            NEA(
                'differs__resolved_value',
                string_sdvs.str_constant(expected_string),
                string_sdvs.str_constant('actual value'),
            ),
            NEA(
                'differs__number_of_references',
                string_sdvs.str_constant(expected_string),
                sdv_with_references([
                    SymbolReference(
                        'symbol_name',
                        ReferenceRestrictionsOnDirectAndIndirect(
                            ArbitraryValueWStrRenderingRestriction.of_any()))
                ]),
            ),
            NEA(
                'different_number_of_references',
                StringSdvTestImpl(expected_string, [
                    SymbolReference(
                        'expected_symbol_name',
                        ReferenceRestrictionsOnDirectAndIndirect(
                            ArbitraryValueWStrRenderingRestriction.of_any()))
                ]),
                StringSdvTestImpl(expected_string, [
                    SymbolReference(
                        'actual_symbol_name',
                        ReferenceRestrictionsOnDirectAndIndirect(
                            ArbitraryValueWStrRenderingRestriction.of_any()))
                ]),
            ),
            NEA(
                'different_number_of_fragments',
                StringSdvTestImpl(expected_string, [],
                                  (string_sdvs.str_fragment('value'), )),
                StringSdvTestImpl(expected_string, [], (())),
            ),
            NEA(
                'different_fragments',
                StringSdvTestImpl(expected_string, [],
                                  (string_sdvs.str_fragment('value 1'), )),
                StringSdvTestImpl(expected_string, [],
                                  (string_sdvs.str_fragment('value 2'), )),
            ),
        ]

        for case in cases:
            with self.subTest(case.name):
                assertion = sut.equals_string_sdv(case.expected)
                # ACT & ASSERT #
                assert_that_assertion_fails(assertion, case.actual)
Пример #3
0
 def test_equals(self):
     test_cases = [
         PathAndRelativityRestriction(PathRelativityVariants(set(), False)),
         PathAndRelativityRestriction(PathRelativityVariants({RelOptionType.REL_ACT}, True)),
         ArbitraryValueWStrRenderingRestriction.of_any(),
         ArbitraryValueWStrRenderingRestriction.of_single(WithStrRenderingType.STRING),
         ArbitraryValueWStrRenderingRestriction.of_single(WithStrRenderingType.PATH),
         ArbitraryValueWStrRenderingRestriction([WithStrRenderingType.PATH, WithStrRenderingType.LIST]),
     ]
     for restriction in test_cases:
         with self.subTest():
             sut.equals(restriction).apply_without_message(self, restriction)
Пример #4
0
 def test_equals(self):
     test_cases = [
         (
             (),
             (),
         ),
         (
             (string_sdvs.str_fragment('abc'), ),
             (string_sdvs.str_fragment('abc'), ),
         ),
         (
             (string_sdvs.symbol_fragment(
                 SymbolReference(
                     'symbol_name',
                     ReferenceRestrictionsOnDirectAndIndirect(
                         ArbitraryValueWStrRenderingRestriction.of_any()))),
              ),
             (string_sdvs.symbol_fragment(
                 SymbolReference(
                     'symbol_name',
                     ReferenceRestrictionsOnDirectAndIndirect(
                         ArbitraryValueWStrRenderingRestriction.of_any()))),
              ),
         ),
         (
             (
                 string_sdvs.str_fragment('abc'),
                 string_sdvs.symbol_fragment(
                     SymbolReference(
                         'symbol_name',
                         ReferenceRestrictionsOnDirectAndIndirect(
                             ArbitraryValueWStrRenderingRestriction.of_any(
                             )))),
             ),
             (
                 string_sdvs.str_fragment('abc'),
                 string_sdvs.symbol_fragment(
                     SymbolReference(
                         'symbol_name',
                         ReferenceRestrictionsOnDirectAndIndirect(
                             ArbitraryValueWStrRenderingRestriction.of_any(
                             )))),
             ),
         ),
     ]
     for fragments1, fragments2 in test_cases:
         with self.subTest(msg=str(fragments1) + ' ' + str(fragments2)):
             sut.equals_string_fragments(fragments1).apply_without_message(
                 self, fragments2)
             sut.equals_string_fragments(fragments2).apply_without_message(
                 self, fragments1)
Пример #5
0
 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)
Пример #6
0
    def test_not_equals(self):
        # ARRANGE #
        value = 'a_value'
        cases = [
            NEA(
                'different constants',
                string_sdvs.str_fragment('some value'),
                string_sdvs.str_fragment('some other value'),
            ),
            NEA(
                'constant and reference',
                string_sdvs.str_fragment(value),
                string_sdvs.symbol_fragment(
                    SymbolReference(
                        value,
                        ReferenceRestrictionsOnDirectAndIndirect(
                            ArbitraryValueWStrRenderingRestriction.of_any()))),
            ),
            NEA(
                'references with different names',
                string_sdvs.symbol_fragment(
                    SymbolReference(
                        'a name',
                        ReferenceRestrictionsOnDirectAndIndirect(
                            ArbitraryValueWStrRenderingRestriction.of_any()))),
                string_sdvs.symbol_fragment(
                    SymbolReference(
                        'a different name',
                        ReferenceRestrictionsOnDirectAndIndirect(
                            ArbitraryValueWStrRenderingRestriction.of_any()))),
            ),
            # NEA(
            #     'references with different restrictions',
            #     string_sdvs.symbol_fragment(
            #         SymbolReference(
            #             'common name',
            #             ReferenceRestrictionsOnDirectAndIndirect(AnyDataTypeRestriction()))
            #     ),
            #     string_sdvs.symbol_fragment(
            #         SymbolReference(
            #             'common name',
            #             TypeCategoryRestriction(TypeCategory.LOGIC))
            #     ),
            # ),
        ]

        # ACT & ASSERT #

        for case in cases:
            with self.subTest(case.name, order='expected == actual'):
Пример #7
0
 def test_equals(self):
     test_cases = [
         (
             'Plain string',
             string_sdvs.str_constant('string value'),
             empty_symbol_table(),
         ),
         (
             'String with reference',
             sdv_with_references([
                 SymbolReference(
                     'symbol_name',
                     ReferenceRestrictionsOnDirectAndIndirect(
                         ArbitraryValueWStrRenderingRestriction.of_any()))
             ]),
             empty_symbol_table(),
         ),
     ]
     for test_case_name, string_value, symbol_table in test_cases:
         assert isinstance(string_value, StringSdv), 'Type info for IDE'
         with self.subTest(msg='{}::with checked references::{}'.format(
                 sut.equals_string_sdv.__name__, test_case_name)):
             assertion = sut.equals_string_sdv(string_value)
             assertion.apply_with_message(self, string_value,
                                          test_case_name)
Пример #8
0
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)
Пример #9
0
 def test_not_equals__same_length__different_types(self):
     # ARRANGE #
     expected = (string_sdvs.str_fragment('value'), )
     actual = (string_sdvs.symbol_fragment(
         SymbolReference(
             'value',
             ReferenceRestrictionsOnDirectAndIndirect(
                 ArbitraryValueWStrRenderingRestriction.of_any()))), )
     assertion = sut.equals_string_fragments(expected)
     # ACT & ASSERT #
     assert_that_assertion_fails(assertion, actual)
Пример #10
0
 def test_equals(self):
     a_string = 'a string'
     an_identical_string = 'a string'
     test_cases = [
         NEA(
             'constant strings',
             string_sdvs.str_fragment(a_string),
             string_sdvs.str_fragment(an_identical_string),
         ),
         NEA(
             'symbol references',
             string_sdvs.symbol_fragment(
                 SymbolReference(
                     a_string,
                     ReferenceRestrictionsOnDirectAndIndirect(
                         ArbitraryValueWStrRenderingRestriction.of_any()))),
             string_sdvs.symbol_fragment(
                 SymbolReference(
                     an_identical_string,
                     ReferenceRestrictionsOnDirectAndIndirect(
                         ArbitraryValueWStrRenderingRestriction.of_any()))),
         ),
         NEA(
             'symbol references with different restrictions (surprisingly)',
             string_sdvs.symbol_fragment(
                 SymbolReference(
                     a_string,
                     ReferenceRestrictionsOnDirectAndIndirect(
                         ArbitraryValueWStrRenderingRestriction.of_any()))),
             string_sdvs.symbol_fragment(
                 SymbolReference(an_identical_string,
                                 ValueTypeRestriction([ValueType.PROGRAM
                                                       ]))),
         ),
     ]
     for case in test_cases:
         with self.subTest(case.name):
             sut.equals_string_fragment_sdv_with_exact_type(
                 case.expected).apply_without_message(self, case.actual)
             sut.equals_string_fragment_sdv_with_exact_type(
                 case.actual).apply_without_message(self, case.expected)
Пример #11
0
 def test_differs__symbol_references(self):
     # ARRANGE #
     path = PathDdvTestImpl(RelOptionType.REL_ACT, path_ddvs.constant_path_part('file-name'))
     actual = PathSdvTestImplWithConstantPathAndSymbolReferences(
         path,
         [SymbolReference('symbol_name',
                          ReferenceRestrictionsOnDirectAndIndirect(
                              ArbitraryValueWStrRenderingRestriction.of_any()))])
     assertion = sut.matches_path_sdv(path,
                                      asrt.matches_sequence([]),
                                      empty_symbol_table())
     # ACT & ASSERT #
     assert_that_assertion_fails(assertion, actual)
Пример #12
0
 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)
Пример #13
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')
Пример #14
0
def is_any_type_w_str_rendering() -> WithStrRenderingTypeRestrictions:
    """
    :return: A restriction that is satisfied iff the symbol is a data value
    """
    return ReferenceRestrictionsOnDirectAndIndirect(
        ArbitraryValueWStrRenderingRestriction.of_any(), None)
Пример #15
0
 def test_not_equals__different__types__one_is_path_relativity_variants(self):
     expected = PathAndRelativityRestriction(PathRelativityVariants({RelOptionType.REL_HDS_CASE}, False))
     actual = ArbitraryValueWStrRenderingRestriction.of_any()
     assert_that_assertion_fails(sut.equals(expected), actual)
Пример #16
0
def reference_restrictions__unconditionally_satisfied(
) -> ReferenceRestrictions:
    return ReferenceRestrictionsOnDirectAndIndirect(
        ArbitraryValueWStrRenderingRestriction.of_any())
Пример #17
0
def is_string() -> ValueRestriction:
    return ArbitraryValueWStrRenderingRestriction.of_single(
        WithStrRenderingType.STRING)
Пример #18
0
def reference_to__on_direct_and_indirect(
        name: str,
        value_restriction: ValueRestriction = ArbitraryValueWStrRenderingRestriction.of_any(),
) -> SymbolReference:
    return SymbolReference(name, ReferenceRestrictionsOnDirectAndIndirect(value_restriction))
Пример #19
0
_NOT_EXISTS_PRE_SDS_RELATIVITY = RelOptionType.REL_ACT

_PATH_SUFFIX_VARIANTS = [
    path_ddvs.constant_path_part('file-name'),
    path_ddvs.empty_path_part(),
]

_RELATIVITY_VARIANTS = [
    _EXISTS_PRE_SDS_RELATIVITY,
    _NOT_EXISTS_PRE_SDS_RELATIVITY,
]

_SYMBOL_REFERENCES = [
    [],
    [SymbolReference('symbol_name',
                     ReferenceRestrictionsOnDirectAndIndirect(ArbitraryValueWStrRenderingRestriction.of_any()))]
]


class TestEqualsCommonToBothAssertionMethods(unittest.TestCase):
    def runTest(self):
        symbols = empty_symbol_table()
        for relativity in _RELATIVITY_VARIANTS:
            for path_suffix in _PATH_SUFFIX_VARIANTS:
                for symbol_references in _SYMBOL_REFERENCES:
                    path = PathDdvTestImpl(relativity, path_suffix)
                    path_sdv = PathSdvTestImplWithConstantPathAndSymbolReferences(path,
                                                                                  symbol_references)
                    test_case_descr = 'relativity:{}, path-suffix: {}'.format(relativity, type(path_suffix))
                    with self.subTest(msg=sut.equals_path_sdv.__name__ + ' :: ' + test_case_descr):
                        assertion = sut.equals_path_sdv(path_sdv)
Пример #20
0
def no_restrictions() -> ReferenceRestrictions:
    return ReferenceRestrictionsOnDirectAndIndirect(
        direct=ArbitraryValueWStrRenderingRestriction.of_any(), indirect=None)
Пример #21
0
 def test_not_equals__different__restriction_types(self):
     actual = ArbitraryValueWStrRenderingRestriction.of_any()
     assert_that_assertion_fails(
         sut.is__path_w_relativity(),
         actual,
     )