예제 #1
0
def check_exe_file(put: unittest.TestCase, expectation: ExpectationOnExeFile,
                   actual: PathSdv):
    path_sdv_assertion = matches_path_sdv(
        expectation.path_ddv,
        expected_symbol_references=equals_symbol_references__w_str_rendering(
            expectation.expected_symbol_references),
        symbol_table=expectation.symbol_for_value_checks)
    path_sdv_assertion.apply_with_message(put, actual, 'path sdv')
    path_symbols = equals_symbol_references__w_str_rendering(
        expectation.expected_symbol_references)
    path_symbols.apply_with_message(put, actual.references,
                                    'path-sdv/references')
예제 #2
0
 def _apply(self,
            put: unittest.TestCase,
            value: StringSdv,
            message_builder: asrt.MessageBuilder):
     put.assertIsInstance(value, StringSdv)
     equals_symbol_references__w_str_rendering(self.symbol_references).apply_with_message(put,
                                                                                          value.references,
                                                                                          'symbol references')
     environment = PathResolvingEnvironmentPreOrPostSds(fake_tcds(),
                                                        self.symbols)
     actual_resolved_prim_val = value.resolve_value_of_any_dependency(environment)
     self.expected_resolved_primitive_value.apply_with_message(put, actual_resolved_prim_val,
                                                               'resolved primitive value')
예제 #3
0
def equals_path_sdv(expected: PathSdv) -> Assertion[SymbolDependentValue]:
    symbols = symbol_table_with_values_matching_references(expected.references)
    expected_path = expected.resolve(symbols)
    return type_sdv_assertions.matches_sdv_of_path(
        equals_symbol_references__w_str_rendering(expected.references),
        equals_path(expected_path),
        symbols=symbols)
예제 #4
0
    def test_that_fails_due_to_missing_symbol_reference(self):
        symbol_usages_of_matcher = []
        symbol_usages_of_expectation = [
            data_references.reference_to__on_direct_and_indirect('symbol_name')]

        self._check_raises_test_error__single_and_multi(
            _constant_line_matcher_type_parser_of_matcher_sdv(
                sdv_ddv.sdv_from_primitive_value(references=symbol_usages_of_matcher)
            ),
            Expectation(
                ParseExpectation(
                    symbol_references=sym_asrt.equals_symbol_references__w_str_rendering(
                        symbol_usages_of_expectation)
                ),
            )
        )
예제 #5
0
 def test_difference_in_relativity_root(self):
     symbols = empty_symbol_table()
     for relativity in _RELATIVITY_VARIANTS:
         for path_suffix in _PATH_SUFFIX_VARIANTS:
             test_case_descr = 'relativity:{}, path-suffix: {}'.format(relativity, type(path_suffix))
             path = PathDdvTestImpl(relativity, path_suffix)
             path_sdv = path_sdvs.constant(path)
             with self.subTest(msg=sut.equals_path_sdv.__name__ + ' :: ' + test_case_descr):
                 assertion = sut.equals_path_sdv(path_sdv)
                 assertion.apply_without_message(self, path_sdv)
             with self.subTest(msg=sut.matches_path_sdv.__name__ + ' :: ' + test_case_descr):
                 assertion = sut.matches_path_sdv(path,
                                                  equals_symbol_references__w_str_rendering(
                                                      path_sdv.references),
                                                  symbols)
                 assertion.apply_without_message(self, path_sdv)
예제 #6
0
 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)
                     assertion.apply_without_message(self, path_sdv)
                 with self.subTest(msg=sut.matches_path_sdv.__name__ + ' :: ' + test_case_descr):
                     assertion = sut.matches_path_sdv(path,
                                                      equals_symbol_references__w_str_rendering(
                                                          path_sdv.references),
                                                      symbols)
                     assertion.apply_without_message(self, path_sdv)
예제 #7
0
def equals_list_sdv(expected: ListSdv,
                    symbols: Optional[SymbolTable] = None) -> Assertion[SymbolDependentValue]:
    if symbols is None:
        symbols = symbol_table_with_values_matching_references(expected.references)

    expected_resolved_value = expected.resolve(symbols)

    def get_element_sdvs(x: ListSdv) -> Sequence[list_sdv.ElementSdv]:
        return x.elements

    return type_sdv_assertions.matches_sdv_of_list(
        equals_symbol_references__w_str_rendering(expected.references),
        equals_list_ddv(expected_resolved_value),
        asrt.sub_component('element SDVs',
                           get_element_sdvs,
                           equals_list_sdv_elements(
                               list(expected.elements))),

        symbols)
예제 #8
0
def equals_string_sdv(expected: StringSdv,
                      symbols: SymbolTable = None) -> Assertion[SymbolDependentValue]:
    if symbols is None:
        symbols = symbol_table_with_values_matching_references(expected.references)

    expected_resolved_value = expected.resolve(symbols)

    def get_fragment_sdvs(x: StringSdv) -> Sequence[StringFragmentSdv]:
        return x.fragments

    return type_sdv_assertions.matches_sdv_of_string(
        equals_symbol_references__w_str_rendering(expected.references),
        equals_string_ddv(expected_resolved_value),
        asrt.sub_component('fragment resolvers',
                           get_fragment_sdvs,
                           equals_string_fragments(
                               expected.fragments)),

        symbols)
예제 #9
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))
예제 #10
0
    def test_symbols_from_contents_assertion_SHOULD_be_reported(self):
        # ARRANGE #

        operand_sym_ref = SymbolReference('operand_symbol_name',
                                          is_string__all_indirect_refs_are_strings())

        condition_str = '{operator} {symbol_reference}'.format(
            operator=comparators.EQ.name,
            symbol_reference=symbol_reference_syntax_for_name(operand_sym_ref.name)
        )
        arguments_constructor = args.complete_arguments_constructor(
            FileQuantificationAssertionVariant(
                Quantifier.ALL,
                file_contents_arg2(sm_arg.NumLines(condition_str))))

        argument = arguments_constructor.apply(
            expectation_type_config__non_is_success(ExpectationType.NEGATIVE)
        )

        source = remaining_source(argument)

        # ACT #

        matcher_sdv = sut.parsers().full.parse(source)

        assert isinstance(matcher_sdv, MatcherSdv)

        actual_symbol_references = matcher_sdv.references

        # ASSERT #

        expected_symbol_references = [
            operand_sym_ref,
        ]
        assertion = equals_symbol_references__w_str_rendering(expected_symbol_references)

        assertion.apply_without_message(self, actual_symbol_references)