Example #1
0
 def runTest(self):
     cases = [
         NameAndValue(
             'missing int matcher',
             InstructionArguments(
                 ProgramOfSymbolReferenceAbsStx('PROGRAM_SYMBOL'),
                 CustomIntegerMatcherAbsStx.empty(),
             ),
         ),
         NameAndValue(
             'missing program',
             InstructionArguments(
                 CustomPgmAndArgsAbsStx.empty(),
                 IntegerMatcherSymbolReferenceAbsStx('INT_MATCHER_SYMBOL'),
             ),
         ),
         NameAndValue(
             'superfluous arguments',
             InstructionArguments(
                 ProgramOfSymbolReferenceAbsStx('PROGRAM_SYMBOL'),
                 im_abs_stx.
                 symbol_reference_followed_by_superfluous_string_on_same_line(
                     'INT_MATCHER_SYMBOL'),
             ),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             PARSE_CHECKER.check_invalid_syntax__abs_stx(
                 self,
                 case.value,
             )
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 #3
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 #4
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 #5
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()),
            ),
        )
Example #6
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()),
                    ),
                )
Example #7
0
 def runTest(self):
     test_cases = [
         (_actual_exitcode(0), of_op(EQ, 72), IS_FAIL),
         (_actual_exitcode(72), of_op(EQ, 72), IS_PASS),
         (_actual_exitcode(72), of_neg_op(EQ, 72), IS_FAIL),
         (_actual_exitcode(72), of_neg_op(EQ, 73), IS_PASS),
         (_actual_exitcode(72), of_op(NE, 72), IS_FAIL),
         (_actual_exitcode(72), of_op(NE, 73), IS_PASS),
         (_actual_exitcode(72), of_op(LT, 28), IS_FAIL),
         (_actual_exitcode(72), of_op(LT, 72), IS_FAIL),
         (_actual_exitcode(72), of_op(LT, 87), IS_PASS),
     ]
     for program_syntax, matcher_syntax, expectation in test_cases:
         instruction_syntax = InstructionArguments(
             program_syntax,
             matcher_syntax,
         )
         with self.subTest(instruction_syntax.as_str__default()):
             CHECKER.check__abs_stx__source_variants(
                 self,
                 instruction_syntax,
                 ArrangementPostAct2(),
                 expectation,
             )
Example #8
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 #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()),
         ))
 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)
                 )
             ),
         )
     )