Exemple #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)
 def __init__(
     self,
     main_program_config: MainProgramConfig = main_program_execution.
     main_program_config(test_case_definition_for(InstructionsSetup())),
     cwd_contents: DirContents = DirContents([])):
     self.main_program_config = main_program_config
     self.cwd_contents = cwd_contents
def test_case_definition_with_config_phase_assertion_instruction(
    put: unittest.TestCase,
    hds_dir_assertion: Assertion[Path],
) -> TestCaseDefinitionForMainProgram:
    return test_case_definition_for(
        InstructionsSetup(
            config_instruction_set={
                INSTR_THAT_ASSERTS_HDS_DIR_MATCHES_PATH:
                single_instruction_setup_for_parser(
                    INSTR_THAT_ASSERTS_HDS_DIR_MATCHES_PATH,
                    ConfigPhaseInstructionParserThatAssertsSourceFileLocationInfo(
                        put, hds_dir_assertion))
            }))
Exemple #4
0
def configuration_with_assert_instruction_that_fails(
        instruction_name: str) -> sut.Configuration:
    assert_instruction_setup = instr_setup(
        instr.assert_phase_instruction_that(
            main=do_return(pfh.new_pfh_fail__str('fail error message'))))

    instruction_set = InstructionsSetup(
        config_instruction_set={},
        setup_instruction_set={},
        before_assert_instruction_set={},
        assert_instruction_set={instruction_name: assert_instruction_setup},
        cleanup_instruction_set={},
    )
    return configuration_for_instruction_set(instruction_set)
Exemple #5
0
def test_case_definition_with_setup_phase_assertion_instruction(
    put: unittest.TestCase,
    expected_default: Optional[Dict[str, str]],
    expected_from_defaults_getter: Dict[str, str],
) -> TestCaseDefinitionForMainProgram:
    return test_case_definition_for(
        InstructionsSetup(
            setup_instruction_set={
                INSTR_THAT_ASSERTS_ENV_VARS:
                single_instruction_setup_for_parser(
                    INSTR_THAT_ASSERTS_ENV_VARS,
                    SetupPhaseInstructionParserThatAssertsEnvVars(
                        put, expected_default, expected_from_defaults_getter))
            }))
def test_case_definition_with_config_phase_assertion_instruction(
        put: unittest.TestCase,
        instruction_parser_file_loc_assertion: Assertion[FileLocationInfo],
) -> TestCaseDefinitionForMainProgram:
    return test_case_definition_for(
        InstructionsSetup(
            config_instruction_set={
                INSTR_THAT_ASSERTS_SOURCE_INFO_MATCHES_LOCATION: single_instruction_setup_for_parser(
                    INSTR_THAT_ASSERTS_SOURCE_INFO_MATCHES_LOCATION,
                    ConfigPhaseInstructionParserThatAssertsSourceFileLocationInfo(
                        put,
                        instruction_parser_file_loc_assertion))
            })
    )
def check_without_files(
    put: unittest.TestCase,
    command_line_arguments: List[str],
    expectation: Assertion[SubProcessResult],
    main_program_config: MainProgramConfig = main_program_execution.
    main_program_config(test_case_definition_for(InstructionsSetup())),
):
    # ARRANGE #
    main_program = main_program_from_config(main_program_config)
    # ACT #
    result = capture_output_from_main_program(command_line_arguments,
                                              main_program)
    # ASSERT #
    expectation.apply_without_message(put, result)
def instruction_set() -> InstructionsSetup:
    return InstructionsSetup(
        config_instruction_set=dict(
            [instruction_item('conf_instruction',
                              instr.configuration_phase_instruction_that())]),
        setup_instruction_set=dict(
            [instruction_item('setup_instruction',
                              instr.setup_phase_instruction_that())]),
        before_assert_instruction_set=dict(
            [instruction_item('before_assert_instruction',
                              instr.before_assert_phase_instruction_that())]),
        assert_instruction_set=dict(
            [instruction_item('assert_instruction',
                              instr.assert_phase_instruction_that())]),
        cleanup_instruction_set=dict(
            [instruction_item('cleanup_instruction',
                              instr.cleanup_phase_instruction_that())]),
    )
Exemple #9
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=[])
Exemple #10
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(),
    )
 def _when_syntax_error_in_case_phase_contents_then_suite_parsing_should_raise_exception(
         self):
     # ARRANGE #
     suite_file = File(
         'the.suite',
         SUITE_WITH_SYNTAX_ERROR_IN_CASE_PHASE.format(
             case_phase_header=self._phase_config().phase_name().syntax))
     cwd_contents = DirContents([suite_file])
     tc_parsing_setup = TestCaseParsingSetup(
         space_separator_instruction_name_extractor, InstructionsSetup(),
         SectionElementParserThatRaisesUnrecognizedSectionElementSourceError(
         ))
     tc_handling_setup = setup_with_null_act_phase_and_null_preprocessing()
     reader = suite_hierarchy_reading.Reader(
         suite_hierarchy_reading.Environment(
             SectionElementParserThatRaisesUnrecognizedSectionElementSourceError(
             ), tc_parsing_setup, tc_handling_setup))
     with self.assertRaises(SuiteParseError):
         with tmp_dir_as_cwd(cwd_contents):
             # ACT & ASSERT #
             reader.apply(suite_file.name_as_path)
Exemple #12
0
def configuration_with_instruction_in_each_phase_with_failing_validation(
        instruction_name: str) -> sut.Configuration:
    instr_setup_factory = InstructionWithFailingValidationFactory()
    instruction_set = InstructionsSetup(
        config_instruction_set={
            instruction_name: instr_setup_factory.conf_instr_setup()
        },
        setup_instruction_set={
            instruction_name: instr_setup_factory.setup_instr_setup()
        },
        before_assert_instruction_set={
            instruction_name: instr_setup_factory.before_assert_instr_setup()
        },
        assert_instruction_set={
            instruction_name: instr_setup_factory.assert_instr_setup()
        },
        cleanup_instruction_set={
            instruction_name: instr_setup_factory.cleanup_instr_setup()
        },
    )
    return configuration_for_instruction_set(instruction_set)
Exemple #13
0
def configuration_with_instruction_in_each_phase_with_internal_error(
        instruction_name: str) -> sut.Configuration:
    instr_setup_factory = InstructionWithImplementationErrorFactory()
    instruction_set = InstructionsSetup(
        config_instruction_set={
            instruction_name: instr_setup_factory.conf_instr_setup()
        },
        setup_instruction_set={
            instruction_name: instr_setup_factory.setup_instr_setup()
        },
        before_assert_instruction_set={
            instruction_name: instr_setup_factory.before_assert_instr_setup()
        },
        assert_instruction_set={
            instruction_name: instr_setup_factory.assert_instr_setup()
        },
        cleanup_instruction_set={
            instruction_name: instr_setup_factory.cleanup_instr_setup()
        },
    )
    return configuration_for_instruction_set(instruction_set)
Exemple #14
0
def configuration_with_instruction_in_each_phase_that_records_phase_name(
        instruction_name: str,
        recording_output: List[str]) -> sut.Configuration:
    instr_setup_factory = PhaseRecordingInstructionFactory(recording_output)
    instruction_set = InstructionsSetup(
        config_instruction_set={
            instruction_name: instr_setup_factory.conf_instr_setup()
        },
        setup_instruction_set={
            instruction_name: instr_setup_factory.setup_instr_setup()
        },
        before_assert_instruction_set={
            instruction_name: instr_setup_factory.before_assert_instr_setup()
        },
        assert_instruction_set={
            instruction_name: instr_setup_factory.assert_instr_setup()
        },
        cleanup_instruction_set={
            instruction_name: instr_setup_factory.cleanup_instr_setup()
        },
    )
    return configuration_for_instruction_set(instruction_set)
Exemple #15
0
from exactly_lib.cli_default.program_modes.test_case.phases import \
    assert_, \
    before_assert, \
    cleanup, \
    configuration, \
    setup
from exactly_lib.processing.instruction_setup import InstructionsSetup

INSTRUCTIONS_SETUP = InstructionsSetup(configuration.INSTRUCTIONS,
                                       setup.INSTRUCTIONS,
                                       before_assert.INSTRUCTIONS,
                                       assert_.INSTRUCTIONS,
                                       cleanup.INSTRUCTIONS)
Exemple #16
0
def instruction_set_with_no_instructions() -> InstructionsSetup:
    return InstructionsSetup({}, {}, {}, {}, {})
INSTRUCTION_SETUP = InstructionsSetup(
    config_instruction_set={
        SET_ACTOR_THAT_PARSES_REFERENCES_INSTRUCTION_NAME:
        _setup_for_actor_that_parses_references(
            SET_ACTOR_THAT_PARSES_REFERENCES_INSTRUCTION_NAME),
        UNCONDITIONALLY_HARD_ERROR_CONF_PHASE_INSTRUCTION_NAME:
        _setup_hard_error_conf_phase_instruction(
            UNCONDITIONALLY_HARD_ERROR_CONF_PHASE_INSTRUCTION_NAME),
    },
    setup_instruction_set={
        DEF_INSTRUCTION_NAME:
        define_symbol__setup.setup(DEF_INSTRUCTION_NAME),
        REF_INSTRUCTION_NAME:
        _ref_instruction_setup(
            REF_INSTRUCTION_NAME, lambda usages: instrs.
            setup_phase_instruction_that(symbol_usages=do_return(usages))),
    },
    before_assert_instruction_set={
        DEF_INSTRUCTION_NAME:
        define_symbol__before_assert.setup(DEF_INSTRUCTION_NAME),
        REF_INSTRUCTION_NAME:
        _ref_instruction_setup(
            REF_INSTRUCTION_NAME,
            lambda usages: instrs.before_assert_phase_instruction_that(
                symbol_usages=do_return(usages))),
    },
    assert_instruction_set={
        DEF_INSTRUCTION_NAME:
        define_symbol__assert.setup(DEF_INSTRUCTION_NAME),
        REF_INSTRUCTION_NAME:
        _ref_instruction_setup(
            REF_INSTRUCTION_NAME, lambda usages: instrs.
            assert_phase_instruction_that(symbol_usages=do_return(usages))),
    },
    cleanup_instruction_set={
        DEF_INSTRUCTION_NAME:
        define_symbol__cleanup.setup(DEF_INSTRUCTION_NAME),
        REF_INSTRUCTION_NAME:
        _ref_instruction_setup(
            REF_INSTRUCTION_NAME, lambda usages: instrs.
            cleanup_phase_instruction_that(symbol_usages=do_return(usages))),
    },
)
Exemple #18
0
def mk_instruction_set_for_setup_phase(instructions: Dict[str, SingleInstructionSetup]) -> InstructionsSetup:
    return InstructionsSetup(setup_instruction_set=instructions)
def instruction_setup(setup_phase_instructions: Dict[str, InstructionParser]) -> InstructionsSetup:
    return InstructionsSetup({},
                             {name: SingleInstructionSetup(parser,
                                                           instruction_documentation('name-of-instruction'))
                              for name, parser in setup_phase_instructions.items()},
                             {}, {}, {})
Exemple #20
0
 def mk_instruction_set_for_phase(self, instructions: Dict[str, SingleInstructionSetup]) -> InstructionsSetup:
     return InstructionsSetup(assert_instruction_set=instructions)
Exemple #21
0
 def instructions_setup(
         self, register_instruction_name: str,
         recording_media: List[Recording]) -> InstructionsSetup:
     return InstructionsSetup()