Exemple #1
0
def checker(accepted_file_relativities: RelOptionsConfiguration = ARBITRARY_FILE_RELATIVITIES
            ) -> parse_checker.Checker:
    return parse_checker.Checker(
        ParserAsLocationAwareParser(
            parse.string_source_parser(accepted_file_relativities)
        )
    )
Exemple #2
0
 def test_invalid_arguments(self):
     # ARRANGE #
     checker = parse_checker.Checker(ParserAsLocationAwareParser(sut.program_parser()))
     for case in invalid_syntax.arguments_cases():
         with self.subTest(case.name):
             syntax = RawProgramOfSymbolReferenceAbsStx(A_VALID_SYMBOL_NAME, case.value)
             checker.check_invalid_syntax__abs_stx(self, syntax)
Exemple #3
0
 def test_invalid_plain_symbol_name(self):
     # ARRANGE #
     checker = parse_checker.Checker(ParserAsLocationAwareParser(sut.program_parser()))
     for case in invalid_syntax.plain_symbol_cases():
         with self.subTest(case.name):
             syntax = RawProgramOfSymbolReferenceAbsStx(case.value)
             checker.check_invalid_syntax__abs_stx(self, syntax)
Exemple #4
0
 def runTest(self):
     # ARRANGE #
     cases = [
         NameAndValue(
             'empty source',
             RawSystemCommandLineAbsStx.of_str(''),
         ),
         NameAndValue(
             'invalid program name - broken syntax due to missing end quote',
             RawSystemCommandLineAbsStx.of_str(
                 QUOTE_CHAR_FOR_TYPE[QuoteType.SOFT] +
                 'valid_program_name'),
         ),
         NameAndValue(
             'invalid argument - broken syntax due to missing end quote',
             RawSystemCommandLineAbsStx.of_str('valid_program_name', [
                 ArgumentOfRichStringAbsStx.of_str(
                     QUOTE_CHAR_FOR_TYPE[QuoteType.SOFT] + 'argument')
             ])),
     ]
     checker = parse_checker.Checker(
         ParserAsLocationAwareParser(sut.program_parser()))
     for case in cases:
         checker.check_invalid_syntax__abs_stx(self, case.value)
Exemple #5
0
 def parse_checker(self) -> parse_checker.Checker[Instruction]:
     return parse_checker.Checker(self.parser())
Exemple #6
0
            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.environ import parse as sut
from exactly_lib.impls.instructions.multi_phase.environ.impl import Phase
from exactly_lib_test.impls.instructions.multi_phase.test_resources import instruction_embryo_check as embryo_check
from exactly_lib_test.section_document.test_resources import parse_checker

PHASE_SPECS = [
    None,
    Phase.ACT,
    Phase.NON_ACT,
]

CHECKER = embryo_check.Checker(sut.EmbryoParser(phase_is_after_act=False))

PARSE_CHECKER = parse_checker.Checker(
    sut.EmbryoParser(phase_is_after_act=False))
from exactly_lib.impls.instructions.assert_ import contents_of_file as sut
from exactly_lib_test.impls.instructions.assert_.test_resources import instruction_check
from exactly_lib_test.section_document.test_resources import parse_checker

CHECKER = instruction_check.Checker(sut.parser('the-instruction-name'))

PARSE_CHECKER = parse_checker.Checker(sut.parser('the-instruction-name'))
Exemple #9
0
        )


class InstructionAbsStx(InstructionArgsAbsStx):
    def __init__(self, value: StringSourceAbsStx):
        self._value = value

    def tokenization(self) -> TokenSequence:
        return abstract_syntaxes.AssignmentOfMandatoryValue(
            self._value).tokenization()


RELATIVITY_OPTIONS_CONFIGURATION = path_relativities.ALL_REL_OPTIONS_ARG_CONFIG

CHECKER = instruction_check.Checker(sut.Parser())
PARSE_CHECKER = parse_checker.Checker(sut.Parser())


def _stdin_is_present_and_valid(
    expected: str,
    may_depend_on_external_resources: bool,
) -> Assertion[SettingsBuilderAssertionModel]:
    return asrt_settings.stdin_is_present_and_valid(
        asrt_string_source.matches__str(
            contents=asrt.equals(expected),
            may_depend_on_external_resources=asrt.equals(
                may_depend_on_external_resources),
        ))


if __name__ == '__main__':
Exemple #10
0
 def parse_checker(self) -> parse_checker.Checker:
     return parse_checker.Checker(self.new_parser())
Exemple #11
0
class TestInvalidTransformer(unittest.TestCase):
    def runTest(self):
        # ARRANGE #
        for program_case in pgm_and_args_cases.cases__w_argument_list__including_program_reference():
            for transformer_case in invalid_syntax.transformer_cases():
                with self.subTest(program=program_case.name,
                                  transformer=transformer_case.name):
                    syntax = FullProgramAbsStx(program_case.pgm_and_args,
                                               transformation=transformer_case.value)
                    # ACT & ASSERT #
                    PARSE_CHECKER.check_invalid_syntax__abs_stx(self, syntax)


class TestInvalidStdin(unittest.TestCase):
    def runTest(self):
        # ARRANGE #
        for program_case in pgm_and_args_cases.cases__w_argument_list__including_program_reference():
            for transformer_case in invalid_syntax.stdin_cases():
                with self.subTest(program=program_case.name,
                                  transformer=transformer_case.name):
                    syntax = FullProgramAbsStx(program_case.pgm_and_args,
                                               stdin=transformer_case.value)
                    # ACT & ASSERT #
                    PARSE_CHECKER.check_invalid_syntax__abs_stx(self, syntax)


PARSE_CHECKER = parse_checker.Checker(ParserAsLocationAwareParser(sut.program_parser()))

if __name__ == '__main__':
    unittest.TextTestRunner().run(suite())
Exemple #12
0
        rel_opt.symbol_conf_rel_any(
            RelOptionType.REL_TMP, symbol_name, syntax_elements.
            EXE_FILE_REL_OPTION_ARG_CONF.options.accepted_relativity_variants),
        rel_opt.symbol_conf_rel_any(
            RelOptionType.REL_HDS_CASE, symbol_name, syntax_elements.
            EXE_FILE_REL_OPTION_ARG_CONF.options.accepted_relativity_variants),
    ]


RELATIVITY_OPTIONS = relativity_options_of_symbol(
    'EXECUTABLE_FILE_SYMBOL_NAME')

python_program_that_exits_with_code_0 = 'exit(0)'
EXECUTABLE_FILE_THAT_EXITS_WITH_CODE_0 = fs.python_executable_file(
    'executable-file', python_program_that_exits_with_code_0)

python_program_that_exits_with_code_given_as_first_cl_arg = """\
import sys

exit_code = int(sys.argv[1])

sys.exit(exit_code)

"""

PARSE_CHECKER = parse_checker.Checker(sut.embryo_parser('instruction-name'))
EXECUTION_CHECKER = embryo_check.Checker(sut.embryo_parser('instruction-name'))

if __name__ == '__main__':
    unittest.TextTestRunner().run(suite())
Exemple #13
0
from types import MappingProxyType
from typing import Mapping, Any

from exactly_lib.impls.instructions.multi_phase import new_file as sut
from exactly_lib.section_document.parse_source import ParseSource
from exactly_lib_test.section_document.test_resources import parse_checker
from exactly_lib_test.section_document.test_resources.misc import ARBITRARY_FS_LOCATION_INFO
from exactly_lib_test.test_resources.source.abstract_syntax import AbstractSyntax


def just_parse(source: ParseSource, phase_is_after_act: bool = True):
    sut.EmbryoParser(phase_is_after_act).parse(ARBITRARY_FS_LOCATION_INFO,
                                               source)


PARSE_CHECKER__BEFORE_ACT = parse_checker.Checker(sut.EmbryoParser(False))
PARSE_CHECKER__AFTER_ACT = parse_checker.Checker(sut.EmbryoParser(True))


def check_invalid_syntax(put: unittest.TestCase, source: ParseSource):
    for phase_is_after_act in [False, True]:
        checker = PARSE_CHECKERS[phase_is_after_act]
        with put.subTest(phase_is_after_act=phase_is_after_act):
            checker.check_invalid_arguments(put, source)


def check_invalid_syntax__abs_stx(
        put: unittest.TestCase,
        source: AbstractSyntax,
        sub_test_identifiers: Mapping[str, Any] = MappingProxyType({}),
):
Exemple #14
0
        self.expected_relativity_root_contents = expected_relativity_root_contents

    def sds_populator_of_root_of(self,
                                 destination_rel_opt: rel_opt_conf.RelativityOptionConfigurationForRelNonHds,
                                 contents: DirContents,
                                 ) -> sds_populator.SdsPopulator:
        return sds_populator.contents_in_resolved_dir(
            sds_populator.SdsSubDirResolverFromSdsFun(destination_rel_opt.root_dir__non_hds),
            contents,
        )


_PARSER__BEFORE_ACT = sut.EmbryoParser(False)
_PARSER__AFTER_ACT = sut.EmbryoParser(True)

_PARSE_CHECKER__BEFORE_ACT = parse_checker.Checker(_PARSER__BEFORE_ACT)
_PARSE_CHECKER__AFTER_ACT = parse_checker.Checker(_PARSER__AFTER_ACT)

_EXECUTION_CHECKER__BEFORE_ACT = instruction_embryo_check.Checker(_PARSER__BEFORE_ACT)
_EXECUTION_CHECKER__AFTER_ACT = instruction_embryo_check.Checker(_PARSER__AFTER_ACT)

_PARSERS = [
    NameAndValue('before act',
                 _PARSER__BEFORE_ACT
                 ),
    NameAndValue('after act',
                 _PARSER__AFTER_ACT
                 ),
]

_PARSE_CHECKERS = [