Ejemplo n.º 1
0
    def test_hard_error(self):
        the_instruction_environment = instruction_environment.fake_post_sds_environment()
        the_os_services = os_services.new_default()

        cases = [
            (
                'hard error exception in left operand',
                asrt_pfh.is_hard_error(asrt.equals('error error in left op')),

                operand_resolver_that(
                    resolve_return_value_action=actions.do_raise(PfhHardErrorException('error error in left op'))),
                operand_resolver_that(),
            ),
            (
                'hard error exception in right operand',
                asrt_pfh.is_hard_error(asrt.equals('error error in right op')),

                operand_resolver_that(),
                operand_resolver_that(
                    resolve_return_value_action=actions.do_raise(PfhHardErrorException('error error in right op'))),
            ),
        ]

        for name, result_assertion, l_op, r_op in cases:
            instruction_to_check = sut.Instruction(cmp_setup(l_op, r_op))
            with self.subTest(name=name):
                # ACT #

                actual = instruction_to_check.main(the_instruction_environment,
                                                   the_os_services)

                # ASSERT #

                result_assertion.apply_without_message(self, actual)
Ejemplo n.º 2
0
    def test_WHEN_given_validator_fails_post_setup_THEN_main_SHOULD_report_hard_error(self):
        # ARRANGE #
        environment = fake_post_sds_environment()

        the_error_message = 'the error message'
        assertion_part = PartForValidation(SdvValidatorThat(
            post_setup_return_value=asrt_text_doc.new_single_string_text_for_test(the_error_message))
        )
        instruction = sut.AssertionInstructionFromAssertionPart(assertion_part,
                                                                lambda env: 'argument to assertion_part')
        is_validation_success = asrt_svh.is_success()
        main_result_is_hard_error = asrt_pfh.is_hard_error(
            asrt_text_doc.is_single_pre_formatted_text_that_equals(the_error_message)
        )

        # ACT & ASSERT #

        pre_sds_result = instruction.validate_pre_sds(environment)
        is_validation_success.apply_with_message(self, pre_sds_result,
                                                 'pre sds validation should succeed')
        post_sds_result = instruction.validate_post_setup(environment)
        is_validation_success.apply_with_message(self, post_sds_result,
                                                 'post setup validation should succeed')
        main_result = instruction.main(environment,
                                       optionally_from_proc_exe_settings(None, environment.proc_exe_settings),
                                       self.the_os_services)

        main_result_is_hard_error.apply_with_message(self,
                                                     main_result,
                                                     'main should fail')
Ejemplo n.º 3
0
 def expectation(self) -> Expectation:
     return Expectation(
         symbol_usages=asrt.matches_singleton_sequence(
             is_reference_to_files_matcher__usage(
                 self.name_of_referenced_symbol)),
         main_result=asrt_pfh.is_hard_error(
             is_string_for_test_that_equals(self.error_message)),
     )
 def test_hard_error(self):
     # ARRANGE #
     error_message = 'hard error'
     # ACT #
     actual = sut.translate_pfh_exception_to_pfh(test_action, DO_HARD_ERROR, error_message)
     # ASSERT #
     expectation = asrt_pfh.is_hard_error(asrt.equals(error_message))
     expectation.apply_without_message(self, actual)
Ejemplo n.º 5
0
 def validation_corresponding_to_dsp__post_sds_as_hard_error(path_location: DirectoryStructurePartition
                                                             ) -> 'ExecutionExpectation':
     if path_location is DirectoryStructurePartition.HDS:
         return ExecutionExpectation(
             validation_pre_sds=svh_assertions.is_validation_error()
         )
     else:
         return ExecutionExpectation(
             main_result=pfh_assertions.is_hard_error()
         )
 def test_hard_error(self):
     # ARRANGE #
     error_message = 'hard error'
     # ACT #
     actual = sut.translate_pfh_exception_to_pfh(test_action, DO_HARD_ERROR, error_message)
     # ASSERT #
     expectation = asrt_pfh.is_hard_error(
         asrt_text_doc.is_string_for_test(asrt.equals(error_message))
     )
     expectation.apply_without_message(self, actual)
Ejemplo n.º 7
0
 def expect_hard_error_of_main__any(
     self,
     symbol_usages: Assertion[
         Sequence[SymbolUsage]] = asrt.is_empty_sequence,
 ):
     return Expectation(
         main_result=pfh_assertions.is_hard_error(
             asrt_text_doc.is_any_text()),
         symbol_usages=symbol_usages,
     )
Ejemplo n.º 8
0
 def expect_failing_validation_post_setup(
     self,
     error_message: Assertion[TextRenderer] = asrt_text_doc.is_any_text(),
     symbol_usages: Assertion[
         Sequence[SymbolUsage]] = asrt.is_empty_sequence,
 ):
     return Expectation(
         main_result=pfh_assertions.is_hard_error(error_message),
         symbol_usages=symbol_usages,
     )
 def expect_failing_validation_post_setup(
     self,
     assertion_on_error_message: Assertion[str] = asrt.anything_goes(),
     symbol_usages: Assertion[
         Sequence[SymbolUsage]] = asrt.is_empty_sequence,
 ):
     return Expectation(
         main_result=pfh_assertions.is_hard_error(
             asrt_text_doc.is_string_for_test(assertion_on_error_message)),
         symbol_usages=symbol_usages,
     )
Ejemplo n.º 10
0
 def validation_corresponding_to__post_sds_as_hard_error(actual: ValidationActual) -> 'ExecutionExpectation':
     if actual.pre_sds is not None:
         return ExecutionExpectation(
             validation_pre_sds=svh_assertions.is_validation_error(
                 asrt_text_doc.is_string_for_test_that_equals(actual.pre_sds),
             )
         )
     elif actual.post_sds is not None:
         return ExecutionExpectation(
             main_result=pfh_assertions.is_hard_error(
                 asrt_text_doc.is_string_for_test_that_equals(actual.post_sds),
             )
         )
     else:
         return ExecutionExpectation()
Ejemplo n.º 11
0
    def test_hard_error_when_there_is_a_single_file_that_is_not_a_regular_file(self):
        parser = sut.parser.Parser()
        name_of_checked_dir = 'checked-dir'
        relativity_root_conf = tr.DEFAULT_REL_OPT_CONFIG
        non_regular_files = [
            empty_dir('a-directory'),
            sym_link('sym-link', 'non-existing-target')
        ]

        for file_contents_assertion in self.file_content_assertion_variants:
            for quantifier in Quantifier:
                arguments_constructor = args.complete_arguments_constructor(
                    name_of_checked_dir,
                    FileQuantificationAssertionVariant(
                        quantifier,
                        file_contents_arg2(file_contents_assertion)))
                for expectation_type in ExpectationType:
                    arguments = arguments_constructor.apply(pfh_expectation_type_config(expectation_type),
                                                            relativity_root_conf)
                    for non_regular_file in non_regular_files:
                        with self.subTest(
                                quantifier=quantifier.name,
                                expectation_type=expectation_type.name,
                                arguments=arguments,
                                non_regular_file=non_regular_file.name):
                            instruction_check.check(
                                self,
                                parser,
                                remaining_source(arguments),
                                arrangement=
                                ArrangementPostAct(
                                    home_or_sds_contents=relativity_root_conf.populator_for_relativity_option_root(
                                        DirContents([
                                            Dir(name_of_checked_dir, [
                                                non_regular_file,
                                            ]),
                                        ])
                                    )
                                ),
                                expectation=
                                Expectation(
                                    main_result=asrt_pfh.is_hard_error()
                                )
                            )
 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)
                 )
             ),
         )
     )
Ejemplo n.º 13
0
    def runTest(self):
        # ARRANGE #

        error_message = 'error message from file matcher'
        file_matcher_that_raises_hard_error = NameAndValue(
            'file_matcher_that_raises_hard_error',
            self._resolver_of_matcher_that_causes_hard_error(error_message)
        )

        path_relativity = conf_rel_sds(RelSdsOptionType.REL_ACT)

        checked_file = empty_file('checked-file.txt')

        argument = args.CompleteInstructionArg(
            ExpectationType.POSITIVE,
            args.PathArg(path_relativity.file_argument_with_option(checked_file.name)),
            fm_args.SymbolReference(file_matcher_that_raises_hard_error.name))

        # ACT & ASSERT #

        instruction_check.check(
            self,
            sut.Parser(),
            remaining_source(str(argument)),
            ArrangementPostAct(
                symbols=symbol_table_from_name_and_resolvers([
                    file_matcher_that_raises_hard_error
                ]),
                sds_contents=path_relativity.populator_for_relativity_option_root__sds(
                    DirContents([checked_file])
                )
            ),
            instruction_check.expectation(
                main_result=pfh_assertions.is_hard_error(asrt_str.contains(error_message)),
                symbol_usages=asrt.matches_sequence([
                    asrt_file_matcher.is_file_matcher_reference_to__ref(file_matcher_that_raises_hard_error.name)
                ])
            ))
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
    def runTest(self):
        # ARRANGE #

        error_message = 'error message from file matcher'
        file_matcher_that_raises_hard_error = FileMatcherSymbolContext.of_primitive(
            'file_matcher_that_raises_hard_error',
            matchers.MatcherThatReportsHardError(error_message)
        )

        path_relativity = conf_rel_sds(RelSdsOptionType.REL_ACT)

        checked_file = File.empty('checked-file.txt')

        argument = args.CompleteInstructionArg(
            ExpectationType.POSITIVE,
            path_relativity.path_argument_of_rel_name(checked_file.name),
            fm_args.SymbolReference(file_matcher_that_raises_hard_error.name))

        # ACT & ASSERT #

        CHECKER.check(
            self,
            remaining_source(str(argument)),
            ArrangementPostAct(
                symbols=file_matcher_that_raises_hard_error.symbol_table,
                sds_contents=path_relativity.populator_for_relativity_option_root__sds(
                    DirContents([checked_file])
                )
            ),
            instruction_check.expectation(
                main_result=pfh_assertions.is_hard_error(
                    asrt_text_doc.rendered_text_matches(asrt_str.contains(error_message))
                ),
                symbol_usages=asrt.matches_sequence([
                    file_matcher_that_raises_hard_error.reference_assertion
                ])
            ))
Ejemplo n.º 16
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)))),
     ]
Ejemplo n.º 17
0
 def expect_failure_because_specified_file_under_sds_is_missing(
         self,
         symbol_usages: Assertion[Sequence[SymbolUsage]] = asrt.is_empty_sequence,
 ):
     return Expectation(main_result=asrt_pfh.is_hard_error(),
                        symbol_usages=symbol_usages)
Ejemplo n.º 18
0
 def expect_target_is_not_a_directory(self):
     return Expectation(main_result=pfh_assertions.is_hard_error())
 def expect_hard_error_in_main(self) -> Expectation:
     return Expectation(main_result=pfh_assertions.is_hard_error())
Ejemplo n.º 20
0
 def expect_failure_to_create_dir(self,
                                  symbol_usages: ValueAssertion = asrt.is_empty_sequence):
     return Expectation(main_result=pfh_assertions.is_hard_error(),
                        symbol_usages=symbol_usages)
Ejemplo n.º 21
0
 def expect_hard_error_of_main(self,
                               assertion_on_error_message: ValueAssertion = asrt.anything_goes()):
     return Expectation(main_result=pfh_assertions.is_hard_error(assertion_on_error_message))