def test_destination_already_exists_in_destination_directory(self): src = 'src-file-name' dst = 'dst-dir-name' home_dir_contents = DirContents([(File.empty(src))]) cwd_dir_contents = DirContents([Dir(dst, [File.empty(src)])]) for parser_case in _EXECUTION_CHECKERS: with self.subTest(parser=parser_case.name): # ACT & ASSERT # parser_case.value.check( self, args.copy( defs.DEFAULT_SRC_REL_OPT.path_argument_of_rel_name(src), defs.DEFAULT_DST_REL_OPT.path_argument_of_rel_name(dst) ).as_remaining_source, Arrangement.phase_agnostic( tcds=TcdsArrangement( pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY, hds_contents=defs.DEFAULT_SRC_REL_OPT.populator_for_relativity_option_root__hds( home_dir_contents), sds_contents=defs.DEFAULT_DST_REL_OPT.populator_for_relativity_option_root__sds( cwd_dir_contents ), ) ), Expectation.phase_agnostic( main_result=asrt_text_doc.is_any_text(), ), )
class SelectorShouldBeApplied(MultipleExecutionCasesGenerator): min_depth = 1 max_depth = 1 num_regular_files_eq_1 = [ Dir('lvl0', [ File.empty('lvl1-included'), Dir('lvl1-not-included', [ File.empty('lvl2-not-included-file'), Dir.empty('lvl2-not-included-dir'), ]) ]) ] num_regular_files_eq_2 = [ Dir('lvl0', [ File.empty('lvl1-included-1'), File.empty('lvl1-included-2'), Dir('lvl1-not-included', [ File.empty('lvl2-not-included-file'), Dir.empty('lvl2-not-included-dir'), ]) ]) ] num_files_setup = NumFilesSetup(comparators.EQ, 2, [ NEA( 'not match', False, num_regular_files_eq_1, ), NEA( 'match', True, num_regular_files_eq_2, ), ]) def arguments(self) -> FileMatcherArg: return _as_arguments( RecWLimArguments( fms_args.Selection(fm_args.Type(FileType.REGULAR), self.num_files_setup.num_files_arg()), self.min_depth, self.max_depth, )) def expected_symbols(self) -> Sequence[Assertion[SymbolReference]]: return () 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 test_directory(self): dir_to_check = 'dir-to-check' cases = [ NEA('match', True, DirContents([Dir.empty(dir_to_check)]), ), NEA('match: symlink to directory', True, DirContents([Dir.empty('the dir'), sym_link(dir_to_check, 'the dir')]), ), NEA('not match: actual is regular', False, DirContents([File.empty(dir_to_check)]), ), NEA('not match: actual is broken symlink', False, DirContents([File.empty('the file.txt'), sym_link(dir_to_check, 'name-of-non-existing-file')]), ), ] for case in cases: with self.subTest(case_name=case.name): self._check(file_type_to_check_for=FileType.DIRECTORY, expected_result=case.expected, base_name_of_file_to_check=dir_to_check, dir_contents=case.actual)
def test_symlink(self): link_target = 'link-target-file' file_to_check = 'file-to-check' cases = [ NEA('match: symlink to regular', True, DirContents([File.empty(link_target), sym_link(file_to_check, link_target)]), ), NEA('match: symlink to directory', True, DirContents([Dir.empty(link_target), sym_link(file_to_check, link_target)]), ), NEA('match: broken symlink', True, DirContents([sym_link(file_to_check, 'non-existing-target-file')]), ), NEA('not match: actual is regular', False, DirContents([File.empty(file_to_check)]), ), ] for case in cases: with self.subTest(case_name=case.name): self._check(file_type_to_check_for=FileType.SYMLINK, expected_result=case.expected, base_name_of_file_to_check=file_to_check, dir_contents=case.actual)
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 file_structure(self, root_path: pathlib.Path) -> DirContents: return DirContents([ File('main.suite', lines_content(['[suites]', '?'])), File.empty('1'), Dir('2', []), File.empty('3'), ])
def file_structure(self, root_path: pathlib.Path) -> DirContents: return DirContents([ File('main.suite', lines_content(['[cases]', '_[!a-bx].case'])), File.empty('_b.case'), File.empty('_x.case'), File.empty('_a.case'), File.empty('_c.case'), ])
def test_all_files_in_dir_WHEN_argument_is_glob_including_all_files(self): file_1 = File.empty('1-file.ext') file_2 = File.empty('2-file.ext') self._expect_success(contents_dir_contents=DirContents( [file_1, file_2]), source='*', expected_contents_rel_contents_dir=[ file_1.name_as_path, file_2.name_as_path, ])
def file_structure_to_read(self, root_path: pathlib.Path) -> DirContents: return DirContents([ File( 'main.suite', lines_content([ section_names.CASES.syntax, '1.case', 'sub/2.case', ])), File.empty('1.case'), Dir('sub', [File.empty('2.case')]) ])
def file_structure_to_read(self, root_path: pathlib.Path) -> DirContents: return DirContents([ File( 'main.suite', lines_content([ section_names.SUITES.syntax, str(root_path / '1.suite'), section_names.CASES.syntax, str(root_path / '1.case'), ])), File.empty('1.suite'), File.empty('1.case'), ])
def test_WHEN_multiple_selectors_THEN_selection_SHOULD_be_conjunction_of_selectors( self): # ARRANGE # prefix_to_include = 'A' file_type_to_include = FileType.DIRECTORY name = prefix_to_include + '-matching-base-name' file_name = prefix_to_include + '-matching-base-name--file' name1 = prefix_to_include + 'dir-in-dir-matching-base-name' name2 = prefix_to_include + '-matching-base-name--dir-in-dir' name3 = prefix_to_include + '-matching-base-name' name4 = prefix_to_include + '-matching-base-name--empty-dir' actual_cases = [ NameAndValue( 'empty', [], ), NameAndValue( 'single regular file that matches on base name', [File.empty(name)], ), NameAndValue( 'single dir that matches on base name', [Dir.empty(name3)], ), NameAndValue( 'single dir that not matches on base name', [Dir.empty('non-matching-base-name')], ), NameAndValue('directories with contents - one level', [ File.empty(file_name), Dir.empty(name4), Dir('non-matching-name-non-empty-dir', [ File.empty('file-in-dir'), Dir.empty(name1), ]), Dir(prefix_to_include + '-matching-base-name--non-empty-dir', [ File.empty('file-in-dir'), Dir.empty(name2), ]), ]), ] cases = test_data.strip_file_type_info_s( test_data.filter_on_file_type( file_type_to_include, test_data.filter_on_base_name_prefix(prefix_to_include, [ test_data.expected_is_direct_contents_of_actual( case.name, case.value) for case in actual_cases ])))
def test_all_files_in_dir_WHEN_argument_is_glob_including_all_files_and_dir_contains_default_suite_file(self): file_1 = File.empty('1-file.ext') dir_2 = Dir('2-dir', [ File.empty(file_names.DEFAULT_SUITE_FILE) ]) self._expect_success( contents_dir_contents=DirContents([file_1, dir_2]), source='*', expected_contents_rel_contents_dir=[ file_1.name_as_path, dir_2.name_as_path / file_names.DEFAULT_SUITE_FILE, ] )
def file_structure(self, root_path: pathlib.Path) -> DirContents: return DirContents([ File( 'main.suite', lines_content( ['[cases]', 'sub-dir-1/?.case', 'sub-dir-2/*.case'])), Dir('sub-dir-1', [ File.empty('b.case'), File.empty('a.case'), ]), Dir('sub-dir-2', [ File.empty('22.case'), File.empty('11.case'), ]), ])
def test_validate_should_fail_when_executable_does_not_exist(self): existing_file_to_interpret = 'existing-file-to-interpret.src' home_dir_contents = fs.DirContents( [File.empty(existing_file_to_interpret)]) for relativity_option_conf in RELATIVITY_OPTIONS: argument = '{relativity_option} non-existing-file {interpret_option}' \ ' {rel_hds_case_option} {existing_file}'.format( relativity_option=relativity_option_conf.option_argument, interpret_option=syntax_elements.EXISTING_FILE_OPTION_NAME, rel_hds_case_option=REL_HDS_CASE_OPTION, existing_file=existing_file_to_interpret, ) expectation = _expect_validation_error_and_symbol_usages_of( relativity_option_conf) arrangement = Arrangement.phase_agnostic( symbols=relativity_option_conf.symbols.in_arrangement(), tcds=TcdsArrangement( hds_contents=hds_case_dir_contents(home_dir_contents), ), ) with self.subTest(msg='option=' + relativity_option_conf.test_case_description): EXECUTION_CHECKER.check__w_source_variants( self, argument, arrangement, expectation)
def test_argument_is_file(self): self._check_argument( 'existing-file', sds_test.Arrangement(sds_contents_before=contents_in( RelSdsOptionType.REL_ACT, DirContents([File.empty('existing-file')]))), sds_test.Expectation(expected_action_result=is_failure()))
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 dir_with_symlink_to_existing_file() -> pathlib.Path: with tmp_dir( DirContents([ File.empty('existing-file'), sym_link('existing-symlink', 'existing-file') ])) as dir_path: yield dir_path / 'existing-symlink'
def test_file_exists(self): # ARRANGE # file_name = 'existing-file' instruction_argument_constructor = ArgumentsConstructorWithFileMatcher(file_name) cases_with_existing_file_of_different_types = [ NameAndValue( 'dir', DirContents([Dir.empty(file_name)])), NameAndValue( 'regular file', DirContents([File.empty(file_name)])), NameAndValue( 'sym-link', DirContents( [Dir.empty('directory'), Link(file_name, 'directory')]) ), NameAndValue( 'broken sym-link', DirContents( [Link(file_name, 'non-existing-target-file')]) ), ] self.checker.check_multiple_cases_with_rel_opt_variants_and_expectation_type_variants( cases_with_existing_file_of_different_types, instruction_argument_constructor, main_result_for_positive_expectation=PassOrFail.PASS, )
def runTest(self): # ARRANGE # expected_file_name = 'quoted file name.src' act_phase_instructions = [instr([str(surrounded_by_hard_quotes(expected_file_name))]), instr([''])] executor_that_records_arguments = CommandExecutorThatRecordsArguments() arrangement = integration_check.arrangement_w_tcds( hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, DirContents([ File.empty(expected_file_name)])), process_execution=ProcessExecutionArrangement( os_services=os_services_access.new_for_cmd_exe(executor_that_records_arguments) ) ) expectation = integration_check.Expectation() # ACT # integration_check.check_execution(self, ACTOR_THAT_RUNS_PYTHON_PROGRAM_FILE, act_phase_instructions, arrangement, expectation) # ASSERT # expected_command = asrt_command.matches_command( driver=asrt_command.matches_executable_file_command_driver(asrt.anything_goes()), arguments=asrt.matches_sequence([ asrt_path.str_as_path(asrt_path.name_equals(expected_file_name)) ]) ) expected_command.apply_with_message( self, executor_that_records_arguments.command, 'command', )
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 runTest(self): checked_file = File.empty('checked-file.txt') string_matcher = StringMatcherSymbolContextOfPrimitiveConstant( 'STRING_MATCHER', True, ) after_bin_op = 'after bin op' integration_check.CHECKER__PARSE_SIMPLE.check( self, source=fm_args.FileContents( sm_args2.conjunction([ sm_args2.SymbolReference(string_matcher.name), sm_args2.Custom(after_bin_op), ]), ).as_remaining_source, input_=integration_check.constant_relative_file_name( checked_file.name), arrangement=arrangement_w_tcds( symbols=string_matcher.symbol_table, tcds_contents=tcds_populators.in_tc_dir( RelOptionType.REL_ACT, DirContents([checked_file]))), expectation=Expectation( ParseExpectation( source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=logic.AND_OPERATOR_NAME + ' ' + after_bin_op), symbol_references=string_matcher.references_assertion), ExecutionExpectation( main_result=asrt_matching_result.matches_value( string_matcher.result_value))), )
def test_single_file_in_root_dir(self): # ARRANGE # expected_file = File.empty('file-name.txt') for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) for rel_opt_conf in ALLOWED_DST_FILE_RELATIVITIES: with self.subTest( relativity_option_string=rel_opt_conf.option_argument, phase_is_after_act=phase_is_after_act): instruction_syntax = abs_stx.without_contents( rel_opt_conf.path_abs_stx_of_name(expected_file.name)) # ACT & ASSERT # checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic(tcds=TcdsArrangement( pre_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ), ), MultiSourceExpectation.phase_agnostic( main_result=IS_SUCCESS, side_effects_on_hds=f_asrt.dir_is_empty(), symbol_usages=asrt.is_empty_sequence, main_side_effects_on_sds= non_hds_dir_contains_exactly( rel_opt_conf.root_dir__non_hds, fs.DirContents([expected_file])), ))
def test_single_file_WHEN_argument_is_existing_single_file(self): file = File.empty('suite.file') self._expect_success(contents_dir_contents=DirContents([file]), source=file.name, expected_contents_rel_contents_dir=[ file.name_as_path, ])
def runTest(self): file_name = 'existing-plain-file' self._check( syntax_for_assignment_of(file_name), Arrangement( root_dir_contents=DirContents([File.empty(file_name)])), Expectation(main_result=svh_assertions.is_validation_error()))
def test_fail_WHEN_actor_argument_is_empty(self): empty_suite_file = File.empty('test.suite') self._expect_raise_argument_parsing_error( cwd_contents=DirContents([empty_suite_file]), arguments=[ common_cli_options.OPTION_FOR_ACTOR, '', empty_suite_file.name ])
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 test_succeed_WHEN_file_argument_do_exit(self): existing_file = File.empty('existing-file.ext') self._expect_successful_parse( cwd_contents=DirContents([existing_file]), arguments=[existing_file.name], expected_file_path=existing_file.name_as_path, )
def _file_contents_cases(self) -> InvalidDestinationFileTestCasesData: arbitrary_transformer = StringTransformerSymbolContext.of_primitive( 'TRANSFORMER_SYMBOL', string_transformers.to_uppercase(), ) symbols = arbitrary_transformer.symbol_table relativity_conf = conf_rel_hds(RelHdsOptionType.REL_HDS_CASE) src_file = relativity_conf.path_abs_stx_of_name('src-file.txt') contents_abs_stx_builder = string_source_abs_stx.TransformableAbsStxBuilder( string_source_abs_stx.StringSourceOfFileAbsStx(src_file)) src_file_in_hds_contents = relativity_conf.populator_for_relativity_option_root( DirContents([File.empty(src_file.name)])) file_contents_cases = [ NameAndValue( 'contents of existing file / without transformation', fs_abs_stx.FileContentsExplicitAbsStx( fs_abs_stx.ModificationType.CREATE, contents_abs_stx_builder.without_transformation())), NameAndValue( 'contents of existing file / with transformation', fs_abs_stx.FileContentsExplicitAbsStx( fs_abs_stx.ModificationType.CREATE, contents_abs_stx_builder.with_transformation( arbitrary_transformer.abstract_syntax))), ] return InvalidDestinationFileTestCasesData(file_contents_cases, symbols, src_file_in_hds_contents)
def runTest(self): self.conf.run_single_line_test_with_source_variants_and_source_check( self, 'file', self.conf. arrangement(sds_contents_before_main=sds_populator.contents_in( RelSdsOptionType.REL_ACT, DirContents([File.empty('file')]))), self.conf.expect_target_is_not_a_directory())
def test_destination_already_exists__without_explicit_destination(self): # ARRANGE # file_name = 'existing-file' file_to_install = DirContents([(File(file_name, 'contents'))]) for parser_case in _EXECUTION_CHECKERS: with self.subTest(parser=parser_case.name): # ACT & ASSERT # parser_case.value.check( self, args.copy( defs.DEFAULT_SRC_REL_OPT.path_argument_of_rel_name(file_name) ).as_remaining_source, Arrangement.phase_agnostic( tcds=TcdsArrangement( pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY, hds_contents=defs.DEFAULT_SRC_REL_OPT.populator_for_relativity_option_root__hds( file_to_install), sds_contents=defs.DEFAULT_DST_REL_OPT.populator_for_relativity_option_root__sds( DirContents([File.empty(file_name)]) ), ) ), Expectation.phase_agnostic_2( main_result=asrt_text_doc.is_any_text(), ) )