Ejemplo n.º 1
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()),
                    ),
                )
 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), ),
         ))
Ejemplo n.º 3
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(), ),
                     ),
                 )
Ejemplo n.º 4
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()),
            ),
        )
Ejemplo n.º 5
0
    def _do_check(
        self,
        program: ProgramAbsStx,
        process_execution_w_stdin_check: ProcessExecutionArrangement,
        program_symbols: Sequence[SymbolContext],
        tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(),
    ):
        # ARRANGE #
        string_matcher_const_true = StringMatcherSymbolContext.of_primitive(
            'CONSTANT_TRUE',
            ConstantMatcherWithCustomName('const true', True),
        )
        symbols = list(program_symbols) + [string_matcher_const_true]
        copy_stdin_and_check_via_matcher = StdoutErrFromProgramAbsStx(
            program,
            string_matcher_const_true.abstract_syntax,
        )

        checker = instruction_check.Checker(self.configuration.parser())
        # ACT & ASSERT #
        checker.check__abs_stx__source_variants(
            self,
            copy_stdin_and_check_via_matcher,
            ArrangementPostAct2(
                symbols=SymbolContext.symbol_table_of_contexts(symbols),
                tcds=TcdsArrangementPostAct(tcds_contents=tcds_contents),
                process_execution=process_execution_w_stdin_check,
            ),
            MultiSourceExpectation(symbol_usages=SymbolContext.
                                   usages_assertion_of_contexts(symbols)),
        )
Ejemplo n.º 6
0
    def runTest(self):
        # ARRANGE #
        contents_of_stdin = 'the contents of stdin'
        string_matcher_that_checks_model = StringMatcherSymbolContext.of_primitive(
            'SM_THAT_CHECKS_MODEL',
            EqualsConstant(contents_of_stdin),
        )
        checker = instruction_check.Checker(self.configuration.parser())
        program_that_copies_stdin_to_output = ProgramOfPythonInterpreterAbsStx.of_execute_python_src_string(
            py_programs.copy_stdin_to__single_line(
                self.configuration.output_file()))
        copy_stdin_and_check_via_matcher = StdoutErrFromProgramAbsStx(
            FullProgramAbsStx(program_that_copies_stdin_to_output,
                              stdin=StringSourceOfStringAbsStx.of_str(
                                  contents_of_stdin, QuoteType.HARD)),
            string_matcher_that_checks_model.abstract_syntax,
        )

        # ACT & ASSERT #
        checker.check__abs_stx__source_variants(
            self,
            copy_stdin_and_check_via_matcher,
            ArrangementPostAct2(
                symbols=string_matcher_that_checks_model.symbol_table, ),
            MultiSourceExpectation(
                symbol_usages=string_matcher_that_checks_model.usages_assertion
            ),
        )
Ejemplo 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
                                    )
                                )
                            )
                        )
Ejemplo n.º 8
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(), )),
     )
Ejemplo n.º 9
0
 def runTest(self):
     # ARRANGE #
     actual_file_name = 'actual'
     invalid_file_cases = [
         NameAndValue(
             'file does not exist',
             [],
         ),
         NameAndValue(
             'file is a dir',
             [Dir.empty(actual_file_name)],
         ),
         NameAndValue(
             'sym-link to dir',
             [
                 Dir.empty('a-dir'),
                 fs.sym_link(actual_file_name, 'a-dir')
             ],
         ),
         NameAndValue(
             'broken sym-link',
             [fs.sym_link(actual_file_name, 'non-existing-target')],
         ),
     ]
     for invalid_file_case in invalid_file_cases:
         for rel_conf in RELATIVITY_OPTION_CONFIGURATIONS_FOR_ACTUAL_FILE:
             with self.subTest(invalid_cause=invalid_file_case,
                               path_variant=rel_conf.name):
                 CHECKER.check__abs_stx__source_variants(
                     self,
                     InstructionArgumentsAbsStx(
                         rel_conf.path_abs_stx_of_name(actual_file_name),
                         EmptyAbsStx(),
                     ),
                     ArrangementPostAct2(
                         symbols=rel_conf.symbols.in_arrangement(),
                         tcds=TcdsArrangementPostAct(
                             tcds_contents=rel_conf.populator_for_relativity_option_root(
                                 DirContents(invalid_file_case.value)),
                             post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY,
                         )
                     ),
                     MultiSourceExpectation(
                         symbol_usages=rel_conf.symbols.usages_expectation(),
                         execution=ExecutionExpectation.validation_corresponding_to_dsp__post_sds_as_hard_error(
                             rel_conf.directory_structure_partition,
                         )
                     ),
                 )
Ejemplo n.º 10
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)
                             )
                         ),
                     )
Ejemplo n.º 11
0
 def runTest(self):
     for validation_case in validation_cases.failing_validation_cases():
         invalid_matcher = validation_case.value.symbol_context
         self.configuration.checker.check__abs_stx__source_variants(
             self,
             self.configuration.syntax_for_matcher(invalid_matcher.abstract_syntax),
             self.configuration.arrangement_for_contents(
                 '',
                 post_sds_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY,
                 symbols=invalid_matcher.symbol_table,
             ).as_arrangement_2(),
             MultiSourceExpectation(
                 symbol_usages=invalid_matcher.usages_assertion,
                 execution=ExecutionExpectation.validation_corresponding_to__post_sds_as_hard_error(
                     validation_case.value.actual,
                 )
             ),
         )
Ejemplo n.º 12
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(),
                     ),
                 ),
             )
Ejemplo n.º 13
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),
                     ),
                 )
             )
Ejemplo n.º 14
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)
                 ),
             )
         ),
     )
Ejemplo n.º 15
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()))