def act_setup_that_prints_single_string_on_stdout( string_to_print: str) -> ActPhaseSetup: return ActPhaseSetup( 'actor for constant ATC', ActorForConstantAtc( ActionToCheckThatRunsConstantActions( execute_initial_action=PrintStringOnStdout(string_to_print))))
def _settings_from_namespace( default: TestCaseHandlingSetup, default_sandbox_root_dir_name_resolver: SandboxRootDirNameResolver, namespace: argparse.Namespace) -> TestCaseExecutionSettings: output = ReportingOption.STATUS_CODE if namespace.act: output = ReportingOption.ACT_PHASE_OUTPUT elif namespace.keep: output = ReportingOption.SANDBOX_DIRECTORY_STRUCTURE_ROOT actor = resolve_actor_from_argparse_argument(default.actor, namespace.actor) preprocessor = _parse_preprocessor(default.preprocessor, namespace.preprocessor) actual_handling_setup = TestCaseHandlingSetup(ActPhaseSetup.of_nav(actor), preprocessor) test_case_file_path = pathlib.Path(namespace.file) suite_file = None if namespace.suite: suite_file = pathlib.Path(namespace.suite[0]) _resolve_and_fail_if_is_not_an_existing_file(suite_file) _resolve_and_fail_if_is_not_an_existing_file(test_case_file_path) return TestCaseExecutionSettings( test_case_file_path, _resolve_and_fail_if_is_not_an_existing_file( test_case_file_path.parent), output, actual_handling_setup, sandbox_root_dir_resolver=default_sandbox_root_dir_name_resolver, run_as_part_of_explicit_suite=suite_file)
def _new_processor( self, recording_media: List[Recording], test_case_processor_constructor: TestCaseProcessorConstructor ) -> sut.Processor: test_case_definition = TestCaseDefinition( TestCaseParsingSetup( space_separator_instruction_name_extractor, self._phase_config().instructions_setup( REGISTER_INSTRUCTION_NAME, recording_media), self._phase_config().act_phase_parser()), _predefined_properties.new_empty()) default_case_configuration = processors.Configuration( test_case_definition, TestCaseHandlingSetup( ActPhaseSetup('recording actor', self._phase_config().actor(recording_media)), 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_case_configuration, suite_hierarchy_reading.Reader( suite_hierarchy_reading.Environment( SectionElementParserThatRaisesUnrecognizedSectionElementSourceError( ), test_case_definition.parsing_setup, default_case_configuration.default_handling_setup)), ProcessingReporterThatDoesNothing(), enumeration.DepthFirstEnumerator(), test_case_processor_constructor, )
def main_program_config( actor: Optional[Actor] = None, builtin_symbols: Sequence[BuiltinSymbol] = (), ) -> MainProgramConfig: if actor is None: actor = _ActorThatParsesReferences(REF_INSTRUCTION_NAME) return main_program_execution.main_program_config( test_case_definition_for(INSTRUCTION_SETUP, builtin_symbols), act_phase_setup=ActPhaseSetup('the actor', actor))
def _execution_settings( self, namespace: argparse.Namespace) -> TestSuiteExecutionSettings: actor = resolve_actor_from_argparse_argument(self.default.actor, namespace.actor) suite_file_path = self._resolve_file_path(namespace.file) return TestSuiteExecutionSettings( self._resolve_reporter(vars(namespace)), TestCaseHandlingSetup(ActPhaseSetup.of_nav(actor), self.default.preprocessor), suite_file_path, )
def main_program_config( tc_definition: TestCaseDefinitionForMainProgram, test_suite_definition: TestSuiteDefinition = test_suite_definition_without_instructions(), act_phase_setup: ActPhaseSetup = ActPhaseSetup( 'actor that runs constant actions', ActorThatRunsConstantActions()), ) -> MainProgramConfig: return MainProgramConfig( TestCaseHandlingSetup(act_phase_setup, IDENTITY_PREPROCESSOR), tc_definition, test_suite_definition, )
def _check( put: unittest.TestCase, test_case_definition: TestCaseDefinitionForMainProgram, actor: Actor, test_case_source: str, mk_sds_resolver: Callable[[str], SandboxRootDirNameResolver], expectation: Expectation, ): # ARRANGE # case_file = File('the-test.case', test_case_source) source_files_dir_contents = DirContents([case_file]) tc_handling_setup = TestCaseHandlingSetup( ActPhaseSetup('the actor', actor), IDENTITY_PREPROCESSOR) test_suite_definition = test_suite_definition_without_instructions() command_line_arguments = [ OPTION_FOR_KEEPING_SANDBOX_DIRECTORY, case_file.name, ] # ACT # with tempfile.TemporaryDirectory() as dir_name: dir_name = resolved_path_name(dir_name) main_pgm = main_program_of( test_case_definition, test_suite_definition, tc_handling_setup, sandbox_root_dir_name_resolver=mk_sds_resolver(dir_name)) actual_result = capture_output_from_main_program__in_tmp_dir( command_line_arguments, source_files_dir_contents, main_pgm) # ASSERT # put.assertEqual(expectation.exit_vale.exit_code, actual_result.exitcode, 'exit code') dir_and_stdout_assertion = expectation.output_assertion_for_sds_dir_name( dir_name) dir_and_stdout_assertion.apply_with_message(put, actual_result.stdout, 'dir and stdout') first_line_should_be_exit_identifier(put, actual_result.stderr, expectation.exit_vale)
def setup() -> TestCaseHandlingSetup: return TestCaseHandlingSetup( ActPhaseSetup(actors.COMMAND_LINE_ACTOR.singular_name, TheActor()), IdentityPreprocessor())
def command_line_actor_setup() -> ActPhaseSetup: return ActPhaseSetup(actors.COMMAND_LINE_ACTOR.singular_name, command_line_actor.actor())
def act_setup_that_does_nothing() -> ActPhaseSetup: return ActPhaseSetup( 'actor that does nothing', ActorForConstantAtc(ActionToCheckThatRunsConstantActions()))
def test_case_handling_setup_with_identity_preprocessor( ) -> TestCaseHandlingSetup: return TestCaseHandlingSetup( ActPhaseSetup('actor that does nothing', ActorThatRunsConstantActions()), IDENTITY_PREPROCESSOR)
def parse(self, fs_location_info: FileSystemLocationInfo, source: ParseSource, ) -> ConfigurationSectionInstruction: actor = actor_utils.parse(source) return Instruction(ActPhaseSetup.of_nav(actor))
def act_phase_setup_for_reference_instruction() -> ActPhaseSetup: return ActPhaseSetup('actor that runs constant actions', ActorThatRunsConstantActions())