def __init__( self, symbol_name: str, expectation: ValidationExpectationSvh, actual: ValidationActual, ): self._expectation = expectation self._symbol_context = FileMatcherSymbolContext.of_sdv( symbol_name, _successful_matcher_with_validation(actual))
def __init__( self, expectation: ValidationAssertions, actual: ValidationActual, symbol_name: str = 'file_matcher_symbol', ): self._expectation = expectation self._symbol_context = FileMatcherSymbolContext.of_sdv( symbol_name, _successful_matcher_with_validation(actual), )
def test_fails_if_applied(put: unittest.TestCase) -> FileMatcherSymbolContext: return FileMatcherSymbolContext.of_sdv( 'test_fails_if_applied', sdv_components.matcher_sdv_from_constant_primitive( matcher_w_init_action.matcher_that_applies_assertion( put, asrt.fail('must not be applied'), lambda x: x, asrt.MessageBuilder.new_empty(), True, )))
def result_is_single_file_name_w_lazy_conjunction_w_1st_is_applied_before_2nd( file_name: str, fm1: NameAndValue[bool], fm2: NameAndValue[bool], additional_symbols: Sequence[SymbolContext] = (), additional_entries: Optional[Mapping[ PurePosixPath, Assertion[Optional[FileMatcher]]]] = None ) -> NExArr[PrimAndExeExpectation[FilesCondition, Optional[MatchingResult]], Arrangement]: expected_result_of_complex = fm1.value and fm2.value sequence_builder = ApplicationSequenceFrom1Builder() fst_matcher = sequence_builder.add_applied(fm1, 1) snd_matcher__w_respect_to_laziness = (sequence_builder.add_applied( fm2, 2) if fm1.value else sequence_builder.add_un_applied(fm2)) symbols = [] symbols += additional_symbols symbols += [ FileMatcherSymbolContext.of_sdv(fm1.name, fst_matcher), FileMatcherSymbolContext.of_sdv(fm2.name, snd_matcher__w_respect_to_laziness), ] entries = ({} if additional_entries is None else dict(additional_entries)) entries.update({ PurePosixPath(file_name): asrt_primitive.is_matcher_that_gives(expected_result_of_complex) }) return NExArr( 'combination of {} && {}'.format(fm1.value, fm2.value), PrimAndExeExpectation.of_prim__const( matches_w_application_order( entries, sequence_builder.expected_application_sequence())), arrangement_wo_tcds(SymbolContext.symbol_table_of_contexts(symbols)), )
def _name_starts_with__and_hard_error_if_applied_to_non_directory( name: str, expected_name_prefix: str, ) -> FileMatcherSymbolContext: return FileMatcherSymbolContext.of_sdv( name, combinator_sdvs.Conjunction( [ sdv_components.matcher_sdv_from_constant_primitive( file_matchers.BaseNameStartsWithMatcher( expected_name_prefix)), sdv_components.matcher_sdv_from_constant_primitive( _HardErrorIfAppliedToNonDirectory()), ], combinator_matchers.no_op_freezer, ))
text_doc_assertions.new_single_string_text_for_test( 'Test failure: File is not a directory')) return matching_result.of(True) NAME_STARTS_WITH__P1 = _name_starts_with__and_hard_error_if_applied_to_non_directory( 'name_starts_with_P1', 'P1') NAME_STARTS_WITH__P2 = _name_starts_with__and_hard_error_if_applied_to_non_directory( 'name_starts_with_P2', 'P2', ) NAME_STARTS_WITH__S1 = FileMatcherSymbolContext.of_sdv( 'name_starts_with_S1', sdv_components.matcher_sdv_from_constant_primitive( file_matchers.BaseNameStartsWithMatcher('S1'))) NO_ACTION_ON_FILES_THEMSELVES__CONTENTS = [ File.empty('P1-f'), Dir.empty('P1-d'), sym_link('P1-s', 'P1-f'), sym_link('P1-sb', 'no-P2-existing'), ] FILES_SHOULD_BE_INCLUDED_EVEN_IF_MATCH__DEPTH_0 = NEA.new_identical_expected_and_actual( 'files should be included even if match / depth 0', NO_ACTION_ON_FILES_THEMSELVES__CONTENTS, ) FILES_SHOULD_BE_INCLUDED_EVEN_IF_MATCH__DEPTH_1 = NEA.new_identical_expected_and_actual(
def mk_logic_type_context_of_sdv( self, name: str, sdv: MatcherSdv[FileMatcherModel]) -> FileMatcherSymbolContext: return FileMatcherSymbolContext.of_sdv(name, sdv)