Esempio n. 1
0
    def runTest(self):
        # ARRANGE #
        checked_dir = Dir.empty('the-checked-dir')

        fsm_1 = FilesMatcherSymbolContextOfPrimitiveConstant('fsm_1', True)
        fsm_2 = FilesMatcherSymbolContextOfPrimitiveConstant('fsm_2', False)
        symbols = [fsm_1, fsm_2]

        rel_conf = rel_opt_conf.conf_rel_any(RelOptionType.REL_ACT)

        arguments = args.recursive(
            rel_conf.path_argument_of_rel_name(checked_dir.name),
            fsm_args.disjunction([fsm_1.argument, fsm_2.argument]),
        )
        is_pass = fsm_1.result_value or fsm_2.result_value
        # ACT # & ASSERT #
        INSTRUCTION_CHECKER.check_2(
            self, arguments.as_remaining_source,
            ArrangementPostAct2(
                symbols=SymbolContext.symbol_table_of_contexts(symbols),
                tcds=TcdsArrangementPostAct(
                    tcds_contents=rel_conf.
                    populator_for_relativity_option_root(
                        DirContents([checked_dir])))),
            Expectation2(
                ParseExpectation(
                    source=asrt_source.source_is_at_end,
                    symbol_usages=SymbolContext.usages_assertion_of_contexts(
                        symbols),
                ),
                ExecutionExpectation(
                    main_result=asrt_pfh.is_non_hard_error(is_pass), ),
            ))
 def runTest(self):
     # ARRANGE #
     sm_1 = StringMatcherSymbolContextOfPrimitiveConstant('sm_1', True)
     sm_2 = StringMatcherSymbolContextOfPrimitiveConstant('sm_2', False)
     symbols = [sm_1, sm_2]
     matcher_syntax = StringMatcherInfixOpAbsStx.disjunction([
         sm_1.abstract_syntax,
         sm_2.abstract_syntax,
     ])
     is_pass = sm_1.result_value or sm_2.result_value
     # ACT & ASSERT #
     self.configuration.checker.check__abs_stx__source_variants(
         self, self.configuration.syntax_for_matcher(matcher_syntax),
         self.configuration.arrangement_for_contents(
             actual_contents='',
             symbols=SymbolContext.symbol_table_of_contexts(symbols),
             post_sds_population_action=
             MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY,
         ).as_arrangement_2(),
         MultiSourceExpectation(
             symbol_usages=SymbolContext.usages_assertion_of_contexts(
                 symbols),
             execution=ExecutionExpectation(
                 main_result=asrt_pfh.is_non_hard_error(is_pass), ),
         ))
Esempio n. 3
0
    def test_stdin_is_concatenation_of_string_sources_WHEN_program_defines_multiple_stdin(
            self):
        # ARRANGE #
        test_setup = MultipleStdinOfProgramTestSetup(self, exit_code=0)
        all_symbols = [
            test_setup.program_symbol, CONST_TRUE_INT_MATCHER_SYMBOL
        ]

        # ACT & ASSERT #
        CHECKER.check__abs_stx__source_variants(
            self,
            InstructionArguments(
                test_setup.program_w_stdin_syntax,
                CONST_TRUE_INT_MATCHER_SYMBOL.abstract_syntax,
            ),
            ArrangementPostAct2(
                symbols=SymbolContext.symbol_table_of_contexts(all_symbols),
                process_execution=test_setup.proc_exe_env__w_stdin_check,
            ),
            MultiSourceExpectation(
                symbol_usages=SymbolContext.usages_assertion_of_contexts(
                    all_symbols),
                execution=ExecutionExpectation(main_result=asrt_pfh.is_pass()),
            ),
        )
Esempio n. 4
0
def _execution_expectation_of(
        expected: ExecutionResult) -> ExecutionExpectation:
    if isinstance(expected, FullExecutionResult):
        return ExecutionExpectation(
            main_result=asrt_pfh.is_non_hard_error(expected.is_match))
    elif isinstance(expected, ValidationFailure):
        return ExecutionExpectation(
            validation_pre_sds=_mk_validation_assertion(
                expected.expectation.passes_pre_sds),
            validation_post_sds=_mk_validation_assertion(
                expected.expectation.passes_post_sds),
        )
    raise ValueError('Unknown {}: {}'.format(
        str(type(ExecutionResult)),
        expected,
    ))
Esempio n. 5
0
    def test_stdin_is_contents_of_string_source_WHEN_program_defines_single_stdin(
            self):
        # ARRANGE #
        test_setup = SingleStdinOfProgramTestSetup(self, exit_code=0)

        for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(
        ):
            all_symbols = list(
                pgm_and_args_case.symbols) + [CONST_TRUE_INT_MATCHER_SYMBOL]
            with self.subTest(pgm_and_args_case.name):
                # ACT & ASSERT #
                CHECKER.check__abs_stx__source_variants(
                    self,
                    InstructionArguments(
                        test_setup.program_w_stdin_syntax(
                            pgm_and_args_case.pgm_and_args),
                        CONST_TRUE_INT_MATCHER_SYMBOL.abstract_syntax,
                    ),
                    ArrangementPostAct2(
                        symbols=SymbolContext.symbol_table_of_contexts(
                            all_symbols),
                        process_execution=test_setup.
                        proc_exe_env__w_stdin_check,
                        tcds=TcdsArrangementPostAct(
                            tcds_contents=pgm_and_args_case.tcds, ),
                    ),
                    MultiSourceExpectation(
                        symbol_usages=SymbolContext.
                        usages_assertion_of_contexts(all_symbols),
                        execution=ExecutionExpectation(
                            main_result=asrt_pfh.is_pass()),
                    ),
                )
Esempio n. 6
0
 def test_invalid_arguments_with_symbol_references(self):
     symbol_name = SymbolWithReferenceSyntax('symbol_name')
     operand_arg_with_symbol_ref_list = [
         IntegerMatcherComparisonAbsStx.of_cmp_op(
             comparators.EQ,
             StringSymbolAbsStx(symbol_name.name),
         ),
     ]
     invalid_symbol_values = [
         'not_a_number',
         '1.5',
         '72 87',
     ]
     for invalid_symbol_value in invalid_symbol_values:
         symbol = StringConstantSymbolContext(symbol_name.name,
                                              invalid_symbol_value)
         for operand_arg_with_symbol_ref in operand_arg_with_symbol_ref_list:
             full_syntax = self._conf().arguments_constructor.apply(
                 operand_arg_with_symbol_ref)
             with self.subTest(argument=full_syntax.as_str__default(),
                               invalid_symbol_value=invalid_symbol_value):
                 self._check(
                     full_syntax,
                     ArrangementPostAct2(symbols=symbol.symbol_table),
                     MultiSourceExpectation(
                         symbol_usages=asrt.matches_sequence([
                             symbol.
                             reference_assertion__string__w_all_indirect_refs_are_strings
                         ]),
                         execution=ExecutionExpectation(
                             validation_pre_sds=svh_asrt.
                             is_validation_error(), ),
                     ),
                 )
Esempio n. 7
0
    def runTest(self):
        file_in_root = File.empty('file-in-root.txt')
        files_in_root_dir = [file_in_root]

        file_matcher_symbol = FileMatcherSymbolContext.of_primitive_constant(
            'FILE_MATCHER_SYMBOL',
            True,
        )

        file_matcher_cases = [
            NInpArr(
                'wo file matcher',
                None,
                (),
            ),
            NInpArr(
                'w file matcher',
                file_matcher_symbol.abstract_syntax,
                [file_matcher_symbol],
            ),
        ]
        relativity_cases = [
            rel_opt_conf.conf_rel_any(RelOptionType.REL_TMP),
            rel_opt_conf.conf_rel_any(RelOptionType.REL_HDS_CASE),
        ]

        for expectation_type in ExpectationType:
            for file_matcher_case in file_matcher_cases:
                for rel_conf in relativity_cases:
                    with self.subTest(relativity=rel_conf.relativity,
                                      file_matcher=file_matcher_case.name,
                                      expectation_type=expectation_type):
                        CHECKER.check__abs_stx__source_variants(
                            self,
                            InstructionArguments(
                                rel_conf.path_abs_stx_of_name__c([
                                    file_in_root.name,
                                    'path-to-check'
                                ]),
                                expectation_type=expectation_type,
                                file_matcher=file_matcher_case.input,
                            ),
                            ArrangementPostAct2(
                                symbols=SymbolContext.symbol_table_of_contexts(file_matcher_case.arrangement),
                                tcds=TcdsArrangementPostAct(
                                    tcds_contents=rel_conf.populator_for_relativity_option_root(
                                        DirContents(files_in_root_dir)
                                    )
                                )
                            ),
                            MultiSourceExpectation(
                                symbol_usages=SymbolContext.usages_assertion_of_contexts(file_matcher_case.arrangement),
                                execution=ExecutionExpectation(
                                    main_result=pfh_assertions.is_pass_of_fail(
                                        expectation_type is ExpectationType.NEGATIVE
                                    )
                                )
                            )
                        )
Esempio n. 8
0
    def runTest(self):
        # ARRANGE #

        files_matcher_name = 'the_files_matcher'
        checked_dir_location = RelOptionType.REL_ACT
        checked_dir = Dir.empty('checked-dir')

        matcher_argument = SymbolReferenceArgument(files_matcher_name).as_str

        tcds = TcdsArrangementPostAct(
            TcdsPopulatorForRelOptionType(checked_dir_location,
                                          DirContents([checked_dir])))

        source_cases = [
            NameAndValue(
                'All arguments on separate lines',
                Arguments(checked_dir.name, [
                    reserved_words.COLON, args.RECURSION_OPTION_STR,
                    matcher_argument
                ]),
            ),
            NameAndValue(
                'Empty lines between arguments',
                Arguments(checked_dir.name, [
                    '',
                    reserved_words.COLON,
                    '',
                    args.RECURSION_OPTION_STR,
                    '',
                    matcher_argument,
                ]),
            ),
        ]

        execution_cases = [
            NExArr(
                'matcher gives ' + str(matcher_result),
                ExecutionExpectation(
                    main_result=asrt_pfh.is_non_hard_error(matcher_result)),
                ArrangementPostAct2(
                    tcds,
                    symbols=FilesMatcherSymbolContext.of_primitive_constant(
                        files_matcher_name, matcher_result).symbol_table))
            for matcher_result in [False, True]
        ]
        # ACT & ASSERT #

        for source_case in source_cases:
            with self.subTest(source_case=source_case.name):
                INSTRUCTION_CHECKER.check_multi__with_source_variants(
                    self,
                    SourceArrangement.new_w_arbitrary_fs_location(
                        source_case.value),
                    symbol_usages=asrt.matches_singleton_sequence(
                        is_reference_to_files_matcher__usage(
                            files_matcher_name)),
                    execution=execution_cases,
                )
Esempio n. 9
0
 def runTest(self):
     self.configuration.checker.check__abs_stx__source_variants(
         self,
         self.configuration.syntax_for_matcher(EmptyAbsStx()),
         self.configuration.arrangement_for_contents(
             'contents that makes the file non-empty',
             post_sds_population_action=
             MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY,
         ).as_arrangement_2(),
         MultiSourceExpectation(execution=ExecutionExpectation(
             main_result=asrt_pfh.is_fail(), )),
     )
Esempio n. 10
0
 def execution_cases(
         self
 ) -> Sequence[NExArr[ExecutionExpectation, ArrangementPostAct2]]:
     return [
         NExArr(
             'pre sds validation',
             ExecutionExpectation(
                 validation_pre_sds=asrt_svh.is_validation_error(
                     asrt_text_doc.is_string_for_test_that_equals(
                         self.err_msg_from_validator)), ),
             self._arrangement(
                 DdvValidatorThat(pre_sds_return_value=asrt_text_doc.
                                  new_single_string_text_for_test(
                                      self.err_msg_from_validator)))),
         NExArr(
             'post sds validation',
             ExecutionExpectation(main_result=asrt_pfh.is_hard_error(
                 asrt_text_doc.is_string_for_test_that_equals(
                     self.err_msg_from_validator)), ),
             self._arrangement(
                 DdvValidatorThat(post_setup_return_value=asrt_text_doc.
                                  new_single_string_text_for_test(
                                      self.err_msg_from_validator)))),
     ]
Esempio n. 11
0
 def runTest(self):
     # ARRANGE #
     actual_file_name = 'actual'
     file_type_cases = [
         NameAndValue(
             'regular file',
             [fs.File.empty(actual_file_name)],
         ),
         NameAndValue(
             'sym-link to regular file',
             [
                 fs.File.empty('a-regular-file'),
                 fs.sym_link(actual_file_name, 'a-regular-file')
             ],
         ),
     ]
     for file_type_case in file_type_cases:
         for rel_conf in RELATIVITY_OPTION_CONFIGURATIONS_FOR_ACTUAL_FILE:
             for matcher_result in [False, True]:
                 matcher_symbol = StringMatcherSymbolContextOfPrimitiveConstant('STRING_MATCHER', matcher_result)
                 all_symbols = list(rel_conf.symbols.contexts_for_arrangement()) + [matcher_symbol]
                 with self.subTest(file_type=file_type_case,
                                   path_variant=rel_conf.name,
                                   matcher_result=matcher_result):
                     CHECKER.check__abs_stx__source_variants(
                         self,
                         InstructionArgumentsAbsStx(
                             rel_conf.path_abs_stx_of_name(actual_file_name),
                             matcher_symbol.abstract_syntax,
                         ),
                         ArrangementPostAct2(
                             symbols=SymbolContext.symbol_table_of_contexts(all_symbols),
                             tcds=TcdsArrangementPostAct(
                                 tcds_contents=rel_conf.populator_for_relativity_option_root(
                                     DirContents(file_type_case.value)),
                                 post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY,
                             )
                         ),
                         MultiSourceExpectation(
                             symbol_usages=SymbolContext.usages_assertion_of_contexts(all_symbols),
                             execution=ExecutionExpectation(
                                 main_result=asrt_pfh.is_pass_of_fail(matcher_symbol.result_value)
                             )
                         ),
                     )
Esempio n. 12
0
 def runTest(self):
     test_setup = test_setups__proc_exe_set.TimeoutTestSetup(
         self, expected_timeout=72)
     # ACT & ASSERT #
     CHECKER.check__abs_stx(
         self,
         InstructionArguments(
             test_setup.valid_program_wo_sym_refs(),
             CONST_TRUE_INT_MATCHER_SYMBOL.abstract_syntax,
         ),
         ArrangementPostAct2(
             symbols=CONST_TRUE_INT_MATCHER_SYMBOL.symbol_table,
             process_execution=test_setup.proc_exe_arr__w_settings_check,
         ),
         Expectation2(
             ParseExpectation(symbol_usages=CONST_TRUE_INT_MATCHER_SYMBOL.
                              usages_assertion),
             ExecutionExpectation(main_result=asrt_pfh.is_pass()),
         ))
Esempio n. 13
0
 def test_invalid_arguments_without_symbol_references(self):
     test_cases = [
         IntegerMatcherComparisonAbsStx.of_cmp_op__str(comparators.EQ, 'a'),
         IntegerMatcherComparisonAbsStx.of_cmp_op__str(
             comparators.GT, '1.5'),
     ]
     for condition_syntax in test_cases:
         with self.subTest(condition_syntax.as_str__default()):
             instr_arg = self._conf().arguments_constructor.apply(
                 condition_syntax)
             self._check(
                 instr_arg,
                 ArrangementPostAct2(),
                 MultiSourceExpectation(
                     symbol_usages=asrt.is_empty_sequence,
                     execution=ExecutionExpectation(
                         validation_pre_sds=svh_asrt.is_validation_error(),
                     ),
                 ),
             )
Esempio n. 14
0
 def runTest(self):
     # ARRANGE #
     for matcher_result in [False, True]:
         matcher = StringMatcherSymbolContextOfPrimitiveConstant('STRING_MATCHER', matcher_result)
         with self.subTest(matcher_result=matcher_result):
             # ACT & ASSERT #
             self.configuration.checker.check__abs_stx__source_variants(
                 self,
                 self.configuration.syntax_for_matcher(matcher.abstract_syntax),
                 self.configuration.arrangement_for_contents(
                     actual_contents='',
                     symbols=matcher.symbol_table,
                     post_sds_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY,
                 ).as_arrangement_2(),
                 MultiSourceExpectation(
                     symbol_usages=matcher.usages_assertion,
                     execution=ExecutionExpectation(
                         main_result=asrt_pfh.is_non_hard_error(matcher.result_value),
                     ),
                 )
             )
Esempio n. 15
0
 def runTest(self):
     # ARRANGE #
     test_setup = StdinCheckWithProgramWExitCode0ForSuccess()
     # ACT & ASSERT #
     CHECKER.check__abs_stx(
         self,
         InstructionArguments(
             test_setup.program_that_checks_stdin__syntax(
                 'the contents of stdin'),
             CONST_TRUE_INT_MATCHER_SYMBOL.abstract_syntax,
         ),
         ArrangementPostAct2(
             symbols=CONST_TRUE_INT_MATCHER_SYMBOL.symbol_table,
             tcds=TcdsArrangementPostAct(
                 tcds_contents=test_setup.tcds_contents, )),
         Expectation2(
             ParseExpectation(symbol_usages=CONST_TRUE_INT_MATCHER_SYMBOL.
                              usages_assertion, ),
             execution=ExecutionExpectation(main_result=asrt_pfh.is_pass()),
         ),
     )
 def runTest(self):
     # ARRANGE #
     program_symbol = ProgramSymbolContext.of_arbitrary_value('PROGRAM_SYMBOL')
     const_true_int_matcher_symbol = IntegerMatcherSymbolContext.of_primitive_constant(
         'CONST_TRUE_INT_MATCHER',
         result=True,
     )
     all_symbols = [program_symbol,
                    const_true_int_matcher_symbol,
                    ]
     hard_error_message = 'the err msg'
     # ACT & ASSERT #
     CHECKER.check__abs_stx(
         self,
         InstructionArguments(
             program_symbol.abstract_syntax,
             const_true_int_matcher_symbol.abstract_syntax,
         ),
         ArrangementPostAct2(
             symbols=SymbolContext.symbol_table_of_contexts(all_symbols),
             process_execution=ProcessExecutionArrangement(
                 os_services_access.new_for_cmd_exe(
                     CommandExecutorThatRaisesHardError(
                         asrt_text_doc.new_single_string_text_for_test(hard_error_message)
                     ),
                 ),
             ),
         ),
         Expectation2(
             ParseExpectation(
                 symbol_usages=SymbolContext.usages_assertion_of_contexts(all_symbols),
             ),
             ExecutionExpectation(
                 main_result=asrt_pfh.is_hard_error(
                     asrt_text_doc.is_string_for_test_that_equals(hard_error_message)
                 )
             ),
         )
     )
Esempio n. 17
0
 def runTest(self):
     # ARRANGE #
     program_symbol = ProgramSymbolContext.of_arbitrary_value(
         'PROGRAM_SYMBOL')
     const_true_int_matcher_symbol = IntegerMatcherSymbolContext.of_primitive_constant(
         'CONST_TRUE_INT_MATCHER',
         result=True,
     )
     string_transformer_that_reports_failure_if_applied = StringTransformerSymbolContext.of_primitive(
         'STRING_TRANSFORMER_THAT_MUST_NOT_BE_USED',
         StringTransformerThatFailsTestIfApplied(self))
     all_symbols = [
         program_symbol,
         string_transformer_that_reports_failure_if_applied,
         const_true_int_matcher_symbol,
     ]
     # ACT & ASSERT #
     CHECKER.check__abs_stx(
         self,
         InstructionArguments(
             FullProgramAbsStx(
                 program_symbol.abstract_syntax,
                 transformation=
                 string_transformer_that_reports_failure_if_applied.
                 abstract_syntax),
             const_true_int_matcher_symbol.abstract_syntax,
         ),
         ArrangementPostAct2(
             symbols=SymbolContext.symbol_table_of_contexts(all_symbols),
             process_execution=ProcessExecutionArrangement(
                 os_services_access.new_for_cmd_exe(
                     CommandExecutorThatJustReturnsConstant(1), ), ),
         ),
         Expectation2(
             ParseExpectation(
                 symbol_usages=SymbolContext.usages_assertion_of_contexts(
                     all_symbols), ),
             ExecutionExpectation(main_result=asrt_pfh.is_pass()),
         ))
Esempio n. 18
0
 def runTest(self):
     error_message = 'the error message'
     matcher_that_raises_hard_error = StringMatcherSymbolContext.of_primitive(
         'STRING_MATCHER',
         matchers.MatcherThatReportsHardError(error_message)
     )
     self.configuration.checker.check__abs_stx__source_variants(
         self,
         self.configuration.syntax_for_matcher(matcher_that_raises_hard_error.abstract_syntax),
         self.configuration.arrangement_for_contents(
             '',
             post_sds_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY,
             symbols=matcher_that_raises_hard_error.symbol_table,
         ).as_arrangement_2(),
         MultiSourceExpectation(
             symbol_usages=matcher_that_raises_hard_error.usages_assertion,
             execution=ExecutionExpectation(
                 main_result=pfh_assertions.is_hard_error(
                     asrt_text_doc.is_string_for_test_that_equals(error_message)
                 ),
             )
         ),
     )
Esempio n. 19
0
from exactly_lib_test.impls.instructions.assert_.test_resources.instruction_check import MultiSourceExpectation, \
    ExecutionExpectation
from exactly_lib_test.test_case.result.test_resources import pfh_assertions

IS_PASS = MultiSourceExpectation()
IS_FAIL = MultiSourceExpectation(execution=ExecutionExpectation(
    main_result=pfh_assertions.is_fail__with_arbitrary_message()))
Esempio n. 20
0
 def expectation(self) -> ExecutionExpectation:
     return ExecutionExpectation(
         main_result=asrt_pfh.is_hard_error__with_arbitrary_message(), )
Esempio n. 21
0
            for case in test_data.cases()
        ])

        # ACT & ASSERT #

        INSTRUCTION_CHECKER.check_multi(
            self,
            SourceArrangement.new_w_arbitrary_fs_location(
                arguments.as_arguments),
            ParseExpectation(symbol_usages=asrt.matches_singleton_sequence(
                is_reference_to_files_matcher__usage(
                    model_checker_symbol_name))),
            execution=[
                NExArr(
                    contents_case.name,
                    ExecutionExpectation(),
                    ArrangementPostAct2(
                        tcds=TcdsArrangementPostAct(
                            tcds_contents=tcds_populators.
                            TcdsPopulatorForRelOptionType(
                                checked_dir_location,
                                DirContents([
                                    Dir(checked_dir_name, contents_case.actual)
                                ]))),
                        symbols=SymbolTable({
                            model_checker_symbol_name:
                            model_checker.matcher__sym_tbl_container(
                                self, checked_dir_path, contents_case.expected)
                        })),
                ) for contents_case in contents_cases
            ],