def assert_config_read_correctly( options_bootstrapper: OptionsBootstrapper, *, expected_worker_count: int, ) -> None: options = options_bootstrapper.full_options_for_scopes( known_scope_infos=[ ScopeInfo(""), ScopeInfo("compile_apt"), ScopeInfo("fruit"), ], ) # So we don't choke on these on the cmd line. options.register("", "--pants-config-files", type=list) options.register("", "--config-override", type=list) options.register("compile_apt", "--worker-count") options.register("fruit", "--apple") self.assertEqual(str(expected_worker_count), options.for_scope("compile_apt").worker_count) self.assertEqual("red", options.for_scope("fruit").apple)
def mock_console( options_bootstrapper: OptionsBootstrapper, *, stdin_content: bytes | str | None = None, ) -> Iterator[tuple[Console, StdioReader]]: global_bootstrap_options = options_bootstrapper.bootstrap_options.for_global_scope( ) colors = (options_bootstrapper.full_options_for_scopes( [GlobalOptions.get_scope_info()], allow_unknown_options=True).for_global_scope().colors) with initialize_stdio(global_bootstrap_options), stdin_context( stdin_content) as stdin, temporary_file( binary_mode=False) as stdout, temporary_file( binary_mode=False) as stderr, stdio_destination( stdin_fileno=stdin.fileno(), stdout_fileno=stdout.fileno(), stderr_fileno=stderr.fileno(), ): # NB: We yield a Console without overriding the destination argument, because we have # already done a sys.std* level replacement. The replacement is necessary in order for # InteractiveProcess to have native file handles to interact with. yield Console(use_colors=colors), StdioReader( _stdout=Path(stdout.name), _stderr=Path(stderr.name))