def test_1_file_in_fc_wo_matcher(self): # ARRANGE # name_of_file_in_fc = 'file-in-files-condition' 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' arguments = args.matches_full( fc_args.FilesCondition([fc_args.FileCondition(name_of_file_in_fc)]) ) checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'dir-w-more-than-one-file') execution_cases = [ NExArr( '2 files: one file name matches', PRIM_AND_EXE_EXPECTATION__NON_MATCH, Arrangement( tcds=checked_dir.tcds_arrangement_dir_with_contents([ File.empty(name_of_file_in_fc), File.empty(name_of_file_not_in_fc_1), ]) ) ), NExArr( '2 files: no file name matches', PRIM_AND_EXE_EXPECTATION__NON_MATCH, Arrangement( tcds=checked_dir.tcds_arrangement_dir_with_contents([ File.empty(name_of_file_not_in_fc_1), File.empty(name_of_file_not_in_fc_2), ]) ) ), NExArr( '3 files: one file name matches', PRIM_AND_EXE_EXPECTATION__NON_MATCH, Arrangement( tcds=checked_dir.tcds_arrangement_dir_with_contents([ File.empty(name_of_file_in_fc), 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.is_empty_sequence, input_=model_constructor__non_recursive(checked_dir.path_sdv), execution=execution_cases )
def _check_variants_with_expectation_type( self, args_variant_constructor: InstructionArgumentsVariantConstructor, expected_result_of_positive_test: PassOrFail, actual_file_contents: str, symbols: SymbolTable = None, expected_symbol_references: Assertion[Sequence[SymbolReference]] = asrt.is_empty_sequence): for expectation_type in ExpectationType: etc = expectation_type_config__non_is_success(expectation_type) with self.subTest(expectation_type=expectation_type): args_variant = args_variant_constructor.construct(expectation_type) complete_instruction_arguments = test_configuration.arguments_for(args_variant) for source in equivalent_source_variants__for_expression_parser( self, complete_instruction_arguments): integration_check.CHECKER__PARSE_FULL.check( self, source, model_constructor.of_str(self, actual_file_contents), Arrangement( tcds=TcdsArrangement( post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY ), symbols=symbols), Expectation( ParseExpectation( symbol_references=expected_symbol_references, ), ExecutionExpectation( main_result=etc.main_result(expected_result_of_positive_test), ), ) )
def test_access_of_sub_dir_for_failure_message_rendering(self): # ARRANGE # root_1__file = File.empty('f-1') root_2__dir = Dir('d-2', []) arguments = args.matches_full( fc_args.FilesCondition([fc_args.FileCondition(root_1__file.name)]) ) checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'checked-dir') # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check__w_source_variants( self, arguments.as_arguments, input_=model_constructor__recursive(checked_dir.path_sdv), arrangement=Arrangement( tcds=checked_dir.tcds_arrangement_dir_with_contents([ root_1__file, root_2__dir, ]) ), expectation=Expectation( parse=ParseExpectation( symbol_references=asrt.is_empty_sequence, ), execution=PRIM_AND_EXE_EXPECTATION__NON_MATCH.execution, primitive=PRIM_AND_EXE_EXPECTATION__NON_MATCH.primitive, ), )
def runTest(self): # ARRANGE # helper = IntegrationCheckHelper() actual_contents = [ Dir('P1-matches', [ File.empty('file-in-pruned-dir'), ]) ] arguments = conjunction([ Parentheses( fsm_args.Prune( fm_args.SymbolReference(NAME_STARTS_WITH__P1.name), fsm_args.NumFiles(int_condition(comparators.EQ, 1)))), fsm_args.NumFiles(int_condition(comparators.EQ, 2)), ]) # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check__w_source_variants( self, arguments=arguments.as_arguments, input_=helper.model_constructor_for_checked_dir__recursive(), arrangement=Arrangement( symbols=NAME_STARTS_WITH__P1.symbol_table, tcds=helper.dir_arg.tcds_arrangement_dir_with_contents( actual_contents)), expectation=Expectation( ParseExpectation(symbol_references=asrt.matches_sequence([ NAME_STARTS_WITH__P1.reference_assertion, ])), EXECUTION_IS_PASS, ))
def test(self): symbol_name = 'the_string_matcher' for quantifier in Quantifier: arguments = args.Quantification( quantifier, fm_args.SymbolReference(symbol_name)) for case in validation_cases.failing_validation_cases(symbol_name): symbol_context = case.value.symbol_context with self.subTest(quantifier=quantifier, validation_case=case.name): integration_check.CHECKER__PARSE_FULL.check( self, source=remaining_source(str(arguments)), input_=arbitrary_model(), arrangement= Arrangement( symbols=symbol_context.symbol_table ), expectation= Expectation( ParseExpectation( symbol_references=symbol_context.references_assertion, ), ExecutionExpectation( validation=case.value.expectation, ), ), )
def _check( self, arguments: ArgumentElements, expected_result: bool, all_symbols: Sequence[NameAndValue[MatcherWTrace[MODEL]]], expected_trace: tree.Node[bool], ): conf = self.configuration helper = self._asrt_helper conf.checker_for_parser_of_full_expr().check__w_source_variants( self, arguments.as_arguments, conf.arbitrary_model, Arrangement(symbols=SymbolContext.symbol_table_of_contexts([ conf.mk_logic_type_context_of_primitive(sym.name, sym.value) for sym in all_symbols ]), ), Expectation( ParseExpectation(symbol_references=helper.is_sym_refs_to( [sym.name for sym in all_symbols]), ), ExecutionExpectation(main_result=asrt_matching_result.matches( value=asrt.equals(expected_result), trace=trace_equals(expected_trace)))), )
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 test_invalid_arguments_with_symbol_references(self): symbol_name = SymbolWithReferenceSyntax('symbol_name') operand_arg_with_symbol_ref_list = [ ' {op} {sym}'.format(op=comparators.EQ.name, sym=symbol_name), ] invalid_symbol_values = [ 'not_a_number', '1.5', '72 87', ] for invalid_symbol_value in invalid_symbol_values: symbol = StringConstantSymbolContext(symbol_name.name, invalid_symbol_value) for operand_arg_with_symbol_ref in operand_arg_with_symbol_ref_list: arguments = self._conf().arguments_constructor.apply( operand_arg_with_symbol_ref) with self.subTest(argument=arguments, invalid_symbol_value=invalid_symbol_value): for source in equivalent_source_variants__for_expression_parser( self, Arguments(arguments)): self._check( source, Arrangement(symbols=symbol.symbol_table), Expectation( ParseExpectation( symbol_references=asrt.matches_sequence([ symbol. reference_assertion__string__w_all_indirect_refs_are_strings ]), ), ExecutionExpectation( validation=asrt_validation. ValidationAssertions. pre_sds_fails__w_any_msg(), ), ), )
def runTest(self): string_transformer = StringTransformerSymbolContext.of_primitive( 'the_string_transformer', string_transformers.arbitrary()) for case in string_matcher_failing_validation_cases.failing_validation_cases( ): with self.subTest(validation_case=case.name): symbol_context = case.value.symbol_context integration_check.CHECKER__PARSE_FULL.check__w_source_variants( self, args2.Transformed( string_transformer.name, args2.SymbolReference( symbol_context.name)).as_arguments, model_constructor.must_not_be_used, Arrangement( symbols=SymbolContext.symbol_table_of_contexts([ string_transformer, symbol_context, ])), Expectation( ParseExpectation( symbol_references=asrt.matches_sequence([ string_transformer.reference_assertion, symbol_context.reference_assertion, ]), ), ExecutionExpectation( validation=case.value.expectation, ), ), )
def runTest(self): # ARRANGE # clashing_file_name = 'clashing-file' non_clashing_file_name = 'non-clashing-file' clash_cases: Sequence[NameAndValue[FileSystemElements]] = [ NameAndValue( 'exists as regular', [fs.File.empty(clashing_file_name)], ), NameAndValue( 'exists as dir', [fs.Dir.empty(clashing_file_name)], ), NameAndValue( 'exists as sym-link to regular', [fs.File.empty(non_clashing_file_name), fs.sym_link(clashing_file_name, non_clashing_file_name)], ), NameAndValue( 'exists as broken sym-link', [fs.sym_link(clashing_file_name, non_clashing_file_name)], ), ] src_dir_relativity = relativity_options.conf_rel_any(RelOptionType.REL_HDS_CASE) src_dir_symbol = PathDdvSymbolContext.of_no_suffix( 'SRC_PATH_SYMBOL', src_dir_relativity.relativity, accepted_relativities=RELATIVITY_VARIANTS__READ__BEFORE_ACT, ) arguments_syntax = abs_stx.CopyOfDirContentsAbsStx(src_dir_symbol.abstract_syntax) for clash_case in clash_cases: with self.subTest(clash_case.name): # ACT & ASSERT # integration_check.CHECKER.check__abs_stx( self, arguments_syntax, clash_case.value, Arrangement( symbols=src_dir_symbol.symbol_table, tcds=TcdsArrangement( tcds_contents=src_dir_relativity.populator_for_relativity_option_root__s( [fs.File.empty(clashing_file_name)] ) ) ), Expectation( ParseExpectation( source=asrt_source.is_at_end_of_line(1), symbol_references=src_dir_symbol.references_assertion, ), execution=ExecutionExpectation.is_any_hard_error() ), )
def execution_cases( self) -> Sequence[NExArr[ExecutionResult, Arrangement]]: return [ NExArr( num_files_setup.name, FullExecutionResult(num_files_setup.expected), Arrangement(tcds=self._helper. tcds_arrangement_for_contents_of_checked_dir( num_files_setup.actual))) for num_files_setup in self.num_files_setup.cases ]
def runTest(self): failure_message = 'failure' failing_validation_result = asrt_validation.new_single_string_text_for_test( failure_message) line_matcher_symbol_name = 'line_matcher_with_failing_validation' asserted_symbol_references = asrt.matches_sequence( [is_reference_to_line_matcher(line_matcher_symbol_name)]) validation_cases = [ NEA('failure pre sds', expected=Expectation( ParseExpectation( symbol_references=asserted_symbol_references, ), ExecutionExpectation( validation=ValidationAssertions.pre_sds_fails( asrt.equals(failure_message)), ), ), actual=ConstantDdvValidator( pre_sds_result=failing_validation_result)), NEA('failure post sds', expected=Expectation( ParseExpectation( symbol_references=asserted_symbol_references, ), ExecutionExpectation(validation=ValidationAssertions. post_sds_fails__w_any_msg(), ), ), actual=ConstantDdvValidator( post_sds_result=failing_validation_result)), ] for case in validation_cases: symbols = LineMatcherSymbolContext.of_sdv( line_matcher_symbol_name, successful_matcher_with_validation(case.actual)).symbol_table for quantifier in Quantifier: arguments_constructor = arguments_building.ImplicitActualFileArgumentsConstructor( CommonArgumentsConstructor(), arguments_building. LineMatchesAssertionArgumentsConstructor( quantifier, line_matcher_symbol_name)) for expectation_type in ExpectationType: arguments = arguments_constructor.apply(expectation_type) source = test_configuration.arguments_for( arguments).as_remaining_source with self.subTest(case=case.name, expectation_type=expectation_type, quantifier=quantifier): self._check(source=source, model=model_constructor.arbitrary(self), arrangement=Arrangement(symbols=symbols), expectation=case.expected)
def execution_case_for(result: bool) -> NExArr: referenced_matcher = matchers.ConstantMatcherWithCustomTrace(mk_trace, result) return NExArr( 'matcher that gives ' + str(result), PrimAndExeExpectation.of_exe( main_result=asrt_matching_result.matches( value=asrt.equals(result), trace=trace_equals(mk_trace(result)) ) ), Arrangement( symbols=helper.logic_type_symbol_context_from_primitive(symbol_name, referenced_matcher).symbol_table ) )
def test_empty(self): # ARRANGE # checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'empty-dir') # ACT & ASSERT # check_non_full_and_full( self, fc_args.FilesCondition([]), model_constructor__non_recursive(checked_dir.path_sdv), Arrangement( tcds=checked_dir.tcds_arrangement_dir_with_contents([])), Expectation( ParseExpectation(symbol_references=asrt.is_empty_sequence), ExecutionExpectation(main_result=asrt.equals(True)), ), )
def runTest(self): for case in failing_integer_validation_cases(): with self.subTest(invalid_value=case.case_name): args_variant_constructor = InstructionArgumentsVariantConstructor( operator=comparators.NE.name, operand=case.integer_expr_string) self._check_single_expression_type( args_variant_constructor, ExpectationType.POSITIVE, model_constructor.arbitrary(self), arrangement=Arrangement(symbols=case.symbol_table), expectation=Expectation( ParseExpectation(symbol_references=case. symbol_references_expectation, ), ExecutionExpectation(validation=case.assertions, ), ))
def execution_case_for( operand_result: bool ) -> NExArr[PrimAndExeExpectation[MatcherWTrace[MODEL], MatchingResult], Arrangement]: operand_matcher = helper.logic_type_symbol_context_from_primitive( symbol_name, matchers.ConstantMatcherWithCustomTrace( mk_operand_trace, operand_result)) trace = tree.Node(logic.NOT_OPERATOR_NAME, not operand_result, (), [mk_operand_trace(operand_result)]) return NExArr( 'operand that gives ' + str(operand_result), PrimAndExeExpectation.of_exe( main_result=asrt_matching_result.matches( value=asrt.equals(not operand_result), trace=trace_equals(trace))), Arrangement(symbols=operand_matcher.symbol_table))
def failing_validation_cases(self, symbol_name: str ) -> Sequence[NExArr[PrimAndExeExpectation[MatcherWTrace[MODEL], MatchingResult], Arrangement]]: return [ NExArr( validation_case.name, expected=PrimAndExeExpectation.of_exe( validation=validation_case.expected, ), arrangement=Arrangement( symbols=self.conf.mk_logic_type_context_of_sdv( symbol_name, self.sdv_with_validation(validation_case.actual)).symbol_table ) ) for validation_case in failing_validation_cases() ]
class ExecutorOfCaseGeneratorForDirContents(ExecutorOfCaseGenerator): def execute_single(self, put: unittest.TestCase, case: SingleCaseGenerator): integration_check.CHECKER__PARSE_FULL.check( put, source=self._concrete_arguments( case.arguments()).as_remaining_source, input_=integration_check.file_in_tcds( case.model_file.location, case.model_file.name, ), arrangement=Arrangement( tcds=case.tcds_arrangement(), symbols=case.symbols(put), ), expectation=Expectation( ParseExpectation(symbol_references=asrt.matches_sequence( case.expected_symbols())), _execution_expectation_of(case.execution_result())))
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): for maybe_with_transformer_option in TRANSFORMER_OPTION_ALTERNATIVES: for maybe_full_match in FULL_MATCH_OPTION_ALTERNATIVES: with self.subTest(maybe_with_transformer_option=maybe_with_transformer_option, maybe_full_match=maybe_full_match): self._check_with_source_variants( test_configuration.arguments_for( args('{maybe_with_transformer_option} {maybe_not} {matches} {maybe_full_match} **', maybe_with_transformer_option=maybe_with_transformer_option, maybe_full_match=maybe_full_match, maybe_not=maybe_not.nothing__if_positive__not_option__if_negative)), model_constructor.empty(self), Arrangement(), Expectation( execution=ExecutionExpectation( validation=ValidationAssertions.pre_sds_fails__w_any_msg() ), ) )
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, ), ), )
def test_empty_fc(self): # ARRANGE # checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'dir-w-single-file') # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check__w_source_variants( self, args.matches_full(fc_args.FilesConditionArg.empty()).as_arguments, model_constructor__non_recursive(checked_dir.path_sdv), Arrangement( tcds=checked_dir.tcds_arrangement_dir_with_contents([ File.empty('a-file') ]) ), Expectation( ParseExpectation( symbol_references=asrt.is_empty_sequence ), exe_w_added_header_matcher(MATCHES_FULL__STRUCTURE_NAME, NON_MATCHING_EXECUTION_EXPECTATION), ), )
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): for case in failing_validation_cases(): with self.subTest(validation_case=case.name): self._check( test_configuration.source_for( args('{transformer_option} {maybe_not} {matches} .', transformer_option=case.value.transformer_arguments_string, maybe_not=maybe_not.nothing__if_positive__not_option__if_negative)), model_constructor.empty(self), Arrangement( symbols=case.value.symbol_context.symbol_table ), Expectation( ParseExpectation( symbol_references=case.value.symbol_context.references_assertion ), ExecutionExpectation( validation=case.value.expectation, ), ), )
def test_invalid_arguments_without_symbol_references(self): test_cases = [ ' {op} a'.format(op=comparators.EQ.name), '{op} 1.5'.format(op=comparators.GT.name), ] for condition_str in test_cases: with self.subTest(msg=condition_str): instr_arg = self._conf().arguments_constructor.apply( condition_str) for source in equivalent_source_variants__for_expression_parser( self, Arguments(instr_arg)): self._check( source, Arrangement(), Expectation( ParseExpectation( symbol_references=asrt.is_empty_sequence, ), ExecutionExpectation( validation=asrt_validation.ValidationAssertions .pre_sds_fails__w_any_msg(), ), ), )
def cases_for(validation_case: NEA[ValidationAssertions, ValidationActual] ) -> List[NExArr[PrimAndExeExpectation[MatcherWTrace[MODEL], MatchingResult], Arrangement]]: validations = [validation_case.actual] + ([ValidationActual.passes()] * (len(self.operands) - 1)) return [ NExArr( 'validation={}, failing_symbol={}'.format(validation_case.name, operand_name_validations[0]), PrimAndExeExpectation.of_exe( validation=validation_case.expected ), Arrangement( symbols=SymbolContext.symbol_table_of_contexts([ self.helper.conf.mk_logic_type_context_of_sdv( sym_and_validation[0], self.helper.sdv_with_validation(sym_and_validation[1])) for sym_and_validation in zip(operand_name_validations, validations) ]) ), ) for operand_name_validations in itertools.permutations(self.operands) ]
def test_recursive_model(self): # ARRANGE # file_in_sub_dir = File.empty('file-in-sub-dir') dir_in_checked_dir = Dir( 'top-level-dir', [file_in_sub_dir], ) checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'the-dir') # ACT & ASSERT # check_non_full_and_full( self, fc_args.FilesCondition([ fc_args.FileCondition(dir_in_checked_dir.name), fc_args.FileCondition(file_in_sub_dir.name), ]), model_constructor__recursive(checked_dir.path_sdv), Arrangement(tcds=checked_dir.tcds_arrangement_dir_with_contents( [dir_in_checked_dir])), Expectation( ParseExpectation(symbol_references=asrt.is_empty_sequence), ExecutionExpectation(main_result=asrt.equals(False)), ), )
def validation_exe_cases(source_dir_name: str, dst_path_symbol_name: str, ) -> Sequence[NExArr[PrimAndExeExpectation[FilesSource, pathlib.Path], Arrangement]]: return [ NExArr( 'dir_partition={}, invalid_contents={}'.format( dir_partition_case.name, invalid_contents_case.name), PrimAndExeExpectation.of_exe( validation=dir_partition_case.expectation ), Arrangement( symbols=dir_partition_case.arrangement.symbols.in_arrangement(), tcds=TcdsArrangement( tcds_contents=dir_partition_case.arrangement.populator_for_relativity_option_root__s( invalid_contents_case.value ) ) ) ) for dir_partition_case in dir_partition_cases_for_validation(dst_path_symbol_name) for invalid_contents_case in invalid_contents_cases(source_dir_name) ]
super().__init__() self._application_output = application_output def new_execution_checker(self) -> WithNodeDescriptionExecutionPropertiesChecker[MatcherWTrace, MatchingResult]: return WithNodeDescriptionExecutionPropertiesChecker( MatcherDdv, MatcherWTrace, self._application_output, ) EXPECTED_VALUE_TYPE_FOR_TEST = ValueType.LINE_MATCHER UNEXPECTED_VALUE_TYPE_FOR_TEST = ValueType.FILE_MATCHER _EMPTY_ARRANGEMENT_W_WO_TCDS = [ NameAndValue('without tcds', Arrangement()), NameAndValue('with tcds', Arrangement( tcds=TcdsArrangement())) ] IntegrationCheckerForTest = sut.IntegrationChecker[ MatcherWTrace[int], Callable[[FullResolvingEnvironment], int], MatchingResult ] def _application_result_check_cases(parser: Parser[MatcherSdv[int]], ) -> List[NameAndValue[IntegrationCheckerForTest]]: return [ NameAndValue(
def test_single_file(self): # ARRANGE # name_of_file_in_model = 'file-in-model' name_of_file_not_in_model = 'file-not-in-model' checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'dir-w-single-file') cases = [ Case( 'no file matcher - different names', fc_args.FilesCondition([ fc_args.FileCondition(name_of_file_not_in_model), ]), Arrangement( IS_REGULAR_AND_IS_DIR_MATCHER_SYMBOLS, checked_dir.tcds_arrangement_dir_with_contents( [File.empty(name_of_file_in_model)])), Expectation( ParseExpectation(symbol_references=asrt.is_empty_sequence), NON_MATCHING_EXECUTION_EXPECTATION, ), ), Case( 'same names - non-matching matcher/actual is dir', fc_args.FilesCondition([ fc_args.FileCondition( name_of_file_in_model, fm_args.SymbolReferenceWReferenceSyntax( IS_REGULAR_FILE_FILE_MATCHER.name)), ]), Arrangement( IS_REGULAR_AND_IS_DIR_MATCHER_SYMBOLS, checked_dir.tcds_arrangement_dir_with_contents( [Dir.empty(name_of_file_in_model)])), Expectation( ParseExpectation( symbol_references=asrt.matches_singleton_sequence( IS_REGULAR_FILE_FILE_MATCHER.reference_assertion)), NON_MATCHING_EXECUTION_EXPECTATION, ), ), Case( 'same names - non-matching matcher/actual is regular file', fc_args.FilesCondition([ fc_args.FileCondition( name_of_file_in_model, fm_args.SymbolReferenceWReferenceSyntax( IS_DIR_FILE_MATCHER.name)), ]), Arrangement( IS_REGULAR_AND_IS_DIR_MATCHER_SYMBOLS, checked_dir.tcds_arrangement_dir_with_contents( [File.empty(name_of_file_in_model)])), Expectation( ParseExpectation( symbol_references=asrt.matches_singleton_sequence( IS_DIR_FILE_MATCHER.reference_assertion)), NON_MATCHING_EXECUTION_EXPECTATION, ), ), ] for case in cases: with self.subTest(case.name): # ACT & ASSERT # check_non_full_and_full( self, case.files_condition, model_constructor__non_recursive(checked_dir.path_sdv), case.arrangement, case.expectation, )
def runTest(self): # ARRANGE # checked_dir = DirArgumentHelper(RelOptionType.REL_ACT, 'a-dir') fc_file_1 = 'file-1' fc_file_2 = 'file-2' file_name_not_in_fc = 'not-in-fc' unconditionally_matching_file_matcher = FileMatcherSymbolContext.of_primitive_constant( 'unconditionally_matching_file_matcher', True) unconditionally_matching_file_matcher_sym_ref_arg = fm_args.SymbolReferenceWReferenceSyntax( unconditionally_matching_file_matcher.name) unconditionally_matching_file_matcher_sym_ref_assertion = unconditionally_matching_file_matcher.reference_assertion symbol_table_with_unconditionally_matching_file_matcher = unconditionally_matching_file_matcher.symbol_table files_condition_w_2_files_cases = [ NIE( 'no file matcher', asrt.is_empty_sequence, fc_args.FilesCondition([ fc_args.FileCondition(fc_file_1), fc_args.FileCondition(fc_file_2), ]), ), NIE( 'file matcher on one file', asrt.matches_sequence([ unconditionally_matching_file_matcher_sym_ref_assertion, ]), fc_args.FilesCondition([ fc_args.FileCondition( fc_file_1, unconditionally_matching_file_matcher_sym_ref_arg), fc_args.FileCondition(fc_file_2), ]), ), NIE( 'file matcher on all files', asrt.matches_sequence([ unconditionally_matching_file_matcher_sym_ref_assertion, unconditionally_matching_file_matcher_sym_ref_assertion, ]), fc_args.FilesCondition([ fc_args.FileCondition( fc_file_1, unconditionally_matching_file_matcher_sym_ref_arg), fc_args.FileCondition( fc_file_2, unconditionally_matching_file_matcher_sym_ref_arg), ]), ), ] expectation_of_matching_giving_false = PrimAndExeExpectation.of_exe( main_result=asrt.equals(False)) model_contents_cases = [ NExArr( 'model is empty', expectation_of_matching_giving_false, Arrangement( symbols= symbol_table_with_unconditionally_matching_file_matcher, tcds=checked_dir.tcds_arrangement_dir_with_contents([])), ), NExArr( 'model contains single file with name in FILES-CONDITION', expectation_of_matching_giving_false, Arrangement( symbols= symbol_table_with_unconditionally_matching_file_matcher, tcds=checked_dir.tcds_arrangement_dir_with_contents( [File.empty(fc_file_1)])), ), NExArr( 'model contains single file with name not in FILES-CONDITION', expectation_of_matching_giving_false, Arrangement( symbols= symbol_table_with_unconditionally_matching_file_matcher, tcds=checked_dir.tcds_arrangement_dir_with_contents( [File.empty(file_name_not_in_fc)])), ), ] for files_condition_w_2_files_case in files_condition_w_2_files_cases: with self.subTest(files_condition_w_2_files_case.name): # ACT & ASSERT # check_non_full_and_full__multi( self, files_condition_w_2_files_case.input_value, symbol_references=files_condition_w_2_files_case. expected_value, model=model_constructor__non_recursive( checked_dir.path_sdv), execution=model_contents_cases, )
def test_multiple_files(self): # ARRANGE # name_of_regular_file = 'a-regular-file' name_of_dir = 'a-dir' checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'dir-w-multiple-files') arrangement = Arrangement( IS_REGULAR_AND_IS_DIR_MATCHER_SYMBOLS, checked_dir.tcds_arrangement_dir_with_contents([ File.empty(name_of_regular_file), Dir.empty(name_of_dir), ])) cases = [ Case( 'no file matchers', fc_args.FilesCondition([ fc_args.FileCondition(name_of_regular_file), fc_args.FileCondition(name_of_dir), ]), arrangement, Expectation( ParseExpectation(symbol_references=asrt.is_empty_sequence), MATCHING_EXECUTION_EXPECTATION, ), ), Case( 'with matcher on regular file', fc_args.FilesCondition([ fc_args.FileCondition( name_of_regular_file, fm_args.SymbolReferenceWReferenceSyntax( IS_REGULAR_FILE_FILE_MATCHER.name)), fc_args.FileCondition(name_of_dir), ]), arrangement, Expectation( ParseExpectation( symbol_references=asrt.matches_singleton_sequence( IS_REGULAR_FILE_FILE_MATCHER.reference_assertion)), MATCHING_EXECUTION_EXPECTATION, ), ), Case( 'with matcher on dir', fc_args.FilesCondition([ fc_args.FileCondition(name_of_regular_file), fc_args.FileCondition( name_of_dir, fm_args.SymbolReferenceWReferenceSyntax( IS_DIR_FILE_MATCHER.name)), ]), arrangement, Expectation( ParseExpectation( symbol_references=asrt.matches_singleton_sequence( IS_DIR_FILE_MATCHER.reference_assertion)), MATCHING_EXECUTION_EXPECTATION, ), ), Case( 'with matcher on both files', fc_args.FilesCondition([ fc_args.FileCondition( name_of_regular_file, fm_args.SymbolReferenceWReferenceSyntax( IS_REGULAR_FILE_FILE_MATCHER.name)), fc_args.FileCondition( name_of_dir, fm_args.SymbolReferenceWReferenceSyntax( IS_DIR_FILE_MATCHER.name)), ]), arrangement, Expectation( ParseExpectation(symbol_references=asrt.matches_sequence([ IS_REGULAR_FILE_FILE_MATCHER.reference_assertion, IS_DIR_FILE_MATCHER.reference_assertion, ])), MATCHING_EXECUTION_EXPECTATION, ), ), ] for case in cases: with self.subTest(case.name): # ACT & ASSERT # check_non_full_and_full( self, case.files_condition, model_constructor__non_recursive(checked_dir.path_sdv), case.arrangement, case.expectation, )