class TestConfigurationForFile(InstructionTestConfiguration): REL_CONF__ACTUAL_FILE = rel_opt_conf.conf_rel_sds(RelSdsOptionType.REL_ACT) FILE_NAME_REL_ACT = 'actual.txt' FILE_NAME_REL_CWD = '../actual.txt' def new_parser(self) -> InstructionParser: return sut.parser('the-instruction-name') def syntax_for_matcher(self, matcher: StringMatcherAbsStx) -> AbstractSyntax: return abstract_syntax.InstructionArgumentsAbsStx( path_abs_stx.DefaultRelPathAbsStx(self.FILE_NAME_REL_CWD), matcher, ) def arrangement_for_contents(self, actual_contents: str, post_sds_population_action: TcdsAction = TcdsAction(), tcds_contents: tcds.TcdsPopulator = tcds.empty(), symbols: SymbolTable = None, ) -> instruction_check.ArrangementPostAct: return instruction_check.ArrangementPostAct( sds_contents=self._populator_for_actual(actual_contents), tcds_contents=tcds_contents, post_sds_population_action=post_sds_population_action, symbols=symbols, ) def _populator_for_actual(self, actual_contents: str) -> sds_populator.SdsPopulator: return self.REL_CONF__ACTUAL_FILE.populator_for_relativity_option_root__sds( DirContents([ File(self.FILE_NAME_REL_ACT, actual_contents) ]) )
def _new_model(self, environment: InstructionEnvironmentForPostSdsStep) -> FilesMatcherModel: rel_opt_conf = rel_opt_confs.conf_rel_sds(RelSdsOptionType.REL_RESULT) self._populate_root_dir(rel_opt_conf, environment) return models.non_recursive( rel_opt_conf.path_sdv_for_root_dir().resolve(environment.symbols) .value_of_any_dependency__d(environment.tcds), )
def test_string_transformer_should_be_parsed_as_simple_expression(self): # ARRANGE # transformation_w_infix_op = str_trans_abs_stx.StringTransformerCompositionAbsStx( [ StringTransformerSymbolReferenceAbsStx('str_trans_1'), StringTransformerSymbolReferenceAbsStx('str_trans_2'), ], within_parens=False, allow_elements_on_separate_lines=False, ) src_rel_opt_conf = conf_rel_sds(RelSdsOptionType.REL_ACT) file_contents_arg = string_source_abs_stx.TransformedStringSourceAbsStx( string_source_abs_stx.StringSourceOfFileAbsStx( src_rel_opt_conf.path_abs_stx_of_name('src-file')), transformation_w_infix_op) instruction_syntax = instr_abs_stx.create_w_explicit_contents( path_abs_stx.DefaultRelPathAbsStx('dst-file'), file_contents_arg, ) # ACT & ASSERT # check_invalid_syntax__abs_stx(self, instruction_syntax)
def test_integer_matcher_on_new_line(self): # ARRANGE # checked_dir_contents = DirContents([File.empty('1'), File.empty('2')]) checked_path = rel_opts.conf_rel_sds(RelSdsOptionType.REL_ACT) # ACT & ASSERT # integration_check.CHECKER__PARSE_SIMPLE.check( self, args.NumFiles( int_condition(comparators.EQ, len(checked_dir_contents.file_system_elements)), int_expr_on_new_line=True, ).as_remaining_source, model.model_with_rel_root_as_source_path(checked_path), arrangement_w_tcds( tcds_contents=checked_path. populator_for_relativity_option_root(checked_dir_contents), ), Expectation( ParseExpectation(source=asrt_source.is_at_end_of_line(2)), ExecutionExpectation( main_result=asrt_matching_result.matches_value(True)), ))
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 test_symbols_from_comparison_SHOULD_be_reported(self): # ARRANGE # checked_dir_contents = DirContents([File.empty('1'), File.empty('2')]) checked_path = rel_opts.conf_rel_sds(RelSdsOptionType.REL_ACT) operand_sym_ref = StringIntConstantSymbolContext( 'operand_symbol_name', len(checked_dir_contents.file_system_elements), default_restrictions=symbol_reference. is_reference_restrictions__integer_expression(), ) matcher_arguments = im_args.comparison(comparators.EQ, operand_sym_ref.argument) # ACT & ASSERT # integration_check.CHECKER__PARSE_SIMPLE.check( self, args.NumFiles( matcher_arguments.as_str, int_expr_on_new_line=True, ).as_remaining_source, model.model_with_rel_root_as_source_path(checked_path), arrangement_w_tcds( symbols=operand_sym_ref.symbol_table, tcds_contents=checked_path. populator_for_relativity_option_root(checked_dir_contents), ), Expectation( ParseExpectation( source=asrt_source.is_at_end_of_line(2), symbol_references=operand_sym_ref.references_assertion, ), ExecutionExpectation( main_result=asrt_matching_result.matches_value(True)), ))
EXPECTED_ACCEPTED_PATH_RELATIVITY_VARIANTS = PathRelativityVariants( {RelOptionType.REL_CWD, RelOptionType.REL_HDS_CASE, RelOptionType.REL_HDS_ACT, RelOptionType.REL_ACT, RelOptionType.REL_TMP}, True) ACCEPTED_REL_OPT_CONFIGURATIONS = ( list(map(rel_opt_conf.conf_rel_any, EXPECTED_ACCEPTED_PATH_RELATIVITY_VARIANTS.rel_option_types)) + [rel_opt_conf.symbol_conf_rel_any(RelOptionType.REL_TMP, 'symbol_name', EXPECTED_ACCEPTED_PATH_RELATIVITY_VARIANTS)] + [rel_opt_conf.default_conf_rel_any(RelOptionType.REL_CWD)] ) UNACCEPTED_REL_OPT_CONFIGURATIONS = [ rel_opt_conf.conf_rel_hds(RelHdsOptionType.REL_HDS_CASE), rel_opt_conf.conf_rel_sds(RelSdsOptionType.REL_RESULT), ] MAKE_CWD_OUTSIDE_OF_EVERY_REL_OPT_DIR = TcdsActionFromPlainTcdsAction( MkSubDirAndMakeItCurrentDirectory( SdsSubDirResolverFromSdsFun(lambda sds: sds.root_dir / 'test-cwd') ) ) if __name__ == '__main__': unittest.TextTestRunner().run(suite())
Dir(name_of_checked_dir, [ non_regular_file, ]), ]) ) ), expectation= Expectation( execution=ExecutionExpectation( is_hard_error=asrt.anything_goes() ), ) ) AN_ACCEPTED_SDS_REL_OPT_CONFIG = rel_opt_conf.conf_rel_sds(RelSdsOptionType.REL_TMP) class TestExistsContentsEmptyFile(unittest.TestCase): name_of_checked_dir = 'checked-dir' exists__empty__arguments = args.complete_arguments_constructor( FileQuantificationAssertionVariant( Quantifier.EXISTS, 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):
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(), ), ))
from exactly_lib_test.impls.types.test_resources.negation_argument_handling import \ ExpectationTypeConfigForNoneIsSuccess, \ expectation_type_config__non_is_success from exactly_lib_test.impls.types.test_resources.negation_argument_handling import \ PassOrFail from exactly_lib_test.impls.types.test_resources.relativity_options import RelativityOptionConfiguration, \ SymbolsConfiguration, conf_rel_sds from exactly_lib_test.section_document.test_resources.parse_source import remaining_source from exactly_lib_test.symbol.test_resources.symbols_setup import SymbolsArrEx from exactly_lib_test.tcfs.test_resources.ds_action import MkSubDirAndMakeItCurrentDirectory from exactly_lib_test.tcfs.test_resources.sds_populator import SdsSubDirResolverFromSdsFun from exactly_lib_test.test_resources.arguments.arguments_building import Arguments from exactly_lib_test.test_resources.files.file_structure import DirContents, empty_dir_contents SOME_ACCEPTED_REL_OPT_CONFIGURATIONS = [ conf_rel_sds(RelSdsOptionType.REL_ACT), conf_rel_sds(RelSdsOptionType.REL_TMP), ] class FilesMatcherArgumentsConstructorWithTemplateStringBase( FilesMatcherArgumentsConstructor, ABC): def __init__(self, matcher_argument_template: str): self.matcher_argument_template = matcher_argument_template class MatcherChecker: """ Methods for checking an instruction with arguments for negation. """
def accepted_src_file_relativities( phase_is_after_act: bool) -> Sequence[RelativityOptionConfiguration]: return (ALLOWED_SRC_FILE_RELATIVITIES__BEFORE_ACT + [conf_rel_sds(RelSdsOptionType.REL_RESULT)] if phase_is_after_act else ALLOWED_SRC_FILE_RELATIVITIES__BEFORE_ACT)