class TestParseInvalidSyntax(instruction_check.TestCaseBase): test_cases_with_no_negation_operator = [ '', '{type_option} file-name'.format( type_option=option_syntax(OptionName(file_properties.TYPE_INFO[FileType.REGULAR].type_argument))), '{type_option}'.format( type_option=option_syntax(OptionName(file_properties.TYPE_INFO[FileType.DIRECTORY].type_argument))), '{invalid_option} file-name'.format( invalid_option=long_option_syntax('invalidOption')), 'file-name unexpectedArgument', ] def test_raise_exception_WHEN_syntax_is_invalid(self): self._assert_each_case_raises_SingleInstructionInvalidArgumentException( self.test_cases_with_no_negation_operator) def test_raise_exception_WHEN_syntax_is_invalid_WITH_not_operator(self): test_cases_with_negation_operator = [ with_negation_argument(case_with_no_negation_operator) for case_with_no_negation_operator in self.test_cases_with_no_negation_operator ] self._assert_each_case_raises_SingleInstructionInvalidArgumentException( test_cases_with_negation_operator) def _assert_each_case_raises_SingleInstructionInvalidArgumentException(self, test_cases: list): parser = sut.Parser() for instruction_argument in test_cases: with self.subTest(instruction_argument=instruction_argument): for source in equivalent_source_variants(self, instruction_argument): with self.assertRaises(SingleInstructionInvalidArgumentException): parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
def visit_option(self, x: arg.Option) -> str: ret_val = [] ret_val.append(long_option_syntax(x.name.long)) if x.argument: ret_val.append(' ') ret_val.append(x.argument) return ''.join(ret_val)
def test_succeed_when_syntax_is_correct__with_relativity_option(self): parser = sut.Parser() for rel_option_type in sut.RELATIVITY_OPTIONS_CONFIGURATION.options.accepted_options: option_string = long_option_syntax(REL_OPTIONS_MAP[rel_option_type].option_name.long) instruction_argument = '{file_option} {rel_option} file'.format( file_option=option_syntax(parse_here_doc_or_file_ref.FILE_ARGUMENT_OPTION), rel_option=option_string) with self.subTest(msg='Argument ' + instruction_argument): for source in equivalent_source_variants__with_source_check(self, assignment_str_of(instruction_argument)): parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
def test_raise_exception_WHEN_there_is_an_initial_illegal_option(self): valid_instruction_arguments_con = args.complete_arguments_constructor( self.assertion_variant.arguments ) parser = sut.files_matcher_parser() for expectation_type in ExpectationType: etc = pfh_expectation_type_config(expectation_type) valid_instruction_arguments = valid_instruction_arguments_con.apply(etc) instruction_args_with_invalid_initial_option = '{invalid_option} {valid_arguments}'.format( invalid_option=long_option_syntax('illegalOption'), valid_arguments=valid_instruction_arguments, ) with self.subTest(arguments=instruction_args_with_invalid_initial_option, expectation_type=str(expectation_type)): for source in equivalent_source_variants(self, instruction_args_with_invalid_initial_option): with self.assertRaises(SingleInstructionInvalidArgumentException): parser.parse(source)
def runTest(self): test_cases = [ ('Invalid file ref syntax', src('{path_type} name = {invalid_option} x', invalid_option=option_syntax.long_option_syntax('invalid-option')) ), ('Superfluous arguments', src('{path_type} name = {rel_opt} x superfluous-arg', rel_opt=REL_ACT_OPTION) ), ] parser = sut.EmbryoParser() for (case_name, source_str) in test_cases: source = remaining_source(source_str) with self.subTest(msg=case_name): with self.assertRaises(SingleInstructionInvalidArgumentException): parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
def test_raise_exception_WHEN_there_is_an_initial_illegal_option(self): valid_instruction_arguments_con = args.complete_arguments_constructor( self.assertion_variant.arguments) parser = parsers().full for expectation_type in ExpectationType: etc = pfh_expectation_type_config(expectation_type) valid_instruction_arguments = valid_instruction_arguments_con.apply( etc) instruction_args_with_invalid_initial_option = '{invalid_option} {valid_arguments}'.format( invalid_option=long_option_syntax('illegalOption'), valid_arguments=valid_instruction_arguments, ) with self.subTest( arguments=instruction_args_with_invalid_initial_option, expectation_type=str(expectation_type)): for source in equivalent_source_variants( self, instruction_args_with_invalid_initial_option): with self.assertRaises( SingleInstructionInvalidArgumentException): parser.parse(source)
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): # ARRANGE # cases = [ NameAndValue('illegal option', option_syntax.long_option_syntax('this-is-an-illegal-option')), NameAndValue('illegal argument', 'this-is-an-illegal-argument'), ] parser = sut.parsers().full for case in cases: with self.subTest(case_name=case.name): source = test_configuration.source_for( args('{illegal_argument} {maybe_not} {empty}', illegal_argument=case.value, maybe_not=maybe_not.nothing__if_positive__not_option__if_negative), ) with self.assertRaises(SingleInstructionInvalidArgumentException) as cm: parser.parse(source) assert_is_single_instruction_invalid_argument_exception().apply_with_message( self, cm.exception, 'exception from parser' )
def runTest(self): # ARRANGE # cases = [ NameAndValue('illegal option', option_syntax.long_option_syntax('this-is-an-illegal-option')), NameAndValue('illegal argument', 'this-is-an-illegal-argument'), ] parser = self.configuration.new_parser() for case in cases: with self.subTest(case_name=case.name): source = self.configuration.source_for( args('{illegal_argument} {maybe_not} {empty}', illegal_argument=case.value, maybe_not=self.maybe_not.nothing__if_positive__not_option__if_negative), ) with self.assertRaises(SingleInstructionInvalidArgumentException) as cm: parser.parse(ARBITRARY_FS_LOCATION_INFO, source) assert_is_single_instruction_invalid_argument_exception().apply_with_message( self, cm.exception, 'exception from parser' )
def runTest(self): test_cases = [ NameAndValue( 'Invalid path syntax', src2(ValueType.PATH, 'name', '{invalid_option} x', invalid_option=option_syntax.long_option_syntax( 'invalid-option'))), NameAndValue( 'Superfluous arguments', src2(ValueType.PATH, 'name', '{rel_opt} x superfluous-arg', rel_opt=REL_ACT_OPTION)), NameAndValue('Missing PATH', src2(ValueType.PATH, 'name', '')), ] parser = sut.EmbryoParser() for case in test_cases: source = remaining_source(case.value) with self.subTest(msg=case.name): with self.assertRaises( SingleInstructionInvalidArgumentException): parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
def is_option(option: a.OptionName) -> TokenMatcher: return _Equals(option_syntax.long_option_syntax(option.long), True)
def __str__(self) -> str: return option_syntax.long_option_syntax(self.option_name)
from exactly_lib.definitions.test_case import phase_names from exactly_lib.help.entities.actors.objects import command_line as command_line_actor_help from exactly_lib.instructions.configuration.utils.single_arg_utils import MANDATORY_EQ_ARG from exactly_lib.section_document.element_parsers.instruction_parser_exceptions import \ SingleInstructionInvalidArgumentException from exactly_lib.test_case.actor import Actor from exactly_lib.test_case_utils.parse.shell_syntax import SHELL_KEYWORD from exactly_lib.util.cli_syntax.elements import argument as a from exactly_lib.util.cli_syntax.option_parsing import matches from exactly_lib.util.cli_syntax.option_syntax import long_option_syntax from exactly_lib.util.process_execution.command import Command from exactly_lib.util.process_execution.commands import executable_file_command, shell_command from exactly_lib.util.textformat.structure.core import ParagraphItem COMMAND_LINE_ACTOR_OPTION_NAME = a.OptionName(long_name='command') COMMAND_LINE_ACTOR_OPTION = long_option_syntax(COMMAND_LINE_ACTOR_OPTION_NAME.long) SHELL_COMMAND_INTERPRETER_ACTOR_KEYWORD = SHELL_KEYWORD SOURCE_INTERPRETER_OPTION_NAME = a.OptionName(long_name='source') SOURCE_INTERPRETER_OPTION = long_option_syntax(SOURCE_INTERPRETER_OPTION_NAME.long) FILE_INTERPRETER_OPTION_NAME = a.OptionName(long_name='file') FILE_INTERPRETER_OPTION = long_option_syntax(FILE_INTERPRETER_OPTION_NAME.long) class InstructionDocumentation(InstructionDocumentationWithTextParserBase): def __init__(self, name: str, single_line_description_un_formatted: str, main_description_rest_un_formatted: str = None): self.command_line_syntax = command_line_actor_help.ActPhaseDocumentationSyntax()
def option_string_for(option_name: argument.OptionName) -> str: return long_option_syntax(option_name.long)
def matches(option_name: OptionName, actual_argument_element: str) -> bool: option_syntax = long_option_syntax(option_name.long) return actual_argument_element == option_syntax
def visit_option(self, x: arg.Option) -> str: option_str = long_option_syntax(x.name.long) if x.argument: return option_str + ' ' + x.argument else: return option_str
def option_description(rel_opt: RelOptionType) -> str: rel_option_info = REL_OPTIONS_MAP[rel_opt] return '{} ({})'.format(rel_option_info.informative_name, long_option_syntax(rel_option_info._option_name.long))
def is_option(option: a.OptionName) -> TokenMatcher: return _Equals(option_syntax.long_option_syntax(option.long), True)
def option_description_row(rel_opt: RelOptionType) -> list: rel_option_info = REL_OPTIONS_MAP[rel_opt] return [rel_option_info.informative_name, '(' + long_option_syntax(rel_option_info._option_name.long) + ')']
EXACTLY_DIR__REL_HOME_CASE = 'EXACTLY_HOME' EXACTLY_DIR__REL_HOME_ACT = 'EXACTLY_ACT_HOME' EXACTLY_DIR__REL_ACT = 'EXACTLY_ACT' EXACTLY_DIR__REL_TMP = 'EXACTLY_TMP' EXACTLY_DIR__REL_RESULT = 'EXACTLY_RESULT' REL_TMP_OPTION_NAME = argument.OptionName(long_name='rel-tmp') REL_ACT_OPTION_NAME = argument.OptionName(long_name='rel-act') REL_RESULT_OPTION_NAME = argument.OptionName(long_name='rel-result') REL_CWD_OPTION_NAME = argument.OptionName(long_name='rel-cd') REL_HOME_CASE_OPTION_NAME = argument.OptionName(long_name='rel-home') REL_HOME_ACT_OPTION_NAME = argument.OptionName(long_name='rel-act-home') REL_SYMBOL_OPTION_NAME = argument.OptionName(long_name='rel') REL_SOURCE_FILE_DIR_OPTION_NAME = argument.OptionName('rel-here') REL_TMP_OPTION = long_option_syntax(REL_TMP_OPTION_NAME.long) REL_ACT_OPTION = long_option_syntax(REL_ACT_OPTION_NAME.long) REL_RESULT_OPTION = long_option_syntax(REL_RESULT_OPTION_NAME.long) REL_CWD_OPTION = long_option_syntax(REL_CWD_OPTION_NAME.long) REL_HOME_CASE_OPTION = long_option_syntax(REL_HOME_CASE_OPTION_NAME.long) REL_HOME_ACT_OPTION = long_option_syntax(REL_HOME_ACT_OPTION_NAME.long) REL_symbol_OPTION = long_option_syntax(REL_SYMBOL_OPTION_NAME.long) REL_source_file_dir_OPTION = long_option_syntax(REL_SOURCE_FILE_DIR_OPTION_NAME.long) HDS_DIR_DISPLAY_ORDER = ( RelHomeOptionType.REL_HOME_CASE, RelHomeOptionType.REL_HOME_ACT, ) SDS_DIR_DISPLAY_ORDER = ( RelSdsOptionType.REL_ACT,
def option(option_name: str) -> str: return option_syntax.long_option_syntax(option_name)
from exactly_lib.definitions.primitives import program, string_transformer from exactly_lib.definitions.test_case.instructions import instruction_names from exactly_lib.impls.types.string_ import syntax_elements as string_se from exactly_lib.type_val_deps.types.path import path_relativities from exactly_lib.util.cli_syntax.elements import argument from exactly_lib.util.cli_syntax.elements import argument as a from exactly_lib.util.cli_syntax.option_syntax import long_option_syntax SHELL_COMMAND_TOKEN = program.SHELL_COMMAND_TOKEN SYSTEM_PROGRAM_TOKEN = program.SYSTEM_PROGRAM_TOKEN SYMBOL_REF_PROGRAM_TOKEN = instruction_names.SYMBOL_REF_PROGRAM_INSTRUCTION_NAME EXE_FILE_REL_OPTION_ARG_CONF = path_relativities.ALL_REL_OPTIONS_ARG_CONFIG PYTHON_EXECUTABLE_OPTION_NAME = argument.OptionName(long_name='python') PYTHON_EXECUTABLE_OPTION_STRING = long_option_syntax( PYTHON_EXECUTABLE_OPTION_NAME.long) REMAINING_PART_OF_CURRENT_LINE_AS_LITERAL_MARKER = string_se.TEXT_UNTIL_EOL_MARKER EXISTING_FILE_OPTION_NAME = a.OptionName(long_name='existing-file') EXISTING_DIR_OPTION_NAME = a.OptionName(long_name='existing-dir') EXISTING_PATH_OPTION_NAME = a.OptionName(long_name='existing-path') ARGUMENT_SYNTAX_ELEMENT_NAME = a.Named('ARGUMENT') WITH_TRANSFORMED_CONTENTS_OPTION_NAME = string_transformer.WITH_TRANSFORMED_CONTENTS_OPTION_NAME STDIN_OPTION_NAME = a.OptionName(long_name='stdin')
def __str__(self) -> str: return option_syntax.long_option_syntax(self.option_name)
EXACTLY_DIR__REL_HDS_CASE = 'EXACTLY_HOME' EXACTLY_DIR__REL_HDS_ACT = 'EXACTLY_ACT_HOME' EXACTLY_DIR__REL_ACT = 'EXACTLY_ACT' EXACTLY_DIR__REL_TMP = 'EXACTLY_TMP' EXACTLY_DIR__REL_RESULT = 'EXACTLY_RESULT' REL_TMP_OPTION_NAME = argument.OptionName(long_name='rel-tmp') REL_ACT_OPTION_NAME = argument.OptionName(long_name='rel-act') REL_RESULT_OPTION_NAME = argument.OptionName(long_name='rel-result') REL_CWD_OPTION_NAME = argument.OptionName(long_name='rel-cd') REL_HDS_CASE_OPTION_NAME = argument.OptionName(long_name='rel-home') REL_HDS_ACT_OPTION_NAME = argument.OptionName(long_name='rel-act-home') REL_SYMBOL_OPTION_NAME = argument.OptionName(long_name='rel') REL_SOURCE_FILE_DIR_OPTION_NAME = argument.OptionName('rel-here') REL_TMP_OPTION = long_option_syntax(REL_TMP_OPTION_NAME.long) REL_ACT_OPTION = long_option_syntax(REL_ACT_OPTION_NAME.long) REL_RESULT_OPTION = long_option_syntax(REL_RESULT_OPTION_NAME.long) REL_CWD_OPTION = long_option_syntax(REL_CWD_OPTION_NAME.long) REL_HDS_CASE_OPTION = long_option_syntax(REL_HDS_CASE_OPTION_NAME.long) REL_HDS_ACT_OPTION = long_option_syntax(REL_HDS_ACT_OPTION_NAME.long) REL_symbol_OPTION = long_option_syntax(REL_SYMBOL_OPTION_NAME.long) REL_source_file_dir_OPTION = long_option_syntax(REL_SOURCE_FILE_DIR_OPTION_NAME.long) HDS_DIR_DISPLAY_ORDER = ( RelHdsOptionType.REL_HDS_CASE, RelHdsOptionType.REL_HDS_ACT, ) SDS_DIR_DISPLAY_ORDER = ( RelSdsOptionType.REL_ACT,
from exactly_lib.definitions.test_case.instructions import instruction_names from exactly_lib.test_case_utils.parse import parse_file_ref from exactly_lib.util.cli_syntax.elements import argument from exactly_lib.util.cli_syntax.elements import argument as a from exactly_lib.util.cli_syntax.option_syntax import long_option_syntax SHELL_COMMAND_TOKEN = instruction_names.SHELL_INSTRUCTION_NAME SYSTEM_PROGRAM_TOKEN = '%' SYMBOL_REF_PROGRAM_TOKEN = instruction_names.SYMBOL_REF_PROGRAM_INSTRUCTION_NAME REL_OPTION_ARG_CONF = parse_file_ref.ALL_REL_OPTIONS_CONFIG PYTHON_EXECUTABLE_OPTION_NAME = argument.OptionName(long_name='python') PYTHON_EXECUTABLE_OPTION_STRING = long_option_syntax(PYTHON_EXECUTABLE_OPTION_NAME.long) REMAINING_PART_OF_CURRENT_LINE_AS_LITERAL_MARKER = ':>' EXISTING_FILE_OPTION_NAME = a.OptionName(long_name='existing-file') ARGUMENT_SYNTAX_ELEMENT_NAME = a.Named('ARGUMENT')