def assertion_variant(self) -> FilesMatcherArgumentsSetup: return files_matcher_setup_without_references( FileQuantificationAssertionVariant( Quantifier.ALL, file_contents_arg2(sm_arg.Empty()), ) )
class TestHardErrorWhenContentsOfAFileThatIsNotARegularFileIsTested(unittest.TestCase): name_of_checked_dir = 'checked-dir' file_content_assertion_variants = [ sm_arg.Empty(), sm_arg.NumLines(int_condition(comparators.NE, 0)), sm_arg.Equals.eq_string('expected'), ] 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 runTest(self): self._check_cases([ NArrEx('empty', sm_args.Empty(), asrt_interval.matches_unlimited()), NArrEx( 'conjunction', arg_rend.within_paren( arg_rend.conjunction([ sm_args.Empty(), sm_args.Equals(FileOrString.of_string('expected')), ])), asrt_interval.matches_unlimited()), NArrEx('negation', arg_rend.within_paren(arg_rend.negation(sm_args.Empty())), asrt_interval.matches_unlimited()), NArrEx( 'constant False' '(currently not able to derive interval from contents - ' 'would like this to become the empty interval)', arg_rend.constant(False), asrt_interval.matches_unlimited()), NArrEx('constant False', arg_rend.constant(True), asrt_interval.matches_unlimited()), ])
def runTest(self): for case in string_transformer_failing_validation_cases.failing_validation_cases( ): with self.subTest(validation_case=case.name): integration_check.CHECKER__PARSE_FULL.check__w_source_variants( self, args2.Transformed(case.value.symbol_context.name, args2.Empty()).as_arguments, model_constructor.must_not_be_used, Arrangement( symbols=case.value.symbol_context.symbol_table), Expectation( ParseExpectation( symbol_references=case.value.symbol_context. references_assertion, ), ExecutionExpectation( validation=case.value.expectation, ), ), )
class TestOnlyFilesSelectedByTheFileMatcherShouldBeChecked(unittest.TestCase): file_content_assertion_variants_that_pass_iff_file_is_empty = [ sm_arg.Empty(), sm_arg.NumLines(int_condition(comparators.EQ, 0)), sm_arg.Equals.eq_string(shlex.quote('')), ] def test__all__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.empty('selected-empty-file.txt'), File( 'un-selected-non-empty-file.txt', 'contents of non-emtpy file'), 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 pass_iff_file_is_empty_assertion in self.file_content_assertion_variants_that_pass_iff_file_is_empty: arguments_constructor = args.complete_arguments_constructor( FileQuantificationAssertionVariant( Quantifier.ALL, file_contents_arg2(pass_iff_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.pass__if_positive__fail__if_negative, ), ) ) 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, ), ) )
class TestForAllContentsEmptyFile(unittest.TestCase): name_of_checked_dir = 'checked-dir' for_all__empty__arguments = args.complete_arguments_constructor( FileQuantificationAssertionVariant( Quantifier.ALL, file_contents_arg2(sm_arg.Empty())) ) @property def instruction_checker(self) -> MatcherChecker: return MatcherChecker(self, sut.parsers().full) 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_just_one_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), 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, [ File.empty('empty-file.txt'), ]), ]), ) def test_just_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), 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('non-empty-file.txt', 'contents of non-empty file'), ]), ]), ) 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 runTest(self): self._check_cases([ NArrEx( '! >= (within line-num-range)', arg_rend.negation( args.LineNum2(im_args.comparison2(comparators.GTE, 4))), asrt_interval.matches_upper_limit(4 - 1)), NArrEx( '! >= (outside line-num-range)', arg_rend.negation( args.LineNum2( im_args.comparison2(comparators.LTE, FIRST_LINE_NUMBER - 1))), asrt_interval.matches_unlimited()), NArrEx('negation contents', arg_rend.negation(args.Contents(sm_args.Empty())), asrt_interval.matches_unlimited()), NArrEx('negation constant False', arg_rend.negation(arg_rend.constant(False)), asrt_interval.matches_unlimited()), NArrEx('negation constant True', arg_rend.negation(arg_rend.constant(True)), asrt_interval.matches_empty()), NArrEx( '> && <= (within line-num-range)', arg_rend.within_paren( arg_rend.conjunction([ args.LineNum2(im_args.comparison2(comparators.GT, 7)), args.LineNum2(im_args.comparison2(comparators.LTE, 12)), ])), asrt_interval.matches_finite(7 + 1, 12)), NArrEx( '> && contents (within line-num-range)', arg_rend.within_paren( arg_rend.conjunction([ args.LineNum2(im_args.comparison2(comparators.GT, 7)), args.Contents(sm_args.Empty()), ])), asrt_interval.matches_lower_limit(7 + 1)), NArrEx( 'contents && contents', arg_rend.within_paren( arg_rend.conjunction([ args.Contents(sm_args.Empty()), args.Contents(sm_args.Empty()), ])), asrt_interval.matches_unlimited()), NArrEx( '> && <= (partly outside line-num-range)', arg_rend.within_paren( arg_rend.conjunction([ args.LineNum2(im_args.comparison2(comparators.GT, -7)), args.LineNum2(im_args.comparison2(comparators.LTE, 12)), ])), asrt_interval.matches_upper_limit(12)), NArrEx( '> && <= (completely outside line-num-range)', arg_rend.within_paren( arg_rend.conjunction([ args.LineNum2(im_args.comparison2(comparators.GT, -7)), args.LineNum2(im_args.comparison2(comparators.LTE, -2)), ])), asrt_interval.matches_empty()), NArrEx( '> && <= && <= (outside line-num-range)', arg_rend.within_paren( arg_rend.conjunction([ args.LineNum2(im_args.comparison2(comparators.GT, -7)), args.LineNum2(im_args.comparison2(comparators.LTE, 12)), args.LineNum2(im_args.comparison2(comparators.LTE, 15)), ])), asrt_interval.matches_upper_limit(12)), NArrEx( '== || <= (within line-num-range)', arg_rend.within_paren( arg_rend.disjunction([ args.LineNum2(im_args.comparison2(comparators.EQ, 17)), args.LineNum2(im_args.comparison2(comparators.LTE, 10)), ])), asrt_interval.matches_upper_limit(17)), NArrEx( '== || contents (within line-num-range)', arg_rend.within_paren( arg_rend.disjunction([ args.LineNum2(im_args.comparison2(comparators.EQ, 17)), args.Contents(sm_args.Empty()), ])), asrt_interval.matches_unlimited()), NArrEx( 'contents || contents', arg_rend.within_paren( arg_rend.disjunction([ args.Contents(sm_args.Empty()), args.Contents(sm_args.Empty()), ])), asrt_interval.matches_unlimited()), NArrEx( '> || == (outside line-num-range)', arg_rend.within_paren( arg_rend.disjunction([ args.LineNum2(im_args.comparison2(comparators.GT, 5)), args.LineNum2(im_args.comparison2(comparators.EQ, -12)), ])), asrt_interval.matches_lower_limit(5 + 1)), NArrEx( '< || <= (completely outside line-num-range)', arg_rend.within_paren( arg_rend.disjunction([ args.LineNum2(im_args.comparison2(comparators.LT, -5)), args.LineNum2(im_args.comparison2(comparators.LTE, -3)), ])), asrt_interval.matches_empty()), NArrEx( '<= || > || == (outside line-num-range)', arg_rend.within_paren( arg_rend.disjunction([ args.LineNum2(im_args.comparison2(comparators.LTE, 0)), args.LineNum2(im_args.comparison2(comparators.GT, 5)), args.LineNum2(im_args.comparison2(comparators.EQ, 3)), ])), asrt_interval.matches_lower_limit(3)), NArrEx( '<= || contents || == (within line-num-range)', arg_rend.within_paren( arg_rend.disjunction([ args.LineNum2(im_args.comparison2(comparators.LTE, 12)), args.Contents(sm_args.Empty()), args.LineNum2(im_args.comparison2(comparators.EQ, 15)), ])), asrt_interval.matches_unlimited()), ])