示例#1
0
    def matches_regex_sdv(self,
                          symbols: SymbolTable,
                          tcds: TestCaseDs) -> Assertion[RegexSdv]:
        def on_primitive_value(tcds: TestCaseDs) -> Assertion[Pattern]:
            return self.pattern

        return matches_regex_sdv(primitive_value=on_primitive_value,
                                 references=self.references,
                                 validation=self.validation,
                                 tcds=tcds,
                                 symbols=symbols)
示例#2
0
    def test_SHOULD_match_WHEN_references_match(self):
        # ARRANGE #
        actual_reference = data_references.reference_to__on_direct_and_indirect(
            'referenced element')
        actual_references = [actual_reference]
        actual_sdv = arbitrary_sdv_with_references(actual_references)

        assertion_to_check = sut.matches_regex_sdv(
            references=asrt.matches_sequence([asrt.is_(actual_reference)]), )
        # ACT & ASSERT #
        assertion_to_check.apply_without_message(self, actual_sdv)
示例#3
0
    def test_SHOULD_not_match_WHEN_resolving_dependencies_do_not_match(self):
        # ARRANGE #
        actual_dependencies = {DirectoryStructurePartition.NON_HDS}

        sdv_of_actual = RegexSdvConstantTestImpl(
            ARBITRARY_PATTERN, resolving_dependencies=actual_dependencies)

        assertion_to_check = sut.matches_regex_sdv(
            dir_dependencies=DirDependencies.HDS)

        # ACT & ASSERT #
        assert_that_assertion_fails(assertion_to_check, sdv_of_actual)
示例#4
0
    def test_SHOULD_match_WHEN_resolving_dependencies_do_match(self):
        # ARRANGE #
        expected_dependencies = {DirectoryStructurePartition.HDS}
        actual_dependencies = expected_dependencies

        sdv_of_actual = RegexSdvConstantTestImpl(
            ARBITRARY_PATTERN, resolving_dependencies=actual_dependencies)

        assertion_to_check = sut.matches_regex_sdv(
            dir_dependencies=DirDependencies.HDS)

        # ACT & ASSERT #
        assertion_to_check.apply_without_message(self, sdv_of_actual)
示例#5
0
    def test_SHOULD_not_match_WHEN_resolved_primitive_value_is_none(self):
        # ARRANGE #
        cases = [
            NameAndValue('without symbol table', None),
            NameAndValue(
                'with symbol table',
                StringSymbolContext.of_sdv('the symbol name',
                                           CONSTANT_STRING_SDV).symbol_table),
        ]
        sdv_of_actual = RegexSdvConstantTestImpl(None)

        for case in cases:
            with self.subTest(name=case.name):
                assertion_to_check = sut.matches_regex_sdv(symbols=case.value)
                # ACT & ASSERT #
                assert_that_assertion_fails(assertion_to_check, sdv_of_actual)
示例#6
0
 def test_SHOULD_match_WHEN_whole_structure_is_valid(self):
     # ARRANGE #
     cases = [
         NameAndValue('without symbol table', None),
         NameAndValue(
             'with symbol table',
             StringSymbolContext(
                 'the symbol name',
                 string.ARBITRARY_SYMBOL_VALUE_CONTEXT).symbol_table,
         ),
     ]
     sdv = ARBITRARY_SDV
     for case in cases:
         with self.subTest(name=case.name):
             assertion_to_check = sut.matches_regex_sdv(symbols=case.value)
             # ACT & ASSERT #
             assertion_to_check.apply_without_message(self, sdv)
示例#7
0
    def test_validator_SHOULD_not_be_none(self):
        # ARRANGE #
        cases = [
            NameAndValue('without symbol table', None),
            NameAndValue(
                'with symbol table',
                StringSymbolContext.of_sdv('the symbol name',
                                           CONSTANT_STRING_SDV).symbol_table,
            ),
        ]
        sdv_of_actual = RegexSdvConstantTestImpl(ARBITRARY_PATTERN,
                                                 value_validator=None)

        for case in cases:
            with self.subTest(name=case.name):
                assertion_to_check = sut.matches_regex_sdv(symbols=case.value)
                # ACT & ASSERT #
                assert_that_assertion_fails(assertion_to_check, sdv_of_actual)
示例#8
0
    def test_SHOULD_not_match_WHEN_actual_is_file_matcher(self):
        # ARRANGE #
        cases = [
            NameAndValue('without symbol table', None),
            NameAndValue(
                'with symbol table',
                StringSymbolContext(
                    'the symbol name',
                    string.ARBITRARY_SYMBOL_VALUE_CONTEXT).symbol_table,
            ),
        ]
        sdv_of_actual = file_matcher_constant_sdv(FileMatcherTestImpl())

        for case in cases:
            with self.subTest(name=case.name):
                assertion_to_check = sut.matches_regex_sdv(symbols=case.value)
                # ACT & ASSERT #
                assert_that_assertion_fails(assertion_to_check, sdv_of_actual)
示例#9
0
    def test_SHOULD_match_WHEN_post_sds_validation_fails_expectedly_but_primitive_value_is_unexpected(
            self):
        # ARRANGE #

        sdv_of_actual = RegexSdvConstantTestImpl(
            ARBITRARY_PATTERN,
            value_validator=ConstantDdvValidator(
                post_sds_result=asrt_validation.
                new_single_string_text_for_test('expected failure')),
        )

        assertion_to_check = sut.matches_regex_sdv(
            dir_dependencies=DirDependencies.NONE,
            validation=ValidationAssertions.post_sds_fails(),
            primitive_value=check_of_primitive_value_fails_expectedly,
        )

        # ACT & ASSERT #
        assertion_to_check.apply_without_message(self, sdv_of_actual)
示例#10
0
    def test_SHOULD_not_match_WHEN_assertion_on_matcher_fails(self):
        # ARRANGE #
        cases = [
            NameAndValue('without symbol table', None),
            NameAndValue(
                'with symbol table',
                StringSymbolContext.of_sdv('the symbol name',
                                           CONSTANT_STRING_SDV).symbol_table,
            ),
        ]
        sdv_of_actual = ARBITRARY_SDV

        for case in cases:
            with self.subTest(name=case.name):
                assertion_to_check = sut.matches_regex_sdv(
                    primitive_value=lambda tcds: asrt.fail('unconditionally'),
                    symbols=case.value)
                # ACT & ASSERT #
                assert_that_assertion_fails(assertion_to_check, sdv_of_actual)
示例#11
0
    def _assert_resolved_pattern_has_pattern_string(self,
                                                    actual_sdv: RegexSdv,
                                                    expected_pattern_string: str,
                                                    matching_string: str,
                                                    non_matching_string: str,
                                                    symbols: SymbolTable):
        def equals_expected_pattern_string(tcds: TestCaseDs) -> Assertion[Pattern]:
            return _AssertPattern(
                pattern_string=expected_pattern_string,
                matching_strings=[matching_string],
                non_matching_string=non_matching_string,
            )

        resolved_value_has_expected_pattern_string = matches_regex_sdv(
            primitive_value=equals_expected_pattern_string,
            references=asrt.anything_goes(),
            symbols=symbols,
        )

        resolved_value_has_expected_pattern_string.apply_without_message(self, actual_sdv)
示例#12
0
    def test_SHOULD_not_match_WHEN_references_do_not_match(self):
        # ARRANGE #
        actual_reference = data_references.reference_to__on_direct_and_indirect(
            'referenced element')
        actual_references = [actual_reference]
        actual_sdv = arbitrary_sdv_with_references(actual_references)

        cases = [
            NameAndValue('assert no references', asrt.is_empty_sequence),
            NameAndValue(
                'assert single invalid reference',
                asrt.matches_sequence([asrt.not_(asrt.is_(actual_reference))
                                       ])),
        ]

        for case in cases:
            with self.subTest(name=case.name):
                assertion_to_check = sut.matches_regex_sdv(
                    references=case.value)
                # ACT & ASSERT #
                assert_that_assertion_fails(assertion_to_check, actual_sdv)