def _check(put: unittest.TestCase,
           integer_matcher: IntegerMatcherAbsStx,
           integer_matcher_symbols: List[SymbolContext]):
    # ARRANGE #
    program_symbol = ProgramSymbolContext.of_arbitrary_value('PROGRAM_SYMBOL')
    all_symbols = [program_symbol] + integer_matcher_symbols

    command_execution_counter = recording.Counter(initial_value=0)
    # ACT & ASSERT #
    CHECKER.check__abs_stx(
        put,
        InstructionArguments(
            program_symbol.abstract_syntax,
            integer_matcher,
        ),
        ArrangementPostAct2(
            symbols=SymbolContext.symbol_table_of_contexts(all_symbols),
            process_execution=ProcessExecutionArrangement(
                os_services=os_services_w_cmd_exe_counting__w_wrapped(
                    command_execution_counter,
                    CommandExecutorThatJustReturnsConstant(1)
                ),
            )
        ),
        Expectation2(
            ParseExpectation(
                symbol_usages=SymbolContext.usages_assertion_of_contexts(all_symbols)
            )
        ),
    )
    put.assertEqual(1,
                    command_execution_counter.value,
                    'number of times the program has been executed')
Example #2
0
    def runTest(self):
        # ARRANGE #
        valid_program_symbol = ProgramSymbolContext.of_arbitrary_value(
            'VALID_PROGRAM')

        for invalid_matcher_case in im_validation_case.failing_validation_cases(
        ):
            invalid_matcher_symbol = invalid_matcher_case.value.symbol_context
            all_symbols = [valid_program_symbol, invalid_matcher_symbol]
            with self.subTest(invalid_matcher_case.name):
                # ACT & ASSERT #
                invalid_matcher_symbol = invalid_matcher_case.value.symbol_context
                CHECKER.check__abs_stx(
                    self,
                    InstructionArguments(
                        valid_program_symbol.abstract_syntax,
                        invalid_matcher_symbol.abstract_syntax,
                    ),
                    ArrangementPostAct2(
                        symbols=SymbolContext.symbol_table_of_contexts(
                            all_symbols), ),
                    Expectation2(
                        ParseExpectation(
                            symbol_usages=SymbolContext.
                            usages_assertion_of_contexts(all_symbols)),
                        ExecutionExpectation.
                        validation_corresponding_to__post_sds_as_hard_error(
                            invalid_matcher_case.value.actual, ),
                    ))
Example #3
0
    def test_stdin_is_devnull_WHEN_program_do_not_define_stdin(self):
        # ARRANGE #
        test_setup = NoStdinTestSetup(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(
                    self,
                    InstructionArguments(
                        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, ),
                    ),
                    Expectation2(
                        ParseExpectation(
                            symbol_usages=SymbolContext.
                            usages_assertion_of_contexts(all_symbols), ),
                        ExecutionExpectation(main_result=asrt_pfh.is_pass()),
                    ))
Example #4
0
    def runTest(self):
        # ARRANGE #
        valid_int_matcher_symbol = IntegerMatcherSymbolContext.of_arbitrary_value(
            'VALID_INT_MATCHER')

        for invalid_program_case in pgm_validation_cases.failing_validation_cases(
        ):
            all_symbols = list(invalid_program_case.value.symbol_contexts) + [
                valid_int_matcher_symbol
            ]
            directly_referenced_symbols = [
                invalid_program_case.value.program_symbol_context,
                valid_int_matcher_symbol
            ]
            with self.subTest(invalid_program_case.name):
                # ACT & ASSERT #
                CHECKER.check__abs_stx(
                    self,
                    InstructionArguments(
                        invalid_program_case.value.abstract_syntax,
                        valid_int_matcher_symbol.abstract_syntax,
                    ),
                    ArrangementPostAct2(
                        symbols=SymbolContext.symbol_table_of_contexts(
                            all_symbols), ),
                    Expectation2(
                        ParseExpectation(symbol_usages=SymbolContext.
                                         usages_assertion_of_contexts(
                                             directly_referenced_symbols), ),
                        ExecutionExpectation.
                        validation_corresponding_to__post_sds_as_hard_error(
                            invalid_program_case.value.actual, ),
                    ))
Example #5
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), ),
            ))
Example #6
0
    def execute(self, source: ParseSource):
        instruction = self.parse_checker.parse(
            self.put,
            ARBITRARY_FS_LOCATION_INFO,
            source,
            ParseExpectation(
                self.expectation.source,
                self.expectation.symbol_usages,
            ),
        )

        ex = self.expectation
        exe_checker = ExecutionChecker(self.put,
                                       self.arrangement.as_arrangement_2(),
                                       ex.execution)
        exe_checker.check(instruction)
        return
Example #7
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()),
         ))
Example #8
0
class ExecutorOfCaseGeneratorForDirContents(ExecutorOfCaseGenerator):
    def execute_single(
        self,
        put: unittest.TestCase,
        case: SingleCaseGenerator,
    ):
        INSTRUCTION_CHECKER.check_2(
            put,
            source=_arguments(
                case.model_file,
                case.arguments(),
            ).as_remaining_source,
            arrangement=ArrangementPostAct2(
                tcds=_mk_tcds_arrangement_post_act(case.tcds_arrangement()),
                symbols=case.symbols(put),
            ),
            expectation=Expectation2(
                ParseExpectation(symbol_usages=_symbol_usages_assertion(
                    case.expected_symbols())),
                _execution_expectation_of(case.execution_result())))
Example #9
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()),
         ),
     )
Example #10
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()),
         ))
Example #11
0
 def execute_multi(self, put: unittest.TestCase,
                   generator: MultipleExecutionCasesGenerator):
     INSTRUCTION_CHECKER.check_multi(
         put,
         source=SourceArrangement.new_w_arbitrary_fs_location(
             _arguments(generator.model_file,
                        generator.arguments()).as_arguments),
         parse_expectation=ParseExpectation(
             symbol_usages=_symbol_usages_assertion(
                 generator.expected_symbols())),
         execution=[
             NExArr(
                 case.name,
                 _execution_expectation_of(case.expected),
                 ArrangementPostAct2(
                     tcds=_mk_tcds_arrangement_post_act(
                         case.arrangement.tcds),
                     symbols=case.arrangement.symbols,
                 ),
             ) for case in generator.execution_cases()
         ],
     )
Example #12
0
    def check_multi__with_source_variants(
            self,
            put: unittest.TestCase,
            source: SourceArrangement,
            symbol_usages: Assertion[Sequence[SymbolUsage]],
            execution: Sequence[NExArr[ExecutionExpectation, ArrangementPostAct2]],
    ):
        for parse_source in equivalent_source_variants__with_source_check__consume_last_line(
                put,
                source.arguments.as_single_string):
            instruction = self._parse_checker.parse(
                put,
                source.fs_location_info,
                parse_source,
                ParseExpectation(
                    symbol_usages=symbol_usages,
                ))

            for case in execution:
                with put.subTest(execution_case=case.name):
                    checker = ExecutionChecker(put, case.arrangement, case.expected)
                    checker.check(instruction)
 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)
                 )
             ),
         )
     )
Example #14
0
 def check__abs_stx__source_variants(self,
                                     put: unittest.TestCase,
                                     syntax: AbstractSyntax,
                                     arrangement: ArrangementPostAct2,
                                     expectation: MultiSourceExpectation,
                                     ):
     tokens = syntax.tokenization()
     for layout_case in layout.STANDARD_LAYOUT_SPECS:
         source_str = tokens.layout(layout_case.value)
         for source_case in equivalent_source_variants__consume_last_line__s__nsc(source_str):
             with put.subTest(layout=layout_case.name,
                              source_variant=source_case.name):
                 self.check_2(
                     put,
                     source_case.source,
                     arrangement,
                     Expectation2(
                         ParseExpectation(
                             source_case.expectation,
                             expectation.symbol_usages,
                         ),
                         expectation.execution,
                     )
                 )
Example #15
0
            SymbolReferenceArgument(model_checker_symbol_name),
        )

        contents_cases = test_data.strip_file_type_info_s([
            test_data.identical_expected_and_actual(case.name, case.value)
            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:
Example #16
0
 def __init__(self,
              parse: ParseExpectation = ParseExpectation(),
              execution: ExecutionExpectation = ExecutionExpectation(),
              ):
     self.parse = parse
     self.execution = execution