def runTest(self): # ARRANGE # checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'a-dir') unconditionally_hard_error_file_matcher = FileMatcherSymbolContext.of_primitive( 'unconditionally_hard_error_file_matcher', matchers.MatcherThatReportsHardError()) file_in_model = 'a-file' # ACT & ASSERT # check_non_full_and_full( self, fc_args.FilesCondition([ fc_args.FileCondition( file_in_model, fm_args.SymbolReferenceWReferenceSyntax( unconditionally_hard_error_file_matcher.name)), ]), model_constructor__non_recursive(checked_dir.path_sdv), Arrangement( symbols=unconditionally_hard_error_file_matcher.symbol_table, tcds=checked_dir.tcds_arrangement_dir_with_contents( [File.empty(file_in_model)])), Expectation( ParseExpectation( symbol_references=asrt.matches_singleton_sequence( unconditionally_hard_error_file_matcher. reference_assertion)), ExecutionExpectation( is_hard_error=asrt_text_doc.is_any_text())), )
def runTest(self): # ARRANGE # error_message = 'error message from file matcher' file_matcher_that_raises_hard_error = FileMatcherSymbolContext.of_primitive( 'file_matcher_that_raises_hard_error', matchers.MatcherThatReportsHardError(error_message) ) path_relativity = conf_rel_sds(RelSdsOptionType.REL_ACT) checked_file = File.empty('checked-file.txt') argument = args.CompleteInstructionArg( ExpectationType.POSITIVE, path_relativity.path_argument_of_rel_name(checked_file.name), fm_args.SymbolReference(file_matcher_that_raises_hard_error.name)) # ACT & ASSERT # CHECKER.check( self, remaining_source(str(argument)), ArrangementPostAct( symbols=file_matcher_that_raises_hard_error.symbol_table, sds_contents=path_relativity.populator_for_relativity_option_root__sds( DirContents([checked_file]) ) ), instruction_check.expectation( main_result=pfh_assertions.is_hard_error( asrt_text_doc.rendered_text_matches(asrt_str.contains(error_message)) ), symbol_usages=asrt.matches_sequence([ file_matcher_that_raises_hard_error.reference_assertion ]) ))
def is_dir_file_matcher(symbol_name: str) -> FileMatcherSymbolContext: return FileMatcherSymbolContext.of_primitive( symbol_name, file_matchers.IsDirectoryMatcher() )
def is_regular_file_matcher(symbol_name: str) -> FileMatcherSymbolContext: return FileMatcherSymbolContext.of_primitive( symbol_name, file_matchers.IsRegularFileMatcher() )
def test__exists__SHOULD_consider_only_files_matched_by_the_file_matcher(self): # ARRANGE # name_of_checked_dir = 'name-of-checked-dir' name_starts_with_selected = FileMatcherSymbolContext.of_primitive( 'a_file_matcher_symbol', FileMatcherThatMatchesAnyFileWhosNameStartsWith('selected')) files_in_checked_dir = Dir(name_of_checked_dir, [ File( 'selected-non-empty-file.txt', 'contents of non-emtpy file'), File.empty('un-selected-empty-file.txt'), Dir.empty('un-selected-dir'), sym_link( 'un-selected-sym-link-to-dir', 'un-selected-dir'), sym_link( 'un-selected-broken-sym-link', 'non-existing-file'), ]) symbol_table_with_file_matcher = name_starts_with_selected.symbol_table relativity_root_conf = AN_ACCEPTED_SDS_REL_OPT_CONFIG expected_symbol_references = asrt.matches_sequence([ is_reference_to_file_matcher(name_starts_with_selected.name) ]) # ACT & ASSERT # for file_is_empty_assertion in self.file_content_assertion_variants_that_pass_iff_file_is_empty: arguments_constructor = args.complete_arguments_constructor( FileQuantificationAssertionVariant( Quantifier.EXISTS, file_contents_arg2(file_is_empty_assertion)), file_matcher=name_starts_with_selected.name ) for expectation_type in ExpectationType: etc = expectation_type_config__non_is_success(expectation_type) arguments = arguments_constructor.apply(etc) with self.subTest( expectation_type=expectation_type.name, arguments=arguments): integration_check.CHECKER__PARSE_FULL.check( self, remaining_source(arguments), model.model_with_source_path_as_sub_dir_of_rel_root(name_of_checked_dir)(relativity_root_conf), arrangement= arrangement_w_tcds( tcds_contents=relativity_root_conf.populator_for_relativity_option_root( DirContents([ files_in_checked_dir, ]) ), symbols=symbol_table_with_file_matcher ), expectation= Expectation( ParseExpectation( symbol_references=expected_symbol_references ), ExecutionExpectation( main_result=etc.fail__if_positive__pass_if_negative, ), ) )
def mk_logic_type_context_of_primitive( self, name: str, primitive: MatcherWTrace[FileMatcherModel] ) -> FileMatcherSymbolContext: return FileMatcherSymbolContext.of_primitive(name, primitive)