def test_differs__relativity(self): # ARRANGE # expected = PathDdvTestImpl(RelOptionType.REL_ACT, path_ddvs.constant_path_part('file-name')) actual = PathDdvTestImpl(RelOptionType.REL_HDS_CASE, path_ddvs.constant_path_part('file-name')) assertion = sut.matches_path_sdv(expected, asrt.ignore, empty_symbol_table()) # ACT & ASSERT # assert_that_assertion_fails(assertion, path_sdvs.constant(actual))
def _parent_path_suffix(path_suffix: str) -> PathPartDdv: if path_suffix == '': return path_ddvs.constant_path_part('..') (head, tail) = os.path.split(path_suffix) return path_ddvs.constant_path_part(head)
def test_differs__exists_pre_sds(self): # ARRANGE # expected = PathDdvTestImpl(_EXISTS_PRE_SDS_RELATIVITY, path_ddvs.constant_path_part('file-name')) actual = PathDdvTestImpl(_NOT_EXISTS_PRE_SDS_RELATIVITY, path_ddvs.constant_path_part('file-name')) assertion = sut.matches_path_sdv(expected, asrt.ignore, empty_symbol_table()) # ACT & ASSERT # assert_that_assertion_fails(assertion, path_sdvs.constant(actual))
def test_differs__exists_pre_sds(self): # ARRANGE # put = test_case_with_failure_exception_set_to_test_exception() expected = PathDdvTestImpl(_EXISTS_PRE_SDS_RELATIVITY, path_ddvs.constant_path_part('file-name')) actual = PathDdvTestImpl(_NOT_EXISTS_PRE_SDS_RELATIVITY, path_ddvs.constant_path_part('file-name')) # ACT & ASSERT # with put.assertRaises(TestException): sut.equals_path(expected).apply_with_message( put, actual, 'NotEquals')
def test_differs__relativity(self): # ARRANGE # put = test_case_with_failure_exception_set_to_test_exception() expected = PathDdvTestImpl(RelOptionType.REL_ACT, path_ddvs.constant_path_part('file-name')) actual = PathDdvTestImpl(RelOptionType.REL_HDS_CASE, path_ddvs.constant_path_part('file-name')) # ACT & ASSERT # with put.assertRaises(TestException): sut.equals_path(expected).apply_with_message( put, actual, 'NotEquals')
def fixed_path_parts(str_or_list) -> PathPartDdv: if isinstance(str_or_list, str): return path_ddvs.constant_path_part(str_or_list) elif isinstance(str_or_list, list): parts = str_or_list if not parts: return path_ddvs.empty_path_part() return path_ddvs.constant_path_part('/'.join(parts)) else: raise TypeError('path parts is neither a str nor a list: ', str(type(str_or_list)))
def test(self): with tmp_dir() as abs_path_of_dir_containing_last_file_base_name: fs_location_info = FileSystemLocationInfo( FileLocationInfo( abs_path_of_dir_containing_last_file_base_name)) instruction_argument = src2(ValueType.PATH, 'name', '{rel_source_file} component') for source in equivalent_source_variants__with_source_check__consume_last_line( self, instruction_argument): expected_path_sdv = path_sdvs.constant( path_ddvs.rel_abs_path( abs_path_of_dir_containing_last_file_base_name, path_ddvs.constant_path_part('component'))) expected_symbol_value = PathSymbolValueContext.of_sdv( expected_path_sdv) expected_symbol = PathSymbolContext('name', expected_symbol_value) INSTRUCTION_CHECKER.check( self, source, Arrangement.phase_agnostic( fs_location_info=fs_location_info), Expectation.phase_agnostic( symbol_usages=asrt.matches_singleton_sequence( expected_symbol.assert_matches_definition_of_sdv), symbols_after_main=assert_symbol_table_is_singleton( 'name', expected_symbol_value. assert_matches_container_of_sdv)))
def runTest(self): # ARRANGE # source_file = fs.File.empty('source-file.src') a_dir = fs.Dir.empty('a-dir') interpreter_with_program_that_is_a_dir = command_sdvs.for_executable_file( path_sdvs.constant( path_ddvs.rel_hds(relativity_configurations.INTERPRETER_FILE.relativity_option_rel_hds, path_ddvs.constant_path_part(a_dir.name))), ) command_line = source_file arrangement = arrangement_w_tcds( hds_contents=hds_populators.multiple([ relativity_configurations.ATC_FILE.populator_for_relativity_option_root__hds( fs.DirContents([source_file]) ), relativity_configurations.INTERPRETER_FILE.populator_for_relativity_option_root__hds( fs.DirContents([a_dir]) ), ]) ) expectation = Expectation( validation=ValidationExpectationSvh.fails__pre_sds() ) # ACT & ASSERT # check_execution(self, sut.actor(interpreter_with_program_that_is_a_dir), [instr([command_line.name])], arrangement, expectation)
def runTest(self): # ARRANGE # source_file = fs.File.empty('source-file.src') interpreter_with_non_existing_program_file = command_sdvs.for_executable_file( path_sdvs.constant( path_ddvs.rel_hds(relativity_configurations.INTERPRETER_FILE.relativity_option_rel_hds, path_ddvs.constant_path_part('non-existing'))), ) arrangement = arrangement_w_tcds( hds_contents=relativity_configurations.ATC_FILE.populator_for_relativity_option_root__hds( fs.DirContents([source_file]) ) ) expectation = Expectation( validation=ValidationExpectationSvh.fails__pre_sds() ) # ACT & ASSERT # check_execution(self, sut.actor(interpreter_with_non_existing_program_file), [instr([source_file.name])], arrangement, expectation)
def visit_path(self, value: PathSdv) -> PathDdv: path = value.resolve(self.symbols) suffix_str = self.suffix_sdv.resolve(self.symbols).value() if not suffix_str: return path suffix_str = suffix_str.lstrip('/') return path_ddvs.stacked(path, path_ddvs.constant_path_part(suffix_str))
def runTest(self): test_cases = [ ( 'Exists pre SDS/fixed path suffix', PathDdvTestImpl(_EXISTS_PRE_SDS_RELATIVITY, path_ddvs.constant_path_part('file-name')), ), ( 'NOT Exists pre SDS/fixed path suffix', PathDdvTestImpl(_NOT_EXISTS_PRE_SDS_RELATIVITY, path_ddvs.constant_path_part('a-file-name')), ), ] for test_case_name, ddv in test_cases: assert isinstance(ddv, PathDdv), 'Type info for IDE' with self.subTest(test_case_name): assertion = sut.equals_path(ddv) assertion.apply_without_message(self, ddv)
def description(self) -> SequenceRenderer[MinorBlock]: path_ddv = path_ddvs.of_rel_option( RelOptionType.REL_RESULT, path_ddvs.constant_path_part(self._sds.result.exitcode_file.name), ) described_path = path_ddv.value_of_any_dependency__d(self._tcds) return rend_comb.SingletonSequenceR( path_rendering.minor_block_renderer_of_primitive( described_path.describer))
def runTest(self): # ARRANGE # put = test_case_with_failure_exception_set_to_test_exception() expected = PathDdvTestImpl(RelOptionType.REL_ACT, path_ddvs.constant_path_part('name')) actual = PathDdvTestImpl(RelOptionType.REL_ACT, path_ddvs.empty_path_part()) # ACT & ASSERT # with put.assertRaises(TestException): sut.equals_path(expected).apply_with_message( put, actual, 'NotEquals')
def of_rel_opt_and_suffix( relativity: RelOptionType, suffix: str, accepted_relativities: PathRelativityVariants = ALL_REL_OPTION_VARIANTS, definition_source: Optional[ SourceLocationInfo] = ARBITRARY_LINE_SEQUENCE_FOR_DEFINITION, ) -> 'PathSymbolValueContext': return PathSymbolValueContext.of_ddv( path_ddvs.of_rel_option(relativity, path_ddvs.constant_path_part(suffix)), accepted_relativities, definition_source)
def _default( checked_file: process_output_files.ProcOutputFile ) -> ComparisonActualFileConstructor: return actual_files.ConstructorForPath( path_sdvs.of_rel_option( RelOptionType.REL_RESULT, path_ddvs.constant_path_part( process_output_files.PROC_OUTPUT_FILE_NAMES[checked_file]) ), texts.target_name_of_proc_output_file_from_act_phase(checked_file), False, )
def _just_string_argument( self, argument: str, ) -> PathSdv: argument_path = pathlib.PurePosixPath(argument) if argument_path.is_absolute(): # TODO Should we check if absolute paths are allowed according to RelOptionArgumentConfiguration?? return path_sdvs.constant(path_ddvs.absolute_file_name(argument)) path_suffix = path_ddvs.constant_path_part(argument) return path_sdvs.constant( path_ddvs.of_rel_option( self.conf.rel_opt_conf.options.default_option, path_suffix))
def visit_string(self, value: StringSdv) -> PathDdv: string_ddv = value.resolve(self.symbols) first_suffix_str = string_ddv.value_when_no_dir_dependencies() following_suffix_str = self.suffix_sdv.resolve(self.symbols).value() path_str = first_suffix_str + following_suffix_str path = pathlib.PurePosixPath(path_str) if path.is_absolute(): return path_ddvs.absolute_file_name(path_str) else: return path_ddvs.of_rel_option( self.default_relativity, path_ddvs.constant_path_part(path_str))
def test_differs__symbol_references(self): # ARRANGE # path = PathDdvTestImpl(RelOptionType.REL_ACT, path_ddvs.constant_path_part('file-name')) actual = PathSdvTestImplWithConstantPathAndSymbolReferences( path, [SymbolReference('symbol_name', ReferenceRestrictionsOnDirectAndIndirect( ArbitraryValueWStrRenderingRestriction.of_any()))]) assertion = sut.matches_path_sdv(path, asrt.matches_sequence([]), empty_symbol_table()) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_rel_tmp_with_argument(self): for is_after_act_phase in [False, True]: with self.subTest(is_after_act_phase=is_after_act_phase): arguments = format_rel_options('{rel_tmp} subdir') parser = sut.EmbryoParser( is_after_act_phase=is_after_act_phase) # ACT # actual = parser.parse(ARBITRARY_FS_LOCATION_INFO, remaining_source(arguments)) # ASSERT # expected_path = path_ddvs.of_rel_option( RelOptionType.REL_TMP, path_ddvs.constant_path_part('subdir')) assertion = matches_path_sdv(expected_path, asrt.is_empty) assertion.apply_without_message(self, actual.destination)
def test_success_when_correct_number_of_arguments__escaped(self): for is_after_act_phase in [False, True]: with self.subTest(is_after_act_phase=is_after_act_phase): arguments = '"expected argument"' parser = sut.EmbryoParser( is_after_act_phase=is_after_act_phase) # ACT # actual = parser.parse(ARBITRARY_FS_LOCATION_INFO, remaining_source(arguments)) # ASSERT # expected_path = path_ddvs.of_rel_option( RelOptionType.REL_CWD, path_ddvs.constant_path_part('expected argument')) assertion = matches_path_sdv(expected_path, asrt.is_empty) assertion.apply_without_message(self, actual.destination)
def test_no_relativity_option_should_use_default_option(self): for is_after_act_phase in [False, True]: with self.subTest(is_after_act_phase=is_after_act_phase): arguments = 'single-argument' parser = sut.EmbryoParser( is_after_act_phase=is_after_act_phase) # ACT # actual = parser.parse(ARBITRARY_FS_LOCATION_INFO, remaining_source(arguments)) # ASSERT # expected_path = path_ddvs.of_rel_option( RelOptionType.REL_CWD, path_ddvs.constant_path_part(arguments)) assertion = matches_path_sdv(expected_path, asrt.is_empty) assertion.apply_without_message(self, actual.destination)
def __init__( self, name: str, relativity: RelOptionType, suffix: str, accepted_relativities: PathRelativityVariants = ALL_REL_OPTION_VARIANTS, definition_source: Optional[ SourceLocationInfo] = ARBITRARY_LINE_SEQUENCE_FOR_DEFINITION, default_reference_variant: PathReferenceVariant = PathReferenceVariant. PATH_OR_STRING, ): self._path_part = path_ddvs.constant_path_part(suffix) super().__init__(name, path_ddvs.of_rel_option(relativity, self._path_part), accepted_relativities, definition_source, default_reference_variant) self._suffix = suffix
def cases__w_argument_list__excluding_program_reference() -> List[PgmAndArgsCase]: """Cases of pgm-and-arg:s that have a list of arguments.""" executable_file = fs.executable_file('executable-file', '') exe_file_relativity = rel_opt.conf_rel_hds(RelHdsOptionType.REL_HDS_CASE) executable_file_ddv = path_ddvs.of_rel_option(exe_file_relativity.relativity, path_ddvs.constant_path_part(executable_file.name) ) system_program = 'the-system-program' return [ PgmAndArgsCase.w_tcds( 'executable file', pgm_and_args=pgm_abs_stx.ProgramOfExecutableFileCommandLineAbsStx( exe_file_relativity.named_file_conf(executable_file.name).abstract_syntax ), expected_command_driver=lambda env: ( asrt_command.matches_executable_file_command_driver( asrt.equals(executable_file_ddv.value_of_any_dependency__d(env.tcds).primitive), )), tcds=exe_file_relativity.populator_for_relativity_option_root__hds( DirContents([executable_file]) ) ), PgmAndArgsCase.wo_tcds( '-python', pgm_and_args=pgm_abs_stx.ProgramOfPythonInterpreterAbsStx(()), expected_command_driver=prim_asrt__constant( asrt_command.matches_executable_file_command_driver( asrt_path.path_as_str(asrt.equals(sys.executable)), )), ), PgmAndArgsCase.wo_tcds( 'system program', pgm_and_args=pgm_abs_stx.ProgramOfSystemCommandLineAbsStx( StringLiteralAbsStx(system_program) ), expected_command_driver=prim_asrt__constant( asrt_command.matches_system_program_command_driver( asrt.equals(system_program) )) ), ]
def test(self): file_symbol = ConstantSuffixPathDdvSymbolContext( 'file_symbol', RelOptionType.REL_TMP, 'first_path_component') string_symbol = StringConstantSymbolContext('string_symbol', 'string symbol value') reference_of_relativity_symbol = SymbolReference( file_symbol.name, path_relativity_restriction( syntax_elements.EXE_FILE_REL_OPTION_ARG_CONF.options. accepted_relativity_variants)) reference_of_path_string_symbol_as_path_component = SymbolReference( string_symbol.name, ReferenceRestrictionsOnDirectAndIndirect( direct=value_restrictions.is_string(), indirect=value_restrictions.is_string()), ) symbols = SymbolContext.symbol_table_of_contexts([ file_symbol, string_symbol, ]) cases = [ Case.of( 'symbol references in file', RelSymbolPathAbsStx(file_symbol.name, string_symbol.name__sym_ref_syntax), arguments=(), expectation=ExpectationOnExeFile( path_ddv=path_ddvs.stacked( file_symbol.ddv, path_ddvs.constant_path_part(string_symbol.str_value)), expected_symbol_references=[ reference_of_relativity_symbol, reference_of_path_string_symbol_as_path_component ], symbol_for_value_checks=symbols, ), source_after_parse=asrt_source.is_at_end_of_line(1), ), ] for case in cases: with self.subTest(name=case.name): _parse_and_check(self, case)
def _single_line_command_cases() -> List[Case]: exe_file_name = 'executable-file' exe_file_relativity__explicit = rel_opt.conf_rel_hds( RelHdsOptionType.REL_HDS_ACT) exe_file_ddv__explicit_relativity = path_ddvs.of_rel_option( exe_file_relativity__explicit.relativity, path_ddvs.constant_path_part(exe_file_name)) exe_file_relativity__default = rel_opt.default_conf_rel_hds( RelHdsOptionType.REL_HDS_CASE) exe_file_ddv__default_relativity = path_ddvs.of_rel_option( exe_file_relativity__default.relativity, path_ddvs.constant_path_part(exe_file_name)) system_program = 'the-system-program' system_program_symbol = StringConstantSymbolContext( 'SYSTEM_PROGRAM_SYMBOL', system_program, default_restrictions=reference_assertions. IS_REFERENCE__STRING__W_ALL_INDIRECT_REFS_ARE_STRINGS, ) return [ Case( 'executable file / explicit relativity', source=pgm_args.executable_file_command_line( exe_file_relativity__explicit.named_file_conf( exe_file_name).cl_argument.as_str), expected_command_driver=lambda tcds: (asrt_command.matches_executable_file_command_driver( asrt.equals( exe_file_ddv__explicit_relativity. value_of_any_dependency__d(tcds).primitive), )), ), Case( 'executable file / default relativity', source=pgm_args.executable_file_command_line( exe_file_relativity__default.named_file_conf( exe_file_name).cl_argument.as_str), expected_command_driver=lambda tcds: (asrt_command.matches_executable_file_command_driver( asrt.equals( exe_file_ddv__default_relativity. value_of_any_dependency__d(tcds).primitive), )), ), Case( '-python', source=pgm_args.py_interpreter_command_line(), expected_command_driver=constant_assertion( asrt_command.matches_executable_file_command_driver( asrt_path.path_as_str(asrt.equals(sys.executable)), )), ), Case('system program', source=pgm_args.system_program_command_line(system_program), expected_command_driver=constant_assertion( asrt_command.matches_system_program_command_driver( asrt.equals(system_program)))), Case('system program / w symbol reference', source=pgm_args.system_program_command_line( system_program_symbol.name__sym_ref_syntax), symbols=[system_program_symbol], expected_command_driver=constant_assertion( asrt_command.matches_system_program_command_driver( asrt.equals(system_program_symbol.str_value)))), ]
def of_rel_option_with_const_file_name( rel_option: relativity_root.RelOptionType, file_name: str) -> PathSdv: return constant( path_ddvs.of_rel_option(rel_option, path_ddvs.constant_path_part(file_name)))
def ret_val(environment: FullResolvingEnvironment) -> FileMatcherModel: ddv = path_ddvs.of_rel_option(relativity, path_ddvs.constant_path_part(file_name)) return file_matcher_models.new_model__of_described( ddv.value_of_any_dependency__d(environment.tcds))
def path_of(rel_option: RelOptionType, path_suffix: str) -> PathDdv: return path_ddvs.of_rel_option(rel_option, path_ddvs.constant_path_part(path_suffix))
def all_command_driver_types() -> Sequence[CommandDriverSdvCase]: # ARRANGE # system_program_name = 'system-program' executable_program_file_name = 'executable-program-file' executable_file_relativity = relativity_options.conf_rel_any( RelOptionType.REL_HDS_ACT) executable_file_ddv = path_ddvs.of_rel_option( executable_file_relativity.relativity_option, path_ddvs.constant_path_part(executable_program_file_name)) shell_initial_command = 'shell initial command' def mk_arrangement__executable_file(symbols: SymbolTable) -> Arrangement: return arrangement_w_tcds( symbols=symbols, tcds_contents=executable_file_relativity. populator_for_relativity_option_root( fs.DirContents( [fs.executable_file(executable_program_file_name)]))) def expected_command_driver__system_program( env: AssertionResolvingEnvironment) -> Assertion[CommandDriver]: return asrt_command.matches_system_program_command_driver( asrt.equals(system_program_name)) def expected_command_driver__executable_file( env: AssertionResolvingEnvironment) -> Assertion[CommandDriver]: return asrt_command.matches_executable_file_command_driver( asrt.equals( executable_file_ddv.value_of_any_dependency__d( env.tcds).primitive), ) def expected_command_driver__shell_cmd_line( env: AssertionResolvingEnvironment) -> Assertion[CommandDriver]: return asrt_command.matches_shell_command_driver( asrt.equals(shell_initial_command)) return [ CommandDriverSdvCase( 'system program', command_driver=driver_sdvs.CommandDriverSdvForSystemProgram( string_sdvs.str_constant(system_program_name)), expected_command_driver=expected_command_driver__system_program, mk_arrangement=lambda sym_tbl: arrangement_wo_tcds(symbols=sym_tbl ), ), CommandDriverSdvCase( 'executable program file', command_driver=driver_sdvs.CommandDriverSdvForExecutableFile( path_sdvs.constant(executable_file_ddv)), expected_command_driver=expected_command_driver__executable_file, mk_arrangement=mk_arrangement__executable_file, ), CommandDriverSdvCase( 'shell command line', command_driver=driver_sdvs.CommandDriverSdvForShell( string_sdvs.str_constant(shell_initial_command)), expected_command_driver=expected_command_driver__shell_cmd_line, mk_arrangement=lambda sym_tbl: arrangement_wo_tcds(symbols=sym_tbl ), ), ]
def path_of_default_relativity(path_suffix: str) -> PathDdv: return path_ddvs.of_rel_option( syntax_elements.EXE_FILE_REL_OPTION_ARG_CONF.options.default_option, path_ddvs.constant_path_part(path_suffix))