Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_run_manager.py 1.8 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  1. import datetime
  2. import io
  3. import wandb.run_manager
  4. from wandb.apis import internal
  5. from wandb.wandb_run import Run
  6. def test_check_update_available_equal(request_mocker, capsys):
  7. "Test update availability in different cases."
  8. test_cases = [
  9. ('0.8.10', '0.8.10', False),
  10. ('0.8.9', '0.8.10', True),
  11. ('0.8.11', '0.8.10', False),
  12. ('1.0.0', '2.0.0', True),
  13. ('0.4.5', '0.4.5a5', False),
  14. ('0.4.5', '0.4.3b2', False),
  15. ('0.4.5', '0.4.6b2', True),
  16. ('0.4.5.alpha', '0.4.4', False),
  17. ('0.4.5.alpha', '0.4.5', True),
  18. ('0.4.5.alpha', '0.4.6', True)
  19. ]
  20. for current, latest, is_expected in test_cases:
  21. is_avail = _is_update_avail(request_mocker, capsys, current, latest)
  22. assert is_avail == is_expected, "expected %s compared to %s to yield update availability of %s" % (current, latest, is_expected)
  23. def _is_update_avail(request_mocker, capsys, current, latest):
  24. "Set up the run manager and detect if the upgrade message is printed."
  25. api = internal.Api(
  26. load_settings=False,
  27. retry_timedelta=datetime.timedelta(0, 0, 50))
  28. api.set_current_run_id(123)
  29. run = Run()
  30. run_manager = wandb.run_manager.RunManager(api, run)
  31. # Without this mocking, during other tests, the _check_update_available
  32. # function will throw a "mock not found" error, then silently fail without
  33. # output (just like it would in a normal network failure).
  34. response = b'{ "info": { "version": "%s" } }' % bytearray(latest, 'utf-8')
  35. request_mocker.register_uri('GET', 'https://pypi.org/pypi/wandb/json',
  36. content=response, status_code=200)
  37. run_manager._check_update_available(current)
  38. captured_out, captured_err = capsys.readouterr()
  39. print(captured_out, captured_err)
  40. return "To upgrade, please run:" in captured_err
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...