Ejemplo n.º 1
0
 def test_raise_exception_when_syntax_is_invalid(self):
     source_cases = [
         NameAndValue(
             'empty - missing all arguments',
             CustomAbsStx.empty(),
         ),
         NameAndValue(
             'superfluous arguments',
             SequenceAbsStx.followed_by_superfluous(
                 InstructionArgumentsAbsStx(
                     DefaultRelPathAbsStx('actual.txt'),
                     StringMatcherSymbolReferenceAbsStx('STRING_MATCHER'),
                 )
             ),
         ),
         NameAndValue(
             'invalid matcher',
             SequenceAbsStx.followed_by_superfluous(
                 InstructionArgumentsAbsStx(
                     DefaultRelPathAbsStx('actual.txt'),
                     StringMatcherSymbolReferenceAbsStx(
                         NOT_A_PRIMITIVE_EXPR_NAME_AND_NOT_A_VALID_SYMBOL_NAME
                     ),
                 )
             ),
         )
     ]
     for source_case in source_cases:
         with self.subTest(source_case.name):
             PARSE_CHECKER.check_invalid_syntax__src_var_consume_last_line_abs_stx(
                 self,
                 source_case.value,
             )
Ejemplo n.º 2
0
 def test_invalid_formatting(self):
     cases = [
         NameAndValue(
             'Missing end quote (soft)',
             MISSING_END_QUOTE__SOFT
         ),
         NameAndValue(
             'Missing end quote (hard)',
             MISSING_END_QUOTE__HARD
         ),
         NameAndValue(
             'Superfluous arguments',
             CustomAbsStx.of_str('x superfluous-arg')
         ),
     ]
     for case in cases:
         syntax = DefineSymbolWMandatoryValue(
             A_VALID_SYMBOL_NAME,
             ValueType.STRING,
             case.value,
         )
         PARSE_CHECKER.check_invalid_syntax__abs_stx(
             self,
             syntax,
             sub_test_identifiers={
                 'case': case.name
             }
         )
Ejemplo n.º 3
0
 def test_failing_parse(self):
     cases = [
         NameAndValue(
             'missing argument',
             CustomAbsStx.empty(),
         ),
         NameAndValue(
             'missing end quote in file name',
             LiteralFilesSourceAbsStx([
                 abs_stx.regular_file_spec(
                     MISSING_END_QUOTE__SOFT,
                     abs_stx.FileContentsEmptyAbsStx(),
                 )
             ])
         ),
         NameAndValue(
             'superfluous arguments',
             SequenceAbsStx.followed_by_superfluous(
                 LiteralFilesSourceAbsStx([])
             ),
         ),
     ]
     # ARRANGE #
     for case in cases:
         with self.subTest(case.name):
             PARSE_CHECKER.check_invalid_syntax__abs_stx(
                 self,
                 _syntax_of(case.value)
             )
Ejemplo n.º 4
0
 def test_fail_when_missing_end_end_paren(self):
     # ARRANGE #
     valid_string = str_abs_stx.StringLiteralAbsStx('contents')
     missing_end_paren = CustomAbsStx(
         TokenSequence.concat([
             TokenSequence.singleton('('),
             valid_string.tokenization(),
         ]))
     # ACT & ASSERT #
     parse_check.checker().check_invalid_syntax__abs_stx(
         self, OptionallyOnNewLine(missing_end_paren))
Ejemplo n.º 5
0
 def test_reserved_word(self):
     for reserved_word in reserved_words.RESERVED_TOKENS:
         syntax = DefineSymbolWMandatoryValue(
             A_VALID_SYMBOL_NAME,
             ValueType.STRING,
             CustomAbsStx.of_str(reserved_word)
         )
         PARSE_CHECKER.check_invalid_syntax__abs_stx(
             self,
             syntax,
             sub_test_identifiers={
                 'reserved_word': reserved_word
             }
         )
Ejemplo n.º 6
0
 def test_invalid_syntax(self):
     syntax = CustomAbsStx(
         TokenSequence.sequence([
             here_doc.here_doc_start_token('marker'),
             '\n',
             'contents',
             '\n',
             'non_marker',
         ]))
     CHECKER.check_invalid_syntax(
         self,
         equivalent_source_variants__for_full_line_expr_parse__s__nsc,
         syntax,
     )
Ejemplo n.º 7
0
 def test_fail_when_missing_end_end_paren(self):
     # ARRANGE #
     valid_program = ProgramOfSymbolReferenceAbsStx('PROGRAM_SYMBOL')
     missing_end_paren = CustomAbsStx(
         TokenSequence.concat([
             TokenSequence.singleton('('),
             valid_program.tokenization(),
         ])
     )
     # ACT & ASSERT #
     PARSE_CHECKER.check_invalid_syntax__abs_stx(
         self,
         OptionallyOnNewLine(missing_end_paren)
     )
Ejemplo n.º 8
0
 def test_fail_if_instruction_is_not_phase_agnostic__multi(self):
     with self.assertRaises(utils.TestError):
         checker = sut.Checker(ParserThatGives(instruction_embryo_that__phase_agnostic()))
         checker.check__abs_stx__multi__std_layouts_and_source_variants(
             self.tc,
             CustomAbsStx.empty(),
             symbol_usages=asrt.is_empty_sequence,
             execution_cases=[
                 NArrEx(
                     'the one and only case',
                     Arrangement.setup_phase_aware(),
                     ExecutionExpectation.setup_phase_aware(),
                 )
             ]
         )
Ejemplo n.º 9
0
    def _check_source_and_exe_variants__failing_assertions(
            self,
            parser: embryo.InstructionEmbryoParser[T],
            arrangement: Arrangement,
            expectation: MultiSourceExpectation[T],
            sub_test_identifiers: Mapping[str, Any] = MappingProxyType({}),
    ):
        """Runs check methods for both single and multi-source.

        Source consumption is assumed to be correct (and is not tested by this method).

        :param parser: Must not consume any source.
        """
        checker = sut.Checker(ParserThatConsumesCurrentLine(parser))

        with self.subTest(zz_execution='single', **sub_test_identifiers):
            with self.assertRaises(utils.TestError):
                checker.check(self.tc,
                              remaining_source('irrelevant source'),
                              arrangement,
                              expectation.as_w_source(asrt.anything_goes()),
                              )

        with self.subTest(zz_execution='w source variants', **sub_test_identifiers):
            with self.assertRaises(utils.TestError):
                checker.check__w_source_variants(
                    self.tc,
                    'irrelevant source',
                    arrangement,
                    expectation,
                )

        with self.subTest(zz_execution='multi execution', **sub_test_identifiers):
            with self.assertRaises(utils.TestError):
                checker.check__abs_stx__multi__std_layouts_and_source_variants(
                    self.tc,
                    CustomAbsStx.of_str('irrelevant source'),
                    symbol_usages=expectation.symbol_usages,
                    execution_cases=[
                        NArrEx(
                            'the one and only case',
                            arrangement,
                            expectation,
                        ),
                    ]
                )
Ejemplo n.º 10
0
 def runTest(self):
     # ARRANGE #
     for modification_type in abs_stx.ModificationType:
         for file_type in abs_stx.FileType:
             missing_contents_file_spec = abs_stx.FileSpecAbsStx.of_file_type(
                 file_type, StringLiteralAbsStx('valid_file_name'),
                 abs_stx.CustomContentsAbsStx(
                     abs_stx.ContentsAbsStx.of_modification_type(
                         modification_type,
                         CustomAbsStx.empty(),
                     ), ))
             literal_syntax = abs_stx.LiteralFilesSourceAbsStx(
                 [missing_contents_file_spec])
             # ACT & ASSERT #
             integration_check.PARSE_CHECKER__FULL.check_invalid_syntax__abs_stx(
                 self,
                 literal_syntax,
                 sub_test_identifiers={
                     'modification_type': modification_type,
                     'file_type': file_type,
                 })
Ejemplo n.º 11
0
    def runTest(self):
        # ARRANGE #
        invalid_modification_types = [':', 2 * syntax.EXPLICIT_CREATE, 'text']

        for invalid_modification_type in invalid_modification_types:
            for file_type in abs_stx.FileType:
                missing_contents_file_spec = abs_stx.FileSpecAbsStx.of_file_type(
                    file_type, StringLiteralAbsStx('valid_file_name'),
                    abs_stx.CustomContentsAbsStx(
                        abs_stx.ContentsAbsStx.of_modification(
                            TokenSequence.singleton(invalid_modification_type),
                            CustomAbsStx.singleton(A_VALID_SYMBOL_NAME),
                        ), ))
                literal_syntax = abs_stx.LiteralFilesSourceAbsStx(
                    [missing_contents_file_spec])
                # ACT & ASSERT #
                integration_check.PARSE_CHECKER__FULL.check_invalid_syntax__abs_stx(
                    self,
                    literal_syntax,
                    sub_test_identifiers={
                        'file_type': file_type,
                        'invalid_modification_type': invalid_modification_type,
                    })
Ejemplo n.º 12
0
 def test_failing_parse(self):
     cases = [
         NameAndValue(
             'missing argument',
             CustomAbsStx.empty(),
         ),
         NameAndValue(
             'missing end quote',
             StringSourceOfStringAbsStx(MISSING_END_QUOTE__SOFT),
         ),
         NameAndValue(
             'superfluous arguments',
             SequenceAbsStx.followed_by_superfluous(
                 StringSourceOfStringAbsStx.of_str_hard('valid string')
             ),
         ),
     ]
     # ARRANGE #
     for case in cases:
         with self.subTest(case.name):
             PARSE_CHECKER.check_invalid_syntax__abs_stx(
                 self,
                 _syntax_of(case.value)
             )
Ejemplo n.º 13
0
 def test_fail_when_there_is_no_arguments(self):
     PARSE_CHECKER.check_invalid_syntax__abs_stx(self, CustomAbsStx.empty())