def test_one_file_wo_matcher_and_one_w_matcher(self): # ARRANGE # file_name_w_matcher = 'file-name-with-matcher' file_name_wo_matcher = 'file-name-without-matcher' fm_symbol = 'file_matcher' arguments = args.FilesCondition([ args.FileCondition(file_name_wo_matcher), args.FileCondition( file_name_w_matcher, fm_args.SymbolReferenceWReferenceSyntax(fm_symbol)), ]) # ACT & ASSERT # CHECKER.check_multi__w_source_variants( self, arguments.as_arguments, asrt.matches_sequence([is_reference_to_file_matcher(fm_symbol)]), None, [ NExArr( 'FileMatcher should give {}'.format(expected_result), PrimAndExeExpectation.of_prim__const( asrt_primitive.files_matches({ PurePosixPath(file_name_wo_matcher): asrt.is_none, PurePosixPath(file_name_w_matcher): asrt_primitive.is_matcher_that_gives( expected_result) })), arrangement_wo_tcds( FileMatcherSymbolContext.of_primitive_constant( fm_symbol, expected_result).symbol_table), ) for expected_result in [False, True] ])
def test_file_matcher_reference_is_reported(self): name_of_file_matcher = 'a_file_matcher_symbol' arguments_constructor = args.complete_arguments_constructor( self.assertion_variant.arguments, file_matcher=name_of_file_matcher) arguments = arguments_constructor.apply( pfh_expectation_type_config(ExpectationType.NEGATIVE)) source = remaining_source(arguments) # ACT # matcher = parsers().full.parse(source) assert isinstance(matcher, MatcherSdv) actual = matcher.references # ASSERT # expected_references = asrt.matches_sequence( list(self.assertion_variant.expected_references) + [is_reference_to_file_matcher(name_of_file_matcher)]) expected_references.apply_without_message(self, actual) asrt_source.is_at_end_of_line(1)
def runTest(self): # ARRANGE # name_of_referenced_selector = 'SELECTOR' name_of_referenced_files_matcher = 'FILES_MATCHER' expected_symbol_usages = asrt.matches_sequence([ is_reference_to_file_matcher(name_of_referenced_selector), is_reference_to_files_matcher(name_of_referenced_files_matcher), ]) arguments = fsm_args.argument_constructor_for_symbol_reference( files_matcher_symbol_name=name_of_referenced_files_matcher, named_matcher=name_of_referenced_selector).apply( expectation_type_config__non_is_success( ExpectationType.POSITIVE)) source = remaining_source(arguments) # ACT # sdv = sut.parsers().full.parse(source) # ASSERT # expected_symbol_usages.apply_without_message(self, sdv.references)
def test_single_file_name_with_matcher(self): # ARRANGE # file_name = 'file-name' fm_symbol = 'file_matcher' cases = [ NameAndValue( 'single name entry', args.FilesCondition([ args.FileCondition( file_name, fm_args.SymbolReferenceWReferenceSyntax(fm_symbol)) ]), ), NameAndValue( 'two entries with same file name, 1st without and 2nd with FileMatcher', args.FilesCondition([ args.FileCondition(file_name), args.FileCondition( file_name, fm_args.SymbolReferenceWReferenceSyntax(fm_symbol)), ]), ), NameAndValue( 'two entries with same file name, 1st with and 2nd without FileMatcher', args.FilesCondition([ args.FileCondition( file_name, fm_args.SymbolReferenceWReferenceSyntax(fm_symbol)), args.FileCondition(file_name), ]), ), ] # ACT & ASSERT # for case in cases: with self.subTest(case.name): CHECKER.check_multi__w_source_variants( self, case.value.as_arguments, asrt.matches_sequence( [is_reference_to_file_matcher(fm_symbol)]), None, [ NExArr( 'FileMatcher should give {}'.format( expected_result), PrimAndExeExpectation.of_prim__const( asrt_primitive.files_matches({ PurePosixPath(file_name): asrt_primitive.is_matcher_that_gives( expected_result) })), arrangement_wo_tcds( FileMatcherSymbolContext.of_primitive_constant( fm_symbol, expected_result).symbol_table), ) for expected_result in [False, True] ])
def runTest(self): # ARRANGE # path_symbol_name = 'the_path_symbol' file_matcher_symbol_name = 'the_file_matcher_symbol' expected_path_symbol_ref = asrt_sym_ref.symbol_usage_equals_data_type_symbol_reference( SymbolReference(path_symbol_name, path_or_string_reference_restrictions( EXPECTED_ACCEPTED_PATH_RELATIVITY_VARIANTS)) ) expected_file_matcher_ref = fm_references.is_reference_to_file_matcher(file_matcher_symbol_name) cases = [ NEA('no symbols', asrt.matches_sequence([]), args.WithOptionalNegation(path_argument('plain-file-name')) ), NEA('path symbol', asrt.matches_sequence([ expected_path_symbol_ref, ]), args.WithOptionalNegation(symbol_path_argument(path_symbol_name)) ), NEA('path symbol and file matcher symbol', asrt.matches_sequence([ expected_path_symbol_ref, expected_file_matcher_ref, ]), args.WithOptionalNegation(symbol_path_argument(path_symbol_name), fm_args.SymbolReference(file_matcher_symbol_name)) ), ] for case in cases: for expectation_type in ExpectationType: arguments = case.actual.get(expectation_type) source = remaining_source(str(arguments)) with self.subTest(case=case.name, expectation_type=expectation_type): # ACT # instruction = sut.setup('the-instruction-name').parse(ARBITRARY_FS_LOCATION_INFO, source) # ASSERT # self.assertIsInstance(instruction, AssertPhaseInstruction) case.expected.apply_without_message(self, instruction.symbol_usages())
def test_two_different_files_w_matcher(self): # ARRANGE # file_name__constant = 'file-name-with-constant-matcher' file_name__w_variations = 'file-name-with-matcher-with-variations' fm__constant = FileMatcherSymbolContextOfPrimitiveConstant( 'fm_constant', True) fm__w_variations = 'fm_w_variations' arguments = args.FilesCondition([ args.FileCondition( file_name__constant, fm_args.SymbolReferenceWReferenceSyntax(fm__constant.name)), args.FileCondition( file_name__w_variations, fm_args.SymbolReferenceWReferenceSyntax(fm__w_variations)), ]) # ACT & ASSERT # CHECKER.check_multi__w_source_variants( self, arguments.as_arguments, asrt.matches_sequence([ fm__constant.reference_assertion, is_reference_to_file_matcher(fm__w_variations), ]), None, [ NExArr( 'FileMatcher with variations should give {}'.format( expected_result_of_matcher_w_variations), PrimAndExeExpectation.of_prim__const( asrt_primitive.files_matches({ PurePosixPath(file_name__constant): asrt_primitive.is_matcher_that_gives( fm__constant.result_value), PurePosixPath(file_name__w_variations): asrt_primitive.is_matcher_that_gives( expected_result_of_matcher_w_variations) })), arrangement_wo_tcds( SymbolContext.symbol_table_of_contexts([ fm__constant, FileMatcherSymbolContext.of_primitive_constant( fm__w_variations, expected_result_of_matcher_w_variations), ])), ) for expected_result_of_matcher_w_variations in [False, True] ])
def test_validation_error_SHOULD_be_reported_WHEN_file_matcher_reports_validation_error( self): # ARRANGE # fm_symbol_name = 'the_file_matcher' arguments = args.FilesCondition([ args.FileCondition( 'file-name', fm_args.SymbolReferenceWReferenceSyntax(fm_symbol_name)) ]) # ACT & ASSERT # CHECKER.check_multi__w_source_variants( self, arguments.as_arguments, symbol_references=asrt.matches_singleton_sequence( is_reference_to_file_matcher(fm_symbol_name)), input_=None, execution=validation_cases.failing_validation_cases__multi_exe( fm_symbol_name))
def test_validation_SHOULD_fail_WHEN_validation_of_files_condition_fails( self): # ARRANGE # fm_symbol_name = 'the_file_matcher' fc_argument = fc_args.FilesCondition([ fc_args.FileCondition( 'file-name', fm_args.SymbolReferenceWReferenceSyntax(fm_symbol_name)) ]) for case in FULL_AND_NON_FULL_CASES: fsm = case.arguments_for_fc(fc_argument) with self.subTest(case.name): # ACT & ASSERT # CHECKER__PARSE_FULL.check_multi__w_source_variants( self, fsm.as_arguments, symbol_references=asrt.matches_singleton_sequence( is_reference_to_file_matcher(fm_symbol_name)), input_=None, execution=validation_cases. failing_validation_cases__multi_exe(fm_symbol_name))
def runTest(self): # ARRANGE # fm_symbol_name = 'file_matcher_symbol' fc_argument = fc_args.FilesCondition([ fc_args.FileCondition('file-name', fm_args.SymbolReferenceWReferenceSyntax(fm_symbol_name)) ]) symbol_references_expectation = asrt.matches_singleton_sequence( is_reference_to_file_matcher(fm_symbol_name), ) parser = sut.parsers().full for case in FULL_AND_NON_FULL_CASES: fsm = case.arguments_for_fc(fc_argument) with self.subTest(case.name): # ACT # sdv = parser.parse(fsm.as_remaining_source) # ASSERT # symbol_references_expectation.apply_without_message( self, sdv.references, )
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 reference_assertion(self, symbol_name: str) -> Assertion[SymbolReference]: return is_reference_to_file_matcher(symbol_name)
def test_2_files_in_fc(self): # ARRANGE # name_of_file_in_fc__1 = 'file-in-files-condition-1' name_of_file_in_fc__2 = 'file-in-files-condition-2' name_of_file_not_in_fc__1 = 'file-not-in-files-condition-1' name_of_file_not_in_fc__2 = 'file-not-in-files-condition-2' file_matcher_name = 'the_file_matcher' arguments = args.matches_full( fc_args.FilesCondition([ fc_args.FileCondition(name_of_file_in_fc__1, fm_args.SymbolReferenceWReferenceSyntax(file_matcher_name)), fc_args.FileCondition(name_of_file_in_fc__2), ]) ) checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'dir-w-more-than-two-files') execution_cases = [ NExArr( '3 files: one file name matches, and matcher matches', PRIM_AND_EXE_EXPECTATION__NON_MATCH, Arrangement( symbols=is_regular_file_matcher(file_matcher_name).symbol_table, tcds=checked_dir.tcds_arrangement_dir_with_contents([ File.empty(name_of_file_in_fc__1), File.empty(name_of_file_not_in_fc__1), File.empty(name_of_file_not_in_fc__2), ]) ) ), NExArr( '3 files: both file names matches, and matcher matches', PRIM_AND_EXE_EXPECTATION__NON_MATCH, Arrangement( symbols=is_regular_file_matcher(file_matcher_name).symbol_table, tcds=checked_dir.tcds_arrangement_dir_with_contents([ File.empty(name_of_file_in_fc__1), File.empty(name_of_file_in_fc__2), File.empty(name_of_file_not_in_fc__1), ]) ) ), NExArr( '3 files: both file name matches, but matcher does not match', PRIM_AND_EXE_EXPECTATION__NON_MATCH, Arrangement( symbols=is_dir_file_matcher(file_matcher_name).symbol_table, tcds=checked_dir.tcds_arrangement_dir_with_contents([ File.empty(name_of_file_in_fc__1), File.empty(name_of_file_in_fc__2), File.empty(name_of_file_not_in_fc__1), ]) ) ), NExArr( '4 files: both file name matches, and matcher matches', PRIM_AND_EXE_EXPECTATION__NON_MATCH, Arrangement( symbols=is_regular_file_matcher(file_matcher_name).symbol_table, tcds=checked_dir.tcds_arrangement_dir_with_contents([ File.empty(name_of_file_in_fc__1), File.empty(name_of_file_in_fc__2), File.empty(name_of_file_not_in_fc__1), File.empty(name_of_file_not_in_fc__2), ]) ) ), ] # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check_multi__w_source_variants( self, arguments.as_arguments, symbol_references=asrt.matches_sequence([ is_reference_to_file_matcher(file_matcher_name), ]), input_=model_constructor__non_recursive(checked_dir.path_sdv), execution=execution_cases )
def test_3_file_names__1_fn_2_times_w_matchers_that_should_be_combined( self): # ARRANGE # fn_1_time_wo_fm = 'file-name--1-time--wo-matcher' fn_1_time_w_fm = 'file-name-1-time--w-matcher' fn_2_times_w_fm = 'file-name-2-times--w-matcher' fn_1_time__fm = NavBuilder('fn_1_time__fm') fn_2_times__fm_1 = NavBuilder('fn_2_times__fm_1') fn_2_times__fm_2 = NavBuilder('fn_2_times__fm_2') cases = [ NIE( 'files wo matcher combination : before', [ is_reference_to_file_matcher(fn_1_time__fm.name), is_reference_to_file_matcher(fn_2_times__fm_1.name), is_reference_to_file_matcher(fn_2_times__fm_2.name), ], args.FilesCondition([ args.FileCondition(fn_1_time_wo_fm), args.FileCondition( fn_1_time_w_fm, fm_args.SymbolReferenceWReferenceSyntax( fn_1_time__fm.name)), args.FileCondition( fn_2_times_w_fm, fm_args.SymbolReferenceWReferenceSyntax( fn_2_times__fm_1.name)), args.FileCondition( fn_2_times_w_fm, fm_args.SymbolReferenceWReferenceSyntax( fn_2_times__fm_2.name)), ]), ), NIE( 'files wo matcher combination : between', [ is_reference_to_file_matcher(fn_2_times__fm_1.name), is_reference_to_file_matcher(fn_1_time__fm.name), is_reference_to_file_matcher(fn_2_times__fm_2.name), ], args.FilesCondition([ args.FileCondition( fn_2_times_w_fm, fm_args.SymbolReferenceWReferenceSyntax( fn_2_times__fm_1.name)), args.FileCondition(fn_1_time_wo_fm), args.FileCondition( fn_1_time_w_fm, fm_args.SymbolReferenceWReferenceSyntax( fn_1_time__fm.name)), args.FileCondition( fn_2_times_w_fm, fm_args.SymbolReferenceWReferenceSyntax( fn_2_times__fm_2.name)), ]), ), NIE( 'files wo matcher combination : after', [ is_reference_to_file_matcher(fn_2_times__fm_1.name), is_reference_to_file_matcher(fn_2_times__fm_2.name), is_reference_to_file_matcher(fn_1_time__fm.name), ], args.FilesCondition([ args.FileCondition( fn_2_times_w_fm, fm_args.SymbolReferenceWReferenceSyntax( fn_2_times__fm_1.name)), args.FileCondition( fn_2_times_w_fm, fm_args.SymbolReferenceWReferenceSyntax( fn_2_times__fm_2.name)), args.FileCondition(fn_1_time_wo_fm), args.FileCondition( fn_1_time_w_fm, fm_args.SymbolReferenceWReferenceSyntax( fn_1_time__fm.name)), ]), ), ] # ACT & ASSERT # for case in cases: with self.subTest(case.name): CHECKER.check_multi( self, case.input_value.as_arguments, ParseExpectation(symbol_references=asrt.matches_sequence( case.expected_value)), None, [ result_is_single_file_name_w_lazy_conjunction_w_1st_is_applied_before_2nd( fn_2_times_w_fm, fn_2_times__fm_1.build(fm1), fn_2_times__fm_2.build(fm2), additional_symbols=[ FileMatcherSymbolContext.of_primitive_constant( fn_1_time__fm.name, fm2) ], additional_entries={ PurePosixPath(fn_1_time_wo_fm): asrt.is_none, PurePosixPath(fn_1_time_w_fm): asrt_primitive.is_matcher_that_gives(fm2), }) for (fm1, fm2) in [(False, False), ( False, True), (True, False), (True, True)] ])
def test_single_repeated_file_name__2_w_fm_1_wo_fm(self): # ARRANGE # file_name = 'file-name' fm1_symbol = NavBuilder('fm1') fm2_symbol = NavBuilder('fm2') cases = [ NameAndValue( 'two entries', args.FilesCondition([ args.FileCondition( file_name, fm_args.SymbolReferenceWReferenceSyntax( fm1_symbol.name)), args.FileCondition( file_name, fm_args.SymbolReferenceWReferenceSyntax( fm2_symbol.name)), ]), ), NameAndValue( 'one empty entry above', args.FilesCondition([ args.FileCondition(file_name), args.FileCondition( file_name, fm_args.SymbolReferenceWReferenceSyntax( fm1_symbol.name)), args.FileCondition( file_name, fm_args.SymbolReferenceWReferenceSyntax( fm2_symbol.name)), ]), ), NameAndValue( 'one empty entry between', args.FilesCondition([ args.FileCondition( file_name, fm_args.SymbolReferenceWReferenceSyntax( fm1_symbol.name)), args.FileCondition(file_name), args.FileCondition( file_name, fm_args.SymbolReferenceWReferenceSyntax( fm2_symbol.name)), ]), ), NameAndValue( 'one empty entry below', args.FilesCondition([ args.FileCondition( file_name, fm_args.SymbolReferenceWReferenceSyntax( fm1_symbol.name)), args.FileCondition( file_name, fm_args.SymbolReferenceWReferenceSyntax( fm2_symbol.name)), args.FileCondition(file_name), ]), ), ] # ACT & ASSERT # for case in cases: with self.subTest(case.name): CHECKER.check_multi( self, case.value.as_arguments, ParseExpectation(symbol_references=asrt.matches_sequence([ is_reference_to_file_matcher(fm1_symbol.name), is_reference_to_file_matcher(fm2_symbol.name), ])), None, [ result_is_single_file_name_w_lazy_conjunction_w_1st_is_applied_before_2nd( file_name, fm1_symbol.build(fm1), fm2_symbol.build(fm2), ) for (fm1, fm2) in [(False, False), ( False, True), (True, False), (True, True)] ])
def runTest(self): # ARRANGE # cases = [ NIE( 'file name reference', [ is_sym_ref_to_string__w_all_indirect_refs_are_strings( STRING_SYMBOL_NAME) ], args.FilesCondition([ args.FileCondition( SymbolWithReferenceSyntax(STRING_SYMBOL_NAME)), ]), ), NIE( 'file name reference (embedded)', [ is_sym_ref_to_string__w_all_indirect_refs_are_strings( STRING_SYMBOL_NAME) ], args.FilesCondition([ args.FileCondition( 'file-name-prefix-' + str(SymbolWithReferenceSyntax(STRING_SYMBOL_NAME)) + '-suffix'), ]), ), NIE( 'file matcher reference', [is_reference_to_file_matcher(FILE_MATCHER_SYMBOL_NAME)], args.FilesCondition([ args.FileCondition( 'constant-file-name', fm_args.SymbolReferenceWReferenceSyntax( FILE_MATCHER_SYMBOL_NAME)), ]), ), NIE( 'file name and file matcher reference', [ is_sym_ref_to_string__w_all_indirect_refs_are_strings( STRING_SYMBOL_NAME), is_reference_to_file_matcher(FILE_MATCHER_SYMBOL_NAME), ], args.FilesCondition([ args.FileCondition( SymbolWithReferenceSyntax(STRING_SYMBOL_NAME), fm_args.SymbolReferenceWReferenceSyntax( FILE_MATCHER_SYMBOL_NAME)), ]), ), NIE( 'multiple file name and file matcher reference', [ is_sym_ref_to_string__w_all_indirect_refs_are_strings( STRING_SYMBOL_NAME), is_reference_to_file_matcher(FILE_MATCHER_SYMBOL_NAME), is_sym_ref_to_string__w_all_indirect_refs_are_strings( STRING_SYMBOL_NAME_2), is_reference_to_file_matcher(FILE_MATCHER_SYMBOL_NAME_2), ], args.FilesCondition([ args.FileCondition( SymbolWithReferenceSyntax(STRING_SYMBOL_NAME), fm_args.SymbolReferenceWReferenceSyntax( FILE_MATCHER_SYMBOL_NAME), ), args.FileCondition( SymbolWithReferenceSyntax(STRING_SYMBOL_NAME_2), fm_args.SymbolReferenceWReferenceSyntax( FILE_MATCHER_SYMBOL_NAME_2), ), ]), ), ] for must_be_on_current_line in [False, True]: for case in cases: with self.subTest( case=case.name, must_be_on_current_line=must_be_on_current_line): # ACT # actual = sut.parsers(must_be_on_current_line).full.parse( case.input_value.as_remaining_source) # ASSERT # expectation = asrt.matches_sequence(case.expected_value) expectation.apply_without_message( self, actual.references, )