def test_failing_parse(self): cases = [ NameAndValue( 'missing argument', '', ), NameAndValue( 'single quoted argument', str( surrounded_by_hard_quotes( arg_syntax. arbitrary_single_line_value_that_must_not_be_quoted()) ), ), NameAndValue( 'non-transformer name that is not a valid symbol name', NOT_A_VALID_SYMBOL_NAME, ), ] # ARRANGE # defined_name = 'defined_name' parser = sut.EmbryoParser() for case in cases: with self.subTest(case.name): source = single_line_source( src2(ValueType.STRING_MATCHER, defined_name, case.value), ) with self.assertRaises( SingleInstructionInvalidArgumentException): # ACT & ASSERT # parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
def test_failing_parse(self): cases = [ NameAndValue( 'single quoted argument', str(surrounded_by_hard_quotes(NAME_MATCHER_NAME)), ), NameAndValue( 'non-selector name that is not a valid symbol name', NOT_A_VALID_SYMBOL_NAME, ), NameAndValue( 'missing matcher', '', ), ] # ARRANGE # defined_name = 'defined_name' parser = sut.EmbryoParser() for case in cases: with self.subTest(name=case.name): source = single_line_source( src2(ValueType.FILE_MATCHER, defined_name, case.value), ) with self.assertRaises( SingleInstructionInvalidArgumentException): # ACT & ASSERT # parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
def test_failing_parse(self): cases = [ NameAndValue( 'missing argument', '', ), NameAndValue( 'single quoted argument', str(surrounded_by_hard_quotes(arg_syntax.FilesCondition.empty())), ), NameAndValue( 'non-transformer name that is not a valid symbol name', NOT_A_VALID_SYMBOL_NAME, ), ] # ARRANGE # defined_name = 'defined_name' parser = sut.EmbryoParser() for case in cases: with self.subTest(case.name): source = remaining_source( src__const(ValueType.FILES_CONDITION, defined_name, case.value), ) with self.assertRaises(SingleInstructionInvalidArgumentException): # ACT & ASSERT # parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
def runTest(self): parser = sut.EmbryoParser() for (source_str, case_name) in INVALID_SYNTAX_CASES: source = remaining_source(source_str) with self.subTest(msg=case_name): with self.assertRaises( SingleInstructionInvalidArgumentException): parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
def runTest(self): parser = sut.EmbryoParser() for (source_str, case_name) in INVALID_SYNTAX_WITH_VALID_TYPE_CASES: for value_type in ValueType: type_ident = ANY_TYPE_INFO_DICT[value_type].identifier source_str = source_str.format(valid_type=type_ident, valid_value=A_VALID_SYMBOL_NAME) source = remaining_source(source_str) with self.subTest(type=type_ident, msg=case_name): with self.assertRaises( SingleInstructionInvalidArgumentException): parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
def test_assignment_of_single_constant_word(self): # ARRANGE # source = single_line_source('{string_type} name1 = v1') source_string = source.source_string parser = sut.EmbryoParser() the_file_path_rel_referrer = pathlib.Path('the-path-rel-referrer') the_file_location_info = FileLocationInfo( pathlib.Path.cwd(), the_file_path_rel_referrer, [ SourceLocation(LineSequence(10, ('line-in-inclusion-chain',)), pathlib.Path('the-path-rel-referrer-of-first-file')) ]) fs_location_info = FileSystemLocationInfo(the_file_location_info) # ACT # instruction = parser.parse(fs_location_info, source) # ASSERT # expected_source_location_path = SourceLocationPath( SourceLocation(single_line_sequence(1, source_string), the_file_path_rel_referrer), the_file_location_info.file_inclusion_chain, ) assertion = matches_source_location_info( abs_path_of_dir_containing_first_file_path=asrt.equals( the_file_location_info.abs_path_of_dir_containing_first_file_path), source_location_path=equals_source_location_path(expected_source_location_path) ) # ASSERT SANITY # assert 1 == len(instruction.symbol_usages), 'A single symbol should have been defined' symbol_definition = instruction.symbol_usages[0] assert isinstance(symbol_definition, SymbolDefinition) assertion.apply_without_message(self, symbol_definition.symbol_container.source_location)
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)
transformation= symbol_reference_followed_by_superfluous_string_on_same_line( 'TRANSFORMER_SYMBOL_NAME')) define_symbol_syntax = DefineSymbolWMandatoryValue( 'the_symbol', ValueType.PROGRAM, program_w_superfluous_stx, ) PARSE_CHECKER.check_invalid_syntax__src_var_consume_last_line_abs_stx( self, define_symbol_syntax) class TestMissingValue(unittest.TestCase): def runTest(self): # ARRANGE # program_w_superfluous_stx = CustomPgmAndArgsAbsStx( TokenSequence.empty()) define_symbol_syntax = DefineSymbolWMandatoryValue( 'the_symbol', ValueType.PROGRAM, program_w_superfluous_stx, ) PARSE_CHECKER.check_invalid_syntax__abs_stx(self, define_symbol_syntax) PARSE_CHECKER = parse_checker.Checker(sut.EmbryoParser())
from exactly_lib.impls.instructions.multi_phase.define_symbol import parser as sut from exactly_lib_test.impls.instructions.multi_phase.test_resources import \ instruction_embryo_check from exactly_lib_test.section_document.test_resources import parse_checker INSTRUCTION_CHECKER = instruction_embryo_check.Checker(sut.EmbryoParser()) PARSE_CHECKER = parse_checker.Checker(sut.EmbryoParser())