示例#1
0
 def as_argument_elements(self) -> ArgumentElements:
     fn = ArgumentElements([self.name])
     return (
         fn
         if self.condition is None
         else
         fn.followed_by(self.condition.as_argument_elements, [syntax.FILE_MATCHER_SEPARATOR])
     )
示例#2
0
    def test_result_of_execution_SHOULD_be_negation_of_negated_expr(self):
        # ARRANGE #
        conf = self.configuration
        helper = self._asrt_helper
        symbol_name = conf.valid_symbol_name_and_not_valid_primitive_or_operator(
        )

        mk_operand_trace = get_mk_operand_trace('the_operand')

        def execution_case_for(
            operand_result: bool
        ) -> NExArr[PrimAndExeExpectation[MatcherWTrace[MODEL],
                                          MatchingResult], Arrangement]:
            operand_matcher = helper.logic_type_symbol_context_from_primitive(
                symbol_name,
                matchers.ConstantMatcherWithCustomTrace(
                    mk_operand_trace, operand_result))
            trace = tree.Node(logic.NOT_OPERATOR_NAME, not operand_result, (),
                              [mk_operand_trace(operand_result)])
            return NExArr(
                'operand that gives ' + str(operand_result),
                PrimAndExeExpectation.of_exe(
                    main_result=asrt_matching_result.matches(
                        value=asrt.equals(not operand_result),
                        trace=trace_equals(trace))),
                Arrangement(symbols=operand_matcher.symbol_table))

        execution_cases = [
            execution_case_for(operand_result)
            for operand_result in [False, True]
        ]

        source_cases = [
            NameAndValue(
                'operand on same line',
                ArgumentElements([logic.NOT_OPERATOR_NAME, symbol_name], )),
            NameAndValue(
                'operand on following line',
                ArgumentElements([logic.NOT_OPERATOR_NAME], [
                    [symbol_name],
                ])),
        ]

        # ACT & ASSERT #

        for source_case in source_cases:
            with self.subTest(source_case.name):
                conf.checker_for_parser_of_full_expr(
                ).check_multi__w_source_variants(
                    self,
                    arguments=source_case.value.as_arguments,
                    symbol_references=asrt.matches_singleton_sequence(
                        helper.is_sym_ref_to(symbol_name)),
                    input_=conf.arbitrary_model,
                    execution=execution_cases,
                )
示例#3
0
 def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess):
     regex_lines = ['1.3',
                    '4.*6']
     here_doc_of_reg_ex = here_document_as_elements(regex_lines)
     actual_contents = lines_content(['123',
                                      '456',
                                      '789'])
     for transformer_option_arguments in TRANSFORMER_OPTION_ALTERNATIVES_ELEMENTS:
         with self.subTest(maybe_with_transformer_option=transformer_option_arguments):
             argument_elements = ArgumentElements(transformer_option_arguments +
                                                  maybe_not.empty__if_positive__not_option__if_negative +
                                                  [matcher_options.MATCHES_ARGUMENT,
                                                   FULL_MATCH_ARGUMENT]
                                                  ).followed_by(here_doc_of_reg_ex)
             self._check(
                 argument_elements.as_remaining_source,
                 model_constructor.of_str(self, actual_contents),
                 arrangement_w_tcds(),
                 Expectation(
                     ParseExpectation(
                         source=asrt_source.is_at_end_of_line(1 + len(here_doc_of_reg_ex.following_lines))
                     ),
                     ExecutionExpectation(
                         main_result=maybe_not.fail__if_positive__pass_if_negative
                     ),
                 ),
             )
示例#4
0
 def test_parse_SHOULD_fail_WHEN_operand_is_missing(self):
     arguments = ArgumentElements([
         self.configuration.
         valid_symbol_name_and_not_valid_primitive_or_operator(),
         self.operator_name
     ])
     with self.assertRaises(SingleInstructionInvalidArgumentException):
         self.configuration.parsers_for_expr_on_any_line().full.parse(
             arguments.as_remaining_source)
示例#5
0
 def runTest(self):
     # ARRANGE #
     empty_program = ArgumentElements([])
     arguments = po_ab.from_program(empty_program,
                                    matcher_arguments.emptiness_matcher())
     source = arguments.as_remaining_source
     with self.assertRaises(SingleInstructionInvalidArgumentException):
         # ACT #
         self.configuration.parser().parse(ARBITRARY_FS_LOCATION_INFO, source)
示例#6
0
def syntax_for_run(program: ArgumentElements,
                   ignore_exit_code: bool = False) -> Arguments:
    st_arguments = [string_transformer.RUN_PROGRAM]
    if ignore_exit_code:
        st_arguments.append(
            option_syntax(
                string_transformer.WITH_IGNORED_EXIT_CODE_OPTION_NAME))
    argument_elements = ArgumentElements(
        st_arguments).append_to_first_and_following_lines(program)
    return argument_elements.as_arguments
示例#7
0
def program(
    program_arg: WithToString,
    transformation: Optional[WithToString] = None,
) -> ArgumentElements:
    extra = []
    if transformation:
        extra.append([
            ab.option(string_transformer.WITH_TRANSFORMED_CONTENTS_OPTION_NAME,
                      transformation)
        ])

    return ArgumentElements([program_arg], extra)
示例#8
0
def symbol_ref_command_elements(
        symbol_name: str,
        arguments: Sequence = (),
        transformation: Optional[str] = None) -> ArgumentElements:
    first_line = [syntax_elements.SYMBOL_REF_PROGRAM_TOKEN, symbol_name
                  ] + list(arguments)

    following_lines = []

    if transformation is not None:
        following_lines.append([syntax_for_transformer_option(transformation)])

    return ArgumentElements(first_line, following_lines)
示例#9
0
    def test_expression_inside_parentheses_SHOULD_be_equal_to_expression_inside_parentheses(
            self):
        # ARRANGE #

        conf = self.configuration
        helper = self._asrt_helper

        symbol_name = conf.valid_symbol_name_and_not_valid_primitive_or_operator(
        )

        source_cases = [
            NameAndValue('expression on single line',
                         ArgumentElements(['(', symbol_name, ')'])),
            NameAndValue(
                'expression on multiple lines',
                ArgumentElements(first_line=['('],
                                 following_lines=[
                                     [symbol_name],
                                     [')'],
                                 ])),
        ]

        # ACT & ASSERT #

        for source_case in source_cases:
            with self.subTest(source_case.name):
                conf.checker_for_parser_of_full_expr(
                ).check_multi__w_source_variants(
                    self,
                    arguments=source_case.value.as_arguments,
                    symbol_references=asrt.matches_singleton_sequence(
                        helper.is_sym_ref_to(symbol_name)),
                    input_=conf.arbitrary_model,
                    execution=helper.
                    execution_cases_for_constant_reference_expressions(
                        symbol_name),
                )
示例#10
0
    def test_expression_inside_parentheses_SHOULD_be_validated(self):
        # ARRANGE #

        conf = self.configuration
        helper = self._asrt_helper

        symbol_name = conf.valid_symbol_name_and_not_valid_primitive_or_operator(
        )

        # ACT & ASSERT #

        conf.checker_for_parser_of_full_expr().check_multi__w_source_variants(
            self,
            arguments=ArgumentElements(['(', symbol_name, ')']).as_arguments,
            symbol_references=asrt.matches_singleton_sequence(
                helper.is_sym_ref_to(symbol_name)),
            input_=conf.arbitrary_model,
            execution=helper.failing_validation_cases(symbol_name),
        )
示例#11
0
    def test_disjunction_followed_by_conjunction__with_negation(self):
        # ARRANGEMENT #

        sym_a = NameAndValue('_a_',
                             matchers.ConstantMatcherWithCustomName('a', True))
        sym_b = NameAndValue(
            '_b_', matchers.ConstantMatcherWithCustomName('b', False))
        sym_c = NameAndValue('_c_',
                             matchers.ConstantMatcherWithCustomName('c', True))

        all_symbols = [sym_a, sym_b, sym_c]

        arguments = ArgumentElements([
            logic.NOT_OPERATOR_NAME,
            sym_a.name,
            logic.OR_OPERATOR_NAME,
            logic.NOT_OPERATOR_NAME,
            sym_b.name,
            logic.AND_OPERATOR_NAME,
            logic.NOT_OPERATOR_NAME,
            sym_c.name,
        ])

        expected_trace = tree.Node(logic.OR_OPERATOR_NAME, False, (), [
            tree.Node(logic.NOT_OPERATOR_NAME, False,
                      (), [sym_a.value.trace_tree]),
            tree.Node(logic.AND_OPERATOR_NAME, False, (), [
                tree.Node(logic.NOT_OPERATOR_NAME, True,
                          (), [sym_b.value.trace_tree]),
                tree.Node(logic.NOT_OPERATOR_NAME, False,
                          (), [sym_c.value.trace_tree]),
            ]),
        ])

        # ACT & ASSERT #

        self._check(
            arguments,
            False,
            all_symbols,
            expected_trace,
        )
示例#12
0
    def _check(self,
               file_type_to_check_for: FileType,
               expected_result: bool,
               base_name_of_file_to_check: str,
               dir_contents: DirContents):

        # ACT #
        integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
            self,
            ArgumentElements(arg.Type(file_type_to_check_for).elements).as_arguments,
            integration_check.constant_relative_file_name(base_name_of_file_to_check),
            arrangement_w_tcds(
                non_hds_contents=non_hds_populator.rel_option(RelNonHdsOptionType.REL_CWD, dir_contents),
            ),
            Expectation(
                execution=ExecutionExpectation(
                    main_result=asrt_matching_result.matches_value(expected_result),
                ),
            )
        )
示例#13
0
    def test_validation_SHOULD_fail_WHEN_validation_of_negated_expr_fails(
            self):
        # ARRANGE #

        conf = self.configuration
        helper = self._asrt_helper

        symbol_name = conf.valid_symbol_name_and_not_valid_primitive_or_operator(
        )

        # ACT & ASSERT #

        conf.checker_for_parser_of_full_expr().check_multi__w_source_variants(
            self,
            arguments=ArgumentElements([logic.NOT_OPERATOR_NAME,
                                        symbol_name]).as_arguments,
            symbol_references=asrt.matches_singleton_sequence(
                helper.is_sym_ref_to(symbol_name)),
            input_=conf.arbitrary_model,
            execution=helper.failing_validation_cases(symbol_name),
        )
示例#14
0
 def as_argument_elements(self) -> ArgumentElements:
     return (
         ArgumentElements(['('])
             .append_to_first_and_following_lines(self.files_condition.as_argument_elements)
             .last_line_followed_by(ArgumentElements([')']))
     )
示例#15
0
 def test_with_arguments(self):
     arg_wo_space = 'arg_wo_space'
     arg_w_space = 'an arg w space'
     arg_w_space__src = surrounded_by_soft_quotes(arg_w_space)
     string_symbol = StringConstantSymbolContext(
         'STRING_SYMBOL',
         'the string value',
         default_restrictions=asrt_rest.is__w_str_rendering(),
     )
     list_symbol = ListConstantSymbolContext(
         'LIST_SYMBOL',
         ['1st value', '2nd value'],
     )
     string_with_invalid_quoting = '"string without ending soft quote'
     arguments_cases = [
         ArgumentsCase(
             'one',
             source=ArgumentElements([arg_w_space__src]),
             expected_arguments=[arg_w_space],
         ),
         ArgumentsCase(
             'two',
             source=ArgumentElements([arg_wo_space, arg_w_space__src]),
             expected_arguments=[arg_wo_space, arg_w_space],
         ),
         ArgumentsCase(
             'string symbol reference',
             source=ArgumentElements([string_symbol.name__sym_ref_syntax]),
             expected_arguments=[string_symbol.str_value],
             symbols=[string_symbol],
         ),
         ArgumentsCase(
             'list symbol reference',
             source=ArgumentElements([list_symbol.name__sym_ref_syntax]),
             expected_arguments=list_symbol.constant_list,
             symbols=[list_symbol],
         ),
         ArgumentsCase(
             'list and string symbol reference',
             source=ArgumentElements([
                 list_symbol.name__sym_ref_syntax,
                 string_symbol.name__sym_ref_syntax
             ]),
             expected_arguments=list_symbol.constant_list +
             [string_symbol.str_value],
             symbols=[list_symbol, string_symbol],
         ),
         ArgumentsCase(
             'special program argument',
             source=program_arguments.
             remaining_part_of_current_line_as_literal(
                 string_with_invalid_quoting).as_argument_elements,
             expected_arguments=[string_with_invalid_quoting],
             symbols=[],
         ),
     ]
     # ARRANGE #
     command_cases = _single_line_command_cases()
     for command_case in command_cases:
         for arguments_case in arguments_cases:
             source_w_arguments = (
                 command_case.source.as_argument_elements.followed_by(
                     arguments_case.source).as_arguments)
             expected_arguments = asrt.matches_sequence([
                 asrt.equals(arg)
                 for arg in arguments_case.expected_arguments
             ])
             expected_command_sdv = command_case.sdv_assertion(
                 self.TCDS,
                 arguments=expected_arguments,
                 arguments_symbols=arguments_case.symbols)
             for source_case in equivalent_source_variants_for_consume_until_end_of_last_line2(
                     source_w_arguments):
                 with self.subTest(
                         command=command_case.name,
                         arguments=arguments_case.name,
                         following_source_variant=source_case.name):
                     # ACT #
                     actual = self.PARSER.parse(source_case.input_value)
                     # ASSERT #
                     source_case.expected_value.apply_with_message(
                         self, source_case.input_value, 'source')
                     expected_command_sdv.apply_with_message(
                         self, actual, 'command')
示例#16
0
 def as_argument_elements(self) -> ArgumentElements:
     return ArgumentElements(self.elements)
示例#17
0
 def as_argument_elements(self) -> ArgumentElements:
     run_primitive = ArgumentElements(
         [matcher_options.RUN_PROGRAM_ARGUMENT])
     return run_primitive.append_to_first_and_following_lines(self.program)
示例#18
0
def shell_command(command_line: WithToString) -> ArgumentElements:
    return ArgumentElements([shell_command_line(command_line)])
示例#19
0
def system_program_argument_elements(
        command_line: WithToString) -> ArgumentElements:
    return ArgumentElements(
        [syntax_elements.SYSTEM_PROGRAM_TOKEN, command_line])
示例#20
0
def interpret_py_source_elements(
        python_source: WithToString) -> ArgumentElements:
    return ArgumentElements([interpret_py_source_line(python_source)])
示例#21
0
def interpret_py_source_file_elements(
        py_file: WithToString) -> ArgumentElements:
    return ArgumentElements([interpret_py_source_file(py_file)])
示例#22
0
    def as_argument_elements(self) -> ArgumentElements:
        ret_val = ArgumentElements([syntax.LITERAL_BEGIN])
        for fc in self.files:
            ret_val = ret_val.followed_by_lines(fc.as_argument_elements.all_lines)

        return ret_val.last_line_followed_by(ArgumentElements([syntax.LITERAL_END]))
示例#23
0
 def as_argument_elements(self) -> ArgumentElements:
     return ArgumentElements([self.symbol_name])
示例#24
0
 def as_argument_elements(self) -> ArgumentElements:
     run_primitive = ArgumentElements([file_matcher.PROGRAM_MATCHER_NAME] +
                                      self.path_arg_position.arguments())
     return run_primitive.append_to_first_and_following_lines(self.program)
示例#25
0
 def as_argument_elements(self) -> ArgumentElements:
     return ArgumentElements([syntax.LITERAL_END])
示例#26
0
def parse_source_of(single_line: ArgumentElementsRenderer) -> ParseSource:
    return ArgumentElements([single_line]).as_remaining_source
示例#27
0
 def as_argument_elements(self) -> ArgumentElements:
     return ArgumentElements([symbol_reference_syntax_for_name(self.symbol_name)])