コード例 #1
0
ファイル: instruction.py プロジェクト: emilkarlen/exactly
    def test_evaluation_of_comparison(self):
        the_instruction_environment = instruction_environment.fake_post_sds_environment()
        the_os_services = os_services.new_default()

        cases = [
            (
                'expectation type is positive: pass WHEN comparison succeeds',
                asrt_pfh.is_pass(),
                ExpectationType.POSITIVE,
                1,
                comparators.LT,
                2,
            ),
            (
                'expectation type is positive: fail WHEN comparison does not succeeds',
                asrt_pfh.is_fail(ASSERT_ERROR_MESSAGE_IS_A_STRING),
                ExpectationType.POSITIVE,
                1,
                comparators.LT,
                1,
            ),
            (
                'expectation type is negative: fail WHEN comparison succeeds',
                asrt_pfh.is_fail(ASSERT_ERROR_MESSAGE_IS_A_STRING),
                ExpectationType.NEGATIVE,
                1,
                comparators.LT,
                2,
            ),
            (
                'expectation type is negative: pass WHEN comparison does not succeeds',
                asrt_pfh.is_pass(),
                ExpectationType.NEGATIVE,
                1,
                comparators.LT,
                1,
            ),
        ]

        for name, result_assertion, expectation_type, l_op, op, r_op in cases:
            # ARRANGE #
            instruction_to_check = sut.Instruction(
                ComparisonHandler(THE_PROPERTY_DESCRIPTOR,
                                  expectation_type,
                                  operand_resolver_that(
                                      resolve_return_value_action=do_return(l_op)),
                                  op,
                                  operand_resolver_that(
                                      resolve_return_value_action=do_return(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)
コード例 #2
0
 def test_fail_error(self):
     # ARRANGE #
     error_message = 'validation error'
     # ACT #
     actual = sut.translate_pfh_exception_to_pfh(test_action, DO_FAIL, error_message)
     # ASSERT #
     expectation = asrt_pfh.is_fail(asrt.equals(error_message))
     expectation.apply_without_message(self, actual)
コード例 #3
0
 def test_fail_due_to_unexpected_result_from_main(self):
     with self.assertRaises(utils.TestError):
         self._check(
             utils.ParserThatGives(_SUCCESSFUL_INSTRUCTION),
             utils.single_line_source(),
             sut.ArrangementPostAct(),
             Expectation(
                 main_result=pfh_assertions.is_fail()),
         )
コード例 #4
0
 def test_fail_error(self):
     # ARRANGE #
     error_message = 'validation error'
     # ACT #
     actual = sut.translate_pfh_exception_to_pfh(test_action, DO_FAIL, error_message)
     # ASSERT #
     expectation = asrt_pfh.is_fail(
         asrt_text_doc.is_string_for_test(asrt.equals(error_message))
     )
     expectation.apply_without_message(self, actual)
コード例 #5
0
ファイル: configuration.py プロジェクト: emilkarlen/exactly
 def expect_failure_of_main(
     self,
     assertion_on_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_fail(assertion_on_error_message),
         symbol_usages=symbol_usages,
     )
コード例 #6
0
def expectation_that_file_for_actual_contents_is_invalid(conf: RelativityOptionConfiguration) -> Expectation:
    if conf.exists_pre_sds:
        return Expectation(
            validation_pre_sds=svh_assertions.is_validation_error(),
            symbol_usages=conf.symbols.usages_expectation(),
        )
    else:
        return Expectation(
            main_result=pfh_assertions.is_fail(),
            symbol_usages=conf.symbols.usages_expectation(),
        )
コード例 #7
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(), )),
     )
コード例 #8
0
ファイル: assertion_part.py プロジェクト: emilkarlen/exactly
 def test_return_pfh_fail_WHEN_PfhFailException_is_raised(self):
     # ARRANGE #
     assertion_part_that_raises = PartThatRaisesFailureExceptionIfArgumentIsEqualToOne()
     instruction = sut.AssertionInstructionFromAssertionPart(assertion_part_that_raises,
                                                             'custom environment',
                                                             lambda env: 1)
     # ACT #
     actual = instruction.main(self.environment, self.the_os_services)
     # ASSERT #
     assertion = asrt_pfh.is_fail(
         asrt.equals(PartThatRaisesFailureExceptionIfArgumentIsEqualToOne.ERROR_MESSAGE))
     assertion.apply_without_message(self, actual)
コード例 #9
0
ファイル: assertion_part.py プロジェクト: emilkarlen/exactly
 def test_return_pfh_fail_WHEN_PfhFailException_is_raised(self):
     # ARRANGE #
     assertion_part_that_raises = PartThatRaisesFailureExceptionIfArgumentIsEqualToOne()
     # ACT #
     actual = assertion_part_that_raises.check_and_return_pfh(self.environment,
                                                              self.the_os_services,
                                                              'custom environment',
                                                              1)
     # ASSERT #
     assertion = asrt_pfh.is_fail(
         asrt.equals(PartThatRaisesFailureExceptionIfArgumentIsEqualToOne.ERROR_MESSAGE))
     assertion.apply_without_message(self, actual)
コード例 #10
0
ファイル: assertion_part.py プロジェクト: emilkarlen/exactly
 def test_return_pfh_fail_WHEN_PfhFailException_is_raised(self):
     # ARRANGE #
     assertion_part_that_raises = PartThatRaisesFailureExceptionIfArgumentIsEqualToOne()
     # ACT #
     actual = assertion_part_that_raises.check_and_return_pfh(self.environment,
                                                              self.the_os_services,
                                                              1)
     # ASSERT #
     assertion = asrt_pfh.is_fail(
         is_string_for_test(
             asrt.equals(PartThatRaisesFailureExceptionIfArgumentIsEqualToOne.ERROR_MESSAGE))
     )
     assertion.apply_without_message(self, actual)
コード例 #11
0
    def runTest(self):
        sb = SB.new_with(constant_transformation_arguments=argument_syntax.syntax_for_transformer_option(
            argument_syntax.syntax_for_replace_transformer('a', 'A')
        ))

        cases = [
            Case('CONTENTS-MATCHER on separate line',
                 source=
                 self.configuration.source_for_lines(
                     sb.format_lines(['',
                                      '{empty}'])),
                 source_assertion=
                 asrt_source.source_is_at_end,
                 main_result_assertion=
                 pfh_assertions.is_pass(),
                 ),
            Case('transformation and CONTENTS-MATCHER on separate line',
                 source=
                 self.configuration.source_for_lines(
                     sb.format_lines(['',
                                      '{constant_transformation_arguments}',
                                      '{empty}'])),
                 source_assertion=
                 asrt_source.source_is_at_end,
                 main_result_assertion=
                 pfh_assertions.is_pass(),
                 ),
            Case('negation and CONTENTS-MATCHER on separate line',
                 source=
                 self.configuration.source_for_lines(
                     sb.format_lines(['',
                                      '{not}',
                                      '{empty}'])),
                 source_assertion=
                 asrt_source.source_is_at_end,
                 main_result_assertion=
                 pfh_assertions.is_fail(),
                 ),
        ]
        for case in cases:
            with self.subTest(case.name):
                self._check(
                    case.source,
                    self.configuration.arrangement_for_contents(
                        actual_contents='',
                        post_sds_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY),
                    Expectation(main_result=case.main_result_assertion,
                                source=case.source_assertion),
                )
コード例 #12
0
ファイル: assertion_part.py プロジェクト: emilkarlen/exactly
    def test_argument_getter_SHOULD_be_given_environment_as_argument(self):
        # ARRANGE #
        assertion_part = PartThatRaisesFailureExceptionIfArgumentIsEqualToOne()

        def argument_getter_that_depends_on_environment(env: InstructionEnvironmentForPostSdsStep) -> int:
            return 1 if env is self.environment else 0

        instruction = sut.AssertionInstructionFromAssertionPart(assertion_part,
                                                                'custom environment',
                                                                argument_getter_that_depends_on_environment)
        # ACT #
        actual = instruction.main(self.environment, self.the_os_services)
        # ASSERT #
        assertion = asrt_pfh.is_fail(asrt.equals(PartThatRaisesFailureExceptionIfArgumentIsEqualToOne.ERROR_MESSAGE))
        assertion.apply_without_message(self, actual)
コード例 #13
0
ファイル: exitcode.py プロジェクト: emilkarlen/exactly
    def test_with_symbol_references(self):
        symbol_1_name = 'symbol_1_name'
        symbol_2_name = 'symbol_2_name'

        test_cases = [
            CaseWithSymbols(
                'two argument form with a symbol that is a single integer',
                argument=' {op} {sym_ref}'.format(op=comparators.EQ.name,
                                                  sym_ref=symbol_reference_syntax_for_name(symbol_1_name)),
                symbol_name_and_value_list=[NameAndValue(symbol_1_name, '72')],
                actual_value_for_pass=72,
                actual_value_for_fail=87,
            ),
            CaseWithSymbols(
                'two argument form with two symbols that makes up the expected value when concatenated',
                argument=' {op} {sym_ref1}{sym_ref2}'.format(
                    op=comparators.EQ.name,
                    sym_ref1=symbol_reference_syntax_for_name(symbol_1_name),
                    sym_ref2=symbol_reference_syntax_for_name(symbol_2_name)),
                symbol_name_and_value_list=[NameAndValue(symbol_1_name, '7'),
                                            NameAndValue(symbol_2_name, '2')],
                actual_value_for_pass=72,
                actual_value_for_fail=87,
            ),
        ]
        for case in test_cases:
            for sub_name, actual_value, result_expectation in [('pass',
                                                                case.actual_value_for_pass,
                                                                pfh_assertions.is_pass()),
                                                               ('fail',
                                                                case.actual_value_for_fail,
                                                                pfh_assertions.is_fail())]:
                with self.subTest(name=case.name, sub_name=sub_name):
                    self._run(
                        remaining_source(case.argument,
                                         ['following line']),
                        ArrangementPostAct(
                            act_result_producer=act_result_of(actual_value),
                            symbols=symbol_table_with_string_constant_symbols(case.symbol_name_and_value_list),
                        ),
                        Expectation(
                            source=is_at_beginning_of_line(2),
                            main_result=result_expectation,
                            symbol_usages=equals_symbol_references(
                                string_symbol_references_of(case.symbol_name_and_value_list))
                        ),
                    )
コード例 #14
0
ファイル: assertion_part.py プロジェクト: emilkarlen/exactly
    def test_return_pfh_fail_WHEN_PfhFailException_is_raised(self):
        # ARRANGE #
        environment = fake_post_sds_environment()

        assertion_part_that_raises = PartThatRaisesFailureExceptionIfArgumentIsEqualToOne()
        instruction = sut.AssertionInstructionFromAssertionPart(assertion_part_that_raises,
                                                                lambda env: 1)
        # ACT #
        actual = instruction.main(environment,
                                  optionally_from_proc_exe_settings(None, environment.proc_exe_settings),
                                  self.the_os_services)
        # ASSERT #
        assertion = asrt_pfh.is_fail(
            asrt_text_doc.is_string_for_test(
                asrt.equals(PartThatRaisesFailureExceptionIfArgumentIsEqualToOne.ERROR_MESSAGE))
        )
        assertion.apply_without_message(self, actual)
コード例 #15
0
ファイル: assertion_part.py プロジェクト: emilkarlen/exactly
    def test_argument_getter_SHOULD_be_given_environment_as_argument(self):
        # ARRANGE #
        environment = fake_post_sds_environment()

        assertion_part = PartThatRaisesFailureExceptionIfArgumentIsEqualToOne()

        def argument_getter_that_depends_on_environment(env: InstructionEnvironmentForPostSdsStep) -> int:
            return 1 if env is environment else 0

        instruction = sut.AssertionInstructionFromAssertionPart(assertion_part,
                                                                argument_getter_that_depends_on_environment)
        # ACT #
        actual = instruction.main(environment,
                                  optionally_from_proc_exe_settings(None, environment.proc_exe_settings),
                                  self.the_os_services)
        # ASSERT #
        assertion = asrt_pfh.is_fail(
            asrt_text_doc.is_string_for_test(
                asrt.equals(PartThatRaisesFailureExceptionIfArgumentIsEqualToOne.ERROR_MESSAGE)
            )
        )
        assertion.apply_without_message(self, actual)
コード例 #16
0
    return ExpectationTypeConfigForPfh(expectation_type)


def pfh_expectation_type_config(expectation_type_of_test_case: ExpectationType) -> ExpectationTypeConfigForPfh:
    return ExpectationTypeConfigForPfh(expectation_type_of_test_case)


def expectation_type_config__non_is_success(expectation_type_of_test_case: ExpectationType
                                            ) -> ExpectationTypeConfigForNoneIsSuccess:
    return ExpectationTypeConfigForNoneIsSuccess(expectation_type_of_test_case)


_MAIN_RESULT_ASSERTION_FOR_PFH = {
    ExpectationType.POSITIVE: {
        PassOrFail.PASS: asrt_pfh.is_pass(),
        PassOrFail.FAIL: asrt_pfh.is_fail(),
    },
    ExpectationType.NEGATIVE: {
        PassOrFail.PASS: asrt_pfh.is_fail(),
        PassOrFail.FAIL: asrt_pfh.is_pass(),
    },
}

_ASSERT_IS_FAILURE_FOR_ERR_MSG = asrt.is_instance(str)

_MAIN_RESULT_ASSERTION_ERR_MSG_FOR_FAIL = {
    ExpectationType.POSITIVE: {
        PassOrFail.PASS: None,
        PassOrFail.FAIL: _ASSERT_IS_FAILURE_FOR_ERR_MSG,
    },
    ExpectationType.NEGATIVE: {
 def expectation_for_non_zero_exitcode(self) -> Expectation:
     return Expectation(main_result=pfh_assertions.is_fail())
コード例 #18
0
ファイル: exitcode.py プロジェクト: emilkarlen/exactly
        self.actual_value_for_fail = actual_value_for_fail
        self.symbol_name_and_value_list = symbol_name_and_value_list


def _actual_exitcode(exit_code: int) -> ArrangementPostAct:
    return ArrangementPostAct(act_result_producer=act_result_of(exit_code))


def act_result_of(exit_code: int):
    return ActResultProducerFromActResult(SubProcessResult(exitcode=exit_code))


def symbol_table_with_string_constant_symbols(symbol_name_and_value_list: list) -> SymbolTable:
    return SymbolTable(dict([(sym.name, data_symbol_utils.string_constant_container(sym.value))
                             for sym in symbol_name_and_value_list]))


def string_symbol_references_of(symbol_name_and_value_list: list) -> list:
    return [
        SymbolReference(symbol.name,
                        string_made_up_by_just_strings())
        for symbol in symbol_name_and_value_list
    ]


_IS_PASS = is_pass()
_IS_FAIL = Expectation(main_result=pfh_assertions.is_fail())

if __name__ == '__main__':
    unittest.TextTestRunner().run(suite())
コード例 #19
0
ファイル: configuration.py プロジェクト: emilkarlen/exactly
 def expect_failure_of_main(self,
                            assertion_on_error_message: ValueAssertion = asrt.anything_goes()):
     return Expectation(main_result=pfh_assertions.is_fail(assertion_on_error_message))