예제 #1
0
    def instruction_setup_with_the_instruction(self, instruction_name: str) -> InstructionsSetup:
        instruction_setup = single_instruction_setup(instruction_name, self.instruction)
        config = dict()
        setup = dict()
        before_assert = dict()
        assert_ = dict()
        cleanup = dict()

        phase_enum = self.phase.the_enum
        if phase_enum is PhaseEnum.SETUP:
            setup[instruction_name] = instruction_setup
        elif phase_enum is PhaseEnum.BEFORE_ASSERT:
            before_assert[instruction_name] = instruction_setup
        elif phase_enum is PhaseEnum.ASSERT:
            assert_[instruction_name] = instruction_setup
        elif phase_enum is PhaseEnum.CLEANUP:
            cleanup[instruction_name] = instruction_setup
        else:
            raise ValueError('Unhandled phase: ' + str(phase_enum))

        return InstructionsSetup(config_instruction_set=config,
                                 setup_instruction_set=setup,
                                 before_assert_instruction_set=before_assert,
                                 assert_instruction_set=assert_,
                                 cleanup_instruction_set=cleanup
                                 )
예제 #2
0
    def instruction_setup_with_the_instruction(
            self, instruction_name: str) -> InstructionsSetup:
        instruction_setup = single_instruction_setup(instruction_name,
                                                     self.instruction)
        config = dict()
        setup = dict()
        before_assert = dict()
        assert_ = dict()
        cleanup = dict()

        phase_enum = self.phase.the_enum
        if phase_enum is PhaseEnum.SETUP:
            setup[instruction_name] = instruction_setup
        elif phase_enum is PhaseEnum.BEFORE_ASSERT:
            before_assert[instruction_name] = instruction_setup
        elif phase_enum is PhaseEnum.ASSERT:
            assert_[instruction_name] = instruction_setup
        elif phase_enum is PhaseEnum.CLEANUP:
            cleanup[instruction_name] = instruction_setup
        else:
            raise ValueError('Unhandled phase: ' + str(phase_enum))

        return InstructionsSetup(config_instruction_set=config,
                                 setup_instruction_set=setup,
                                 before_assert_instruction_set=before_assert,
                                 assert_instruction_set=assert_,
                                 cleanup_instruction_set=cleanup)
def test_suite_definition_with_single_conf_instruction(name: str,
                                                       instruction: ConfigurationSectionInstruction
                                                       ) -> TestSuiteDefinition:
    configuration_section_instructions = {
        name: single_instruction_setup(name, instruction)

    }
    return test_suite_definition_with_instructions(configuration_section_instructions)
예제 #4
0
def test_suite_definition_with_single_conf_instruction(name: str,
                                                       instruction: ConfigurationSectionInstruction
                                                       ) -> TestSuiteDefinition:
    configuration_section_instructions = {
        name: single_instruction_setup(name, instruction)

    }
    return test_suite_definition_with_instructions(configuration_section_instructions)
예제 #5
0
def test_case_definition_with_only_assert_phase_instructions(
    assert_phase_instructions: Sequence[Tuple[str, AssertPhaseInstruction]]
) -> TestCaseDefinitionForMainProgram:
    assert_phase_instructions_dict = {
        name: single_instruction_setup(name, instruction)
        for name, instruction in assert_phase_instructions
    }
    return TestCaseDefinitionForMainProgram(TestCaseParsingSetup(
        instruction_name_extractor_function=
        instruction_name_and_argument_splitter.splitter,
        instruction_setup=InstructionsSetup(
            config_instruction_set={},
            setup_instruction_set={},
            assert_instruction_set=assert_phase_instructions_dict,
            before_assert_instruction_set={},
            cleanup_instruction_set={},
        ),
        act_phase_parser=ActPhaseParser()),
                                            builtin_symbols=[])
예제 #6
0
def test_case_definition_with_only_assert_phase_instructions(
        assert_phase_instructions: Sequence[Tuple[str, AssertPhaseInstruction]]
) -> TestCaseDefinition:
    assert_phase_instructions_dict = {
        name: single_instruction_setup(name, instruction)
        for name, instruction in assert_phase_instructions
    }
    return TestCaseDefinition(
        TestCaseParsingSetup(
            instruction_name_extractor_function=instruction_name_and_argument_splitter.splitter,
            instruction_setup=InstructionsSetup(
                config_instruction_set={},
                setup_instruction_set={},
                assert_instruction_set=assert_phase_instructions_dict,
                before_assert_instruction_set={},
                cleanup_instruction_set={},
            ),
            act_phase_parser=ActPhaseParser()),
        predefined_properties.new_empty(),
    )
예제 #7
0
파일: misc.py 프로젝트: emilkarlen/exactly
def test_case_definition_with_only_assert_phase_instructions(
        assert_phase_instructions: Sequence[Tuple[str, AssertPhaseInstruction]]
) -> TestCaseDefinitionForMainProgram:
    assert_phase_instructions_dict = {
        name: single_instruction_setup(name, instruction)
        for name, instruction in assert_phase_instructions
    }
    return TestCaseDefinitionForMainProgram(
        TestCaseParsingSetup(
            instruction_name_extractor_function=instruction_name_and_argument_splitter.splitter,
            instruction_setup=InstructionsSetup(
                config_instruction_set={},
                setup_instruction_set={},
                assert_instruction_set=assert_phase_instructions_dict,
                before_assert_instruction_set={},
                cleanup_instruction_set={},
            ),
            act_phase_parser=ActPhaseParser()),
        builtin_symbols=[]
    )
예제 #8
0
def test_case_definition_with_only_assert_phase_instructions(
        assert_phase_instructions: Sequence[Tuple[str, AssertPhaseInstruction]]
) -> TestCaseDefinition:
    assert_phase_instructions_dict = {
        name: single_instruction_setup(name, instruction)
        for name, instruction in assert_phase_instructions
    }
    return TestCaseDefinition(
        TestCaseParsingSetup(
            instruction_name_extractor_function=instruction_name_and_argument_splitter.splitter,
            instruction_setup=InstructionsSetup(
                config_instruction_set={},
                setup_instruction_set={},
                assert_instruction_set=assert_phase_instructions_dict,
                before_assert_instruction_set={},
                cleanup_instruction_set={},
            ),
            act_phase_parser=ActPhaseParser()),
        PredefinedProperties({},
                             symbol_table.empty_symbol_table())
    )
    def _run(self,
             suite_file_name: str,
             suite_file_overriding: Optional[Path]):
        default_test_case_handling = setup_with_null_act_phase_and_null_preprocessing()

        suite_conf_instruction = SuiteConfInstructionThatSets(
            preprocessor=preprocessor_that_gives_const_source_with_single_assert_instruction(
                ASSERT_PHASE_INSTRUCTION_THAT_PASS_IFF_STDOUT_IS_SUCCESS_INDICATOR_STRING__NAME),
            act_phase_setup=act_setup_that_prints_single_string_on_stdout(SUCCESS_INDICATOR_STRING))

        suite_conf_instructions = {
            SUITE_CONF_INSTRUCTION_THAT_SETS_PREPROCESSOR_AND_ACTOR__NAME:
                single_instruction_setup(SUITE_CONF_INSTRUCTION_THAT_SETS_PREPROCESSOR_AND_ACTOR__NAME,
                                         suite_conf_instruction)

        }

        suite_conf_parser = configuration_section_parser(suite_conf_instructions)

        test_case_definition = test_case_definition_with_only_assert_phase_instructions([
            (
                ASSERT_PHASE_INSTRUCTION_THAT_PASS_IFF_STDOUT_IS_SUCCESS_INDICATOR_STRING__NAME,
                assert_phase_instruction_that_pass_iff_stdout_is_success_indicator_string(SUCCESS_INDICATOR_STRING)
            ),
            (
                ASSERT_PHASE_INSTRUCTION_THAT_FAILS_UNCONDITIONALLY__NAME,
                ASSERT_PHASE_INSTRUCTION_THAT_FAILS_UNCONDITIONALLY,
            ),
        ])
        processor = sut.Processor(test_case_definition,
                                  AtcOsProcessExecutorThatJustReturnsConstant(),
                                  suite_conf_parser)

        suite_file = File(
            suite_file_name,
            test_suite_source_with_single_conf_instruction(
                SUITE_CONF_INSTRUCTION_THAT_SETS_PREPROCESSOR_AND_ACTOR__NAME)
        )
        case_file = File(
            'test.case',
            test_case_source_with_single_assert_phase_instruction(
                ASSERT_PHASE_INSTRUCTION_THAT_FAILS_UNCONDITIONALLY__NAME)
        )

        sub_dir_path = Path('sub-dir')

        suite_and_case_files = DirContents([
            suite_file,
            case_file,
        ]).in_dir(str(sub_dir_path))

        explicit_suite_file_path = None
        if suite_file_overriding:
            explicit_suite_file_path = sub_dir_path / suite_file_overriding

        with tmp_dir_as_cwd(suite_and_case_files) as tmp_dir:
            execution_settings = TestCaseExecutionSettings(sub_dir_path / case_file.name_as_path,
                                                           tmp_dir / sub_dir_path,
                                                           ReportingOption.STATUS_CODE,
                                                           default_test_case_handling,
                                                           run_as_part_of_explicit_suite=explicit_suite_file_path)

            # ACT #
            actual_result = capture_output_from_processor(processor,
                                                          execution_settings)
        # ASSERT #
        if actual_result.exitcode != exit_values.EXECUTION__PASS.exit_code:
            self.fail(_error_message(actual_result))
예제 #10
0
from exactly_lib_test.common.test_resources.instruction_setup import single_instruction_setup
from exactly_lib_test.test_suite.test_resources.instructions import configuration_section_instruction_that

CONFIGURATION_SECTION_INSTRUCTIONS = {
    'test-suite-conf-instruction': single_instruction_setup('test-suite-conf-instruction',
                                                            configuration_section_instruction_that()),
}
예제 #11
0
    def _run(self,
             suite_file_name: str,
             suite_file_overriding: Optional[Path]):
        default_test_case_handling = setup_with_null_act_phase_and_null_preprocessing()

        suite_conf_instruction = SuiteConfInstructionThatSets(
            preprocessor=preprocessor_that_gives_const_source_with_single_assert_instruction(
                ASSERT_PHASE_INSTRUCTION_THAT_PASS_IFF_STDOUT_IS_SUCCESS_INDICATOR_STRING__NAME),
            act_phase_setup=act_setup_that_prints_single_string_on_stdout(SUCCESS_INDICATOR_STRING))

        suite_conf_instructions = {
            SUITE_CONF_INSTRUCTION_THAT_SETS_PREPROCESSOR_AND_ACTOR__NAME:
                single_instruction_setup(SUITE_CONF_INSTRUCTION_THAT_SETS_PREPROCESSOR_AND_ACTOR__NAME,
                                         suite_conf_instruction)

        }

        suite_conf_parser = configuration_section_parser(suite_conf_instructions)

        test_case_definition = test_case_definition_with_only_assert_phase_instructions([
            (
                ASSERT_PHASE_INSTRUCTION_THAT_PASS_IFF_STDOUT_IS_SUCCESS_INDICATOR_STRING__NAME,
                assert_phase_instruction_that_pass_iff_stdout_is_success_indicator_string(SUCCESS_INDICATOR_STRING)
            ),
            (
                ASSERT_PHASE_INSTRUCTION_THAT_FAILS_UNCONDITIONALLY__NAME,
                ASSERT_PHASE_INSTRUCTION_THAT_FAILS_UNCONDITIONALLY,
            ),
        ])
        processor = sut.Processor(test_case_definition,
                                  os_services_access.new_for_cmd_exe(CommandExecutorThatJustReturnsConstant()),
                                  suite_conf_parser,
                                  2 ** 10)

        suite_file = File(
            suite_file_name,
            test_suite_source_with_single_conf_instruction(
                SUITE_CONF_INSTRUCTION_THAT_SETS_PREPROCESSOR_AND_ACTOR__NAME)
        )
        case_file = File(
            'test.case',
            test_case_source_with_single_assert_phase_instruction(
                ASSERT_PHASE_INSTRUCTION_THAT_FAILS_UNCONDITIONALLY__NAME)
        )

        sub_dir_path = Path('sub-dir')

        suite_and_case_files = DirContents([
            suite_file,
            case_file,
        ]).in_dir(str(sub_dir_path))

        explicit_suite_file_path = None
        if suite_file_overriding:
            explicit_suite_file_path = sub_dir_path / suite_file_overriding

        with tmp_dir_as_cwd(suite_and_case_files) as tmp_dir:
            execution_settings = TestCaseExecutionSettings(sub_dir_path / case_file.name_as_path,
                                                           tmp_dir / sub_dir_path,
                                                           ReportingOption.STATUS_CODE,
                                                           default_test_case_handling,
                                                           run_as_part_of_explicit_suite=explicit_suite_file_path)

            # ACT #
            actual_result = capture_output_from_processor(processor,
                                                          execution_settings)
        # ASSERT #
        if actual_result.exitcode != exit_values.EXECUTION__PASS.exit_code:
            self.fail(_error_message(actual_result))
예제 #12
0
def instruction_item(instruction_name: str,
                     instruction: Instruction) -> (str, SingleInstructionSetup):
    return (instruction_name,
            single_instruction_setup(instruction_name,
                                     instruction))