MCPcopy
hub / github.com/ray-project/ray / test_usage_stats_prompt

Function test_usage_stats_prompt

python/ray/_common/tests/test_usage_stats.py:510–663  ·  view source on GitHub ↗

Test usage stats prompt is shown in the proper cases.

(
    monkeypatch,
    capsys,
    tmp_path,
    reset_usage_stats,
    shutdown_only,
    clear_loggers,
    reset_ray_version_commit,
)

Source from the content-addressed store, hash-verified

508# test is terminated. It seems like loggers are shared across drivers
509# although we call ray.shutdown().
510def test_usage_stats_prompt(
511 monkeypatch,
512 capsys,
513 tmp_path,
514 reset_usage_stats,
515 shutdown_only,
516 clear_loggers,
517 reset_ray_version_commit,
518):
519 """
520 Test usage stats prompt is shown in the proper cases.
521 """
522 with monkeypatch.context() as m:
523 m.setenv("RAY_USAGE_STATS_ENABLED", "1")
524 m.setenv("RAY_USAGE_STATS_PROMPT_ENABLED", "0")
525 ray_usage_lib.show_usage_stats_prompt(cli=True)
526 captured = capsys.readouterr()
527 assert usage_constants.USAGE_STATS_ENABLED_FOR_CLI_MESSAGE not in captured.out
528 assert usage_constants.USAGE_STATS_ENABLED_FOR_CLI_MESSAGE not in captured.err
529
530 with monkeypatch.context() as m:
531 m.setenv("RAY_USAGE_STATS_ENABLED", "1")
532 m.setenv("RAY_USAGE_STATS_PROMPT_ENABLED", "0")
533 ray_usage_lib.show_usage_stats_prompt(cli=False)
534 captured = capsys.readouterr()
535 assert (
536 usage_constants.USAGE_STATS_ENABLED_FOR_RAY_INIT_MESSAGE not in captured.out
537 )
538 assert (
539 usage_constants.USAGE_STATS_ENABLED_FOR_RAY_INIT_MESSAGE not in captured.err
540 )
541
542 with monkeypatch.context() as m:
543 m.setenv("RAY_USAGE_STATS_ENABLED", "0")
544 ray_usage_lib.show_usage_stats_prompt(cli=True)
545 captured = capsys.readouterr()
546 assert usage_constants.USAGE_STATS_DISABLED_MESSAGE in captured.out
547
548 with monkeypatch.context() as m:
549 m.delenv("RAY_USAGE_STATS_ENABLED", raising=False)
550 tmp_usage_stats_config_path = tmp_path / "config1.json"
551 m.setenv("RAY_USAGE_STATS_CONFIG_PATH", str(tmp_usage_stats_config_path))
552 # Usage stats collection is enabled by default.
553 ray_usage_lib.show_usage_stats_prompt(cli=True)
554 captured = capsys.readouterr()
555 assert (
556 usage_constants.USAGE_STATS_ENABLED_BY_DEFAULT_FOR_CLI_MESSAGE
557 in captured.out
558 )
559
560 with monkeypatch.context() as m:
561 # Win impl relies on kbhit() instead of select()
562 # so the pipe trick won't work.
563 if sys.platform != "win32":
564 m.delenv("RAY_USAGE_STATS_ENABLED", raising=False)
565 saved_interactive = cli_logger.interactive
566 saved_stdin = sys.stdin
567 tmp_usage_stats_config_path = tmp_path / "config2.json"

Callers

nothing calls this directly

Calls 5

openFunction · 0.85
shutdownMethod · 0.65
contextMethod · 0.45
writeMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…