Ejemplo n.º 1
0
def new_processor(
        setup_phase_instructions: Dict[str, InstructionParser],
        test_case_processor_constructor: TestCaseProcessorConstructor,
        predefined_properties: PredefinedProperties) -> sut.Processor:
    test_case_definition = TestCaseDefinition(
        TestCaseParsingSetup(space_separator_instruction_name_extractor,
                             instruction_setup(setup_phase_instructions),
                             ActPhaseParser()), predefined_properties)
    default_configuration = processors.Configuration(
        test_case_definition,
        test_case_handling_setup_with_identity_preprocessor(),
        os_services_access.new_for_current_os(), 2**10, False,
        sandbox_dir_resolving.mk_tmp_dir_with_prefix('test-suite-'))

    return sut.Processor(
        default_configuration,
        suite_hierarchy_reading.Reader(
            suite_hierarchy_reading.Environment(
                SectionElementParserThatRaisesRecognizedSectionElementSourceError(
                ), test_case_definition.parsing_setup,
                default_configuration.default_handling_setup)),
        ExecutionTracingProcessingReporter(),
        enumeration.DepthFirstEnumerator(),
        test_case_processor_constructor,
    )
Ejemplo n.º 2
0
def test_case_definition_for(
    instructions_set: InstructionsSetup,
    builtin_symbols: Sequence[BuiltinSymbol] = ()
) -> TestCaseDefinitionForMainProgram:
    return TestCaseDefinitionForMainProgram(
        TestCaseParsingSetup(space_separator_instruction_name_extractor,
                             instructions_set, ActPhaseParser()),
        list(builtin_symbols))
Ejemplo n.º 3
0
def default_environment() -> Environment:
    return Environment(
        test_suite.new_parser(),
        TestCaseParsingSetup(white_space_name_and_argument_splitter,
                             instruction_set_with_no_instructions(),
                             ActPhaseParser()),
        TestCaseHandlingSetup(command_line_actor_setup(),
                              IDENTITY_PREPROCESSOR))
    def _run(self, test_case_runner: TestCaseRunner, suite_file_name: str,
             suite_file_overriding: Optional[Path]):
        # ARRANGE #

        expected_instruction_recording = [
            # First test case
            SETUP_INSTRUCTION_IN_CONTAINING_SUITE,
            SETUP_INSTRUCTION_IN_CASE,
        ]

        suite_file = File(
            suite_file_name,
            SUITE_WITH_SETUP_INSTRUCTION.format(
                marker=SETUP_INSTRUCTION_IN_CONTAINING_SUITE))

        case_file = File(
            'test.case',
            CASE_THAT_REGISTERS_MARKER.format(
                marker=SETUP_INSTRUCTION_IN_CASE))

        sub_dir_path = Path('dir-containing-test-case')

        suite_and_case_files = DirContents([
            suite_file,
            case_file,
        ])

        explicit_suite_file_path = None
        if suite_file_overriding:
            explicit_suite_file_path = sub_dir_path / suite_file_overriding

        recording_media = []

        test_case_parsing_setup = TestCaseParsingSetup(
            space_separator_instruction_name_extractor,
            instruction_setup_with_setup_instructions(
                REGISTER_INSTRUCTION_NAME, recording_media), ActPhaseParser())
        test_case_handling_setup = test_case_handling_setup_with_identity_preprocessor(
        )

        test_suite_definition = test_suite_definition_without_instructions()
        # ACT #
        with tmp_dir_as_cwd(suite_and_case_files.in_dir_path(sub_dir_path)):
            actual_result = test_case_runner.run(
                test_case_parsing_setup, test_case_handling_setup,
                test_suite_definition, sub_dir_path / case_file.name_as_path,
                explicit_suite_file_path)
        # ASSERT #

        self.assertEqual(exit_values.EXECUTION__PASS.exit_code,
                         actual_result.exitcode,
                         'Sanity check of result indicator')

        recordings = list(map(Recording.string.fget, recording_media))
        self.assertEqual(expected_instruction_recording, recordings)
def default_main_program() -> main_program.MainProgram:
    return main_program.MainProgram(
        test_case_handling_setup.setup(),
        sandbox_dir_resolving.mk_tmp_dir_with_prefix(
            program_info.PROGRAM_NAME + '-'),
        TestCaseDefinitionForMainProgram(
            TestCaseParsingSetup(
                instruction_name_and_argument_splitter.splitter,
                default_instructions_setup.INSTRUCTIONS_SETUP,
                ActPhaseParser()),
            builtin_symbols.ALL,
        ), test_suite.test_suite_definition(), io.DEFAULT_BUFFER_SIZE)
Ejemplo n.º 6
0
def configuration_for_instruction_set(
        instruction_set: InstructionsSetup) -> sut.Configuration:
    tc_parsing_setup = TestCaseParsingSetup(
        first_space_separated_string_extractor, instruction_set,
        ActPhaseParser())
    tc_definition = TestCaseDefinition(tc_parsing_setup,
                                       _predefined_properties.new_empty())
    tc_handling_setup = setup_with_null_act_phase_and_null_preprocessing()
    return sut.Configuration(
        tc_definition,
        tc_handling_setup,
        os_services_access.new_for_current_os(),
        2**10,
        is_keep_sandbox=False,
    )
Ejemplo n.º 7
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=[])
Ejemplo n.º 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()),
        predefined_properties.new_empty(),
    )
Ejemplo n.º 9
0
def execute_main_program(
    arguments: List[str],
    the_test_case_handling_setup: TestCaseHandlingSetup,
    instructions_setup: InstructionsSetup = EMPTY_INSTRUCTIONS_SETUP,
    name_and_argument_splitter=first_char_is_name_and_rest_is_argument__splitter,
    builtin_symbols: Sequence[BuiltinSymbol] = (),
    test_suite_def: TestSuiteDefinition = test_suite_definition()
) -> SubProcessResult:
    program = main_program.MainProgram(
        the_test_case_handling_setup, sandbox_root_name_resolver.for_test(),
        TestCaseDefinitionForMainProgram(
            TestCaseParsingSetup(name_and_argument_splitter,
                                 instructions_setup, ActPhaseParser()),
            list(builtin_symbols),
        ), test_suite_def, 2**10)

    def action_with_stdout_files(stdout_files: StdOutputFiles) -> int:
        return program.execute(arguments, stdout_files)

    std_out_files, exit_code = capture_stdout_err(action_with_stdout_files)
    return SubProcessResult(exit_code, std_out_files.out, std_out_files.err)
Ejemplo n.º 10
0
def parsing_setup_with_no_instructions() -> TestCaseParsingSetup:
    return TestCaseParsingSetup(lambda x: '',
                                instruction_set_with_no_instructions(),
                                ActPhaseParser())
Ejemplo n.º 11
0
            hierarchy_reader, reporter, DepthFirstEnumerator(),
            case_processing.
            new_processor_that_is_allowed_to_pollute_current_process)
        exit_code = processor.process(setup.root_suite_based_at(tmp_dir_path),
                                      null_output_reporting_environment())
        setup.assertions(put, reporter.complete_suite_reporter, exit_code)


def _default_case_configuration(
    test_case_handling_setup: TestCaseHandlingSetup
) -> case_processing.Configuration:
    return case_processing.Configuration(
        _DEFAULT_TEST_CASE_DEFINITION, test_case_handling_setup,
        os_services_access.new_for_current_os(), 2**10, False)


def white_space_name_and_argument_splitter(s: str) -> str:
    return s.split()[0]


INSTRUCTION_SETUP = instruction_set_with_no_instructions()

_TEST_CASE_PARSING_SETUP = TestCaseParsingSetup(
    white_space_name_and_argument_splitter, INSTRUCTION_SETUP,
    ActPhaseParser())

_DEFAULT_TEST_CASE_DEFINITION = TestCaseDefinition(
    _TEST_CASE_PARSING_SETUP,
    _predefined_properties.new_empty(),
)
Ejemplo n.º 12
0
 def act_phase_parser(self) -> SectionElementParser:
     return ActPhaseParser()