def test_file_is_directory_with_files_but_none_that_matches_name_pattern( self): name_of_directory = 'name-of-directory' pattern_that_matches_exactly_one_file = 'a*' dir_with_two_files = Dir(name_of_directory, [ File.empty('a file'), File.empty('b file'), ]) contents_of_relativity_option_root = DirContents([dir_with_two_files]) instruction_argument_constructor = argument_constructor_for_num_files_check( int_condition(comparators.EQ, 1), name_option_pattern=pattern_that_matches_exactly_one_file) self.checker.check_parsing_with_different_source_variants( instruction_argument_constructor, model.model_with_source_path_as_sub_dir_of_rel_root( name_of_directory), default_relativity=RelOptionType.REL_CWD, non_default_relativity=RelOptionType.REL_TMP, main_result_for_positive_expectation=PassOrFail.PASS, contents_of_relativity_option_root= contents_of_relativity_option_root, )
def test_no_files(self): self.instruction_checker.check_expectation_type_variants( self.for_all__empty__arguments, model.model_with_source_path_as_sub_dir_of_rel_root(self.name_of_checked_dir), root_dir_of_dir_contents=AN_ACCEPTED_SDS_REL_OPT_CONFIG, main_result_for_positive_expectation=PassOrFail.PASS, contents_of_relativity_option_root=DirContents([ Dir(self.name_of_checked_dir, []), ]), )
def test_file_is_directory_that_is_empty(self): name_of_empty_directory = 'name-of-empty_directory' instruction_argument_constructor = argument_constructor_for_emptiness_check() contents_of_relativity_option_root = DirContents([Dir.empty(name_of_empty_directory)]) self.checker.check_rel_opt_variants_and_expectation_type_variants( instruction_argument_constructor, model_with_source_path_as_sub_dir_of_rel_root(name_of_empty_directory), PassOrFail.PASS, contents_of_relativity_option_root=contents_of_relativity_option_root)
def test_just_one_regular(self): self.instruction_checker.check_expectation_type_variants( self.exists__type_dir__arguments, model.model_with_source_path_as_sub_dir_of_rel_root(self.name_of_checked_dir), root_dir_of_dir_contents=AN_ACCEPTED_SDS_REL_OPT_CONFIG, main_result_for_positive_expectation=PassOrFail.FAIL, contents_of_relativity_option_root=DirContents([ Dir(self.name_of_checked_dir, [ File.empty('regular.txt'), ]), ]), )
def test_one_empty_and_one_non_empty_file(self): self.instruction_checker.check_expectation_type_variants( self.for_all__empty__arguments, model.model_with_source_path_as_sub_dir_of_rel_root(self.name_of_checked_dir), main_result_for_positive_expectation=PassOrFail.FAIL, root_dir_of_dir_contents=AN_ACCEPTED_SDS_REL_OPT_CONFIG, contents_of_relativity_option_root=DirContents([ Dir(self.name_of_checked_dir, [ File.empty('empty-file.txt'), File('non-empty-file.txt', 'contents of non-empty file'), ]), ]), )
def test_file_is_directory_that_contain_files_but_non_matching_given_name_pattern(self): name_of_directory = 'name-of-directory' pattern = 'a*' existing_file = File.empty('b') instruction_argument_constructor = argument_constructor_for_emptiness_check(name_option_pattern=pattern) contents_of_relativity_option_root = DirContents([Dir(name_of_directory, [existing_file])]) self.checker.check_rel_opt_variants_and_expectation_type_variants( instruction_argument_constructor, model_with_source_path_as_sub_dir_of_rel_root(name_of_directory), PassOrFail.PASS, contents_of_relativity_option_root=contents_of_relativity_option_root)
def test_file_is_a_directory_that_is_not_empty(self): non_empty_directory = Dir('name-of-non-empty-dir', [File.empty('file-in-dir')]) instruction_argument_constructor = argument_constructor_for_emptiness_check() contents_of_relativity_option_root = DirContents([non_empty_directory]) self.checker.check_parsing_with_different_source_variants( instruction_argument_constructor, model_with_source_path_as_sub_dir_of_rel_root(non_empty_directory.name), default_relativity=RelOptionType.REL_CWD, non_default_relativity=RelOptionType.REL_TMP, main_result_for_positive_expectation=PassOrFail.FAIL, contents_of_relativity_option_root=contents_of_relativity_option_root, )
def test_hard_error_when_there_is_a_single_file_that_is_not_a_regular_file(self): name_of_checked_dir = 'checked-dir' relativity_root_conf = rel_opt_conf.default_conf_rel_any(RelOptionType.REL_CWD) the_model = model.model_with_source_path_as_sub_dir_of_rel_root(self.name_of_checked_dir)(relativity_root_conf) non_regular_files = [ Dir.empty('a-directory'), sym_link('sym-link', 'non-existing-target') ] for file_contents_assertion in self.file_content_assertion_variants: for quantifier in Quantifier: arguments_constructor = args.complete_arguments_constructor( FileQuantificationAssertionVariant( quantifier, file_contents_arg2(file_contents_assertion))) for expectation_type in ExpectationType: arguments = arguments_constructor.apply( expectation_type_config__non_is_success(expectation_type)) for non_regular_file in non_regular_files: with self.subTest( quantifier=quantifier.name, expectation_type=expectation_type.name, arguments=arguments, non_regular_file=non_regular_file.name): integration_check.CHECKER__PARSE_FULL.check( self, remaining_source(arguments), the_model, arrangement= arrangement_w_tcds( tcds_contents=relativity_root_conf.populator_for_relativity_option_root( DirContents([ Dir(name_of_checked_dir, [ non_regular_file, ]), ]) ) ), expectation= Expectation( execution=ExecutionExpectation( is_hard_error=asrt.anything_goes() ), ) )
def test_file_is_directory_with_files_but_none_that_matches_name_pattern(self): name_of_directory = 'name-of-directory' pattern = 'a*' existing_file = File.empty('b') instruction_argument_constructor = argument_constructor_for_emptiness_check(name_option_pattern=pattern) contents_of_relativity_option_root = DirContents([Dir(name_of_directory, [existing_file])]) self.checker.check_parsing_with_different_source_variants( instruction_argument_constructor, model_with_source_path_as_sub_dir_of_rel_root(name_of_directory), default_relativity=RelOptionType.REL_CWD, non_default_relativity=RelOptionType.REL_TMP, main_result_for_positive_expectation=PassOrFail.PASS, contents_of_relativity_option_root=contents_of_relativity_option_root, )
def test_file_is_a_directory_that_has_unexpected_number_of_files(self): directory_with_one_file = Dir('name-of-non-empty-dir', [File.empty('file-in-dir')]) instruction_argument_constructor = argument_constructor_for_num_files_check( int_condition(comparators.EQ, 2)) contents_of_relativity_option_root = DirContents( [directory_with_one_file]) self.checker.check_parsing_with_different_source_variants( instruction_argument_constructor, model.model_with_source_path_as_sub_dir_of_rel_root( directory_with_one_file.name), default_relativity=RelOptionType.REL_CWD, non_default_relativity=RelOptionType.REL_TMP, main_result_for_positive_expectation=PassOrFail.FAIL, contents_of_relativity_option_root= contents_of_relativity_option_root, )
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 runTest(self): # ARRANGE # positive_expectation = expectation_type_config__non_is_success( ExpectationType.POSITIVE) rel_opt_conf = rel_opt_confs.conf_rel_sds(RelSdsOptionType.REL_TMP) parser = sut.parsers().full # dir contents checked_dir = Dir('checked-dir', [ File.empty('a.x'), File.empty('a.y'), File.empty('b.x'), File.empty('b.y'), ]) # arguments file_matcher_arg__begins_with_a = fm_args.file_matcher_arguments( name_pattern='a*') file_matcher_arg__ends_with_x = fm_args.file_matcher_arguments( name_pattern='*.x') files_matcher_args__num_files_eq_1 = fsm_args.NumFilesAssertionVariant( int_args.int_condition(comparators.EQ, 1)) files_matcher_args__num_files_ending_with_x_eq_1 = fsm_args.SelectionAndMatcherArgumentsConstructor( file_matcher_arg__ends_with_x, files_matcher_args__num_files_eq_1, ) files_matcher_source__num_files_ending_with_x_eq_1 = files_matcher_args__num_files_ending_with_x_eq_1.apply( positive_expectation) symbol_name = 'FILES_MATCHER_SYMBOL' files_matcher_args__begins_with_a__symbol = fsm_args.SelectionAndMatcherArgumentsConstructor( file_matcher_arg__begins_with_a, fsm_args.symbol_reference(symbol_name), ) files_matcher_source__begins_with_a__symbol = files_matcher_args__begins_with_a__symbol.apply( positive_expectation) num_files_ending_with_x_eq_1_resolver = parser.parse( remaining_source( files_matcher_source__num_files_ending_with_x_eq_1)) symbols = FilesMatcherSymbolContext.of_sdv( symbol_name, num_files_ending_with_x_eq_1_resolver, ).symbol_table # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check( self, remaining_source(files_matcher_source__begins_with_a__symbol), model.model_with_source_path_as_sub_dir_of_rel_root( checked_dir.name)(rel_opt_conf), arrangement_w_tcds( non_hds_contents=rel_opt_conf. populator_for_relativity_option_root__sds( DirContents([checked_dir])), symbols=symbols, ), Expectation( ParseExpectation(symbol_references=asrt.matches_sequence( [is_reference_to_files_matcher(symbol_name)]), ), ExecutionExpectation( main_result=matcher_assertions.is_matching_success(), ), ))