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_settings.py 2.2 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  1. import os
  2. import pytest
  3. from click.testing import CliRunner
  4. import wandb.util as util
  5. from wandb.settings import Settings
  6. from wandb import env
  7. def test_read_empty_settings():
  8. settings = Settings()
  9. assert settings.get(Settings.DEFAULT_SECTION, 'foo', fallback=None) is None
  10. def test_read_global_setting(global_wandb_settings):
  11. global_wandb_settings.write("[default]\nfoo = bar\n")
  12. global_wandb_settings.flush()
  13. settings = Settings()
  14. assert settings.get(Settings.DEFAULT_SECTION, 'foo') == 'bar'
  15. def test_read_local_setting(global_wandb_settings, local_wandb_settings):
  16. global_wandb_settings.write("[default]\nfoo = baz\n")
  17. global_wandb_settings.flush()
  18. local_wandb_settings.write("[default]\nfoo = bar\n")
  19. local_wandb_settings.flush()
  20. settings = Settings()
  21. assert settings.get(Settings.DEFAULT_SECTION, 'foo') == 'bar'
  22. def test_write_setting_globally(global_wandb_settings):
  23. settings = Settings()
  24. settings.set(Settings.DEFAULT_SECTION, 'foo', 'bar', globally=True)
  25. with open(global_wandb_settings.name, "r") as f:
  26. data = f.read()
  27. assert "[default]" in data
  28. assert "foo = bar" in data
  29. def test_write_setting_locally(local_wandb_settings):
  30. settings = Settings()
  31. settings.set(Settings.DEFAULT_SECTION, 'foo', 'bar')
  32. with open(local_wandb_settings.name, "r") as f:
  33. data = f.read()
  34. assert "[default]" in data
  35. assert "foo = bar" in data
  36. def test_items(global_wandb_settings, local_wandb_settings):
  37. global_wandb_settings.write("[default]\nfoo = baz\n")
  38. global_wandb_settings.flush()
  39. local_wandb_settings.write("[default]\nfoo = bar\n")
  40. local_wandb_settings.flush()
  41. settings = Settings()
  42. assert settings.items() == {
  43. 'section': Settings.DEFAULT_SECTION,
  44. 'foo': 'bar',
  45. }
  46. @pytest.fixture
  47. def global_wandb_settings(tmpdir):
  48. os.environ[env.CONFIG_DIR] = tmpdir.strpath
  49. with open(os.path.join(tmpdir.strpath, 'settings'), "w+") as f:
  50. yield f
  51. del os.environ[env.CONFIG_DIR]
  52. @pytest.fixture
  53. def local_wandb_settings():
  54. with CliRunner().isolated_filesystem():
  55. util.mkdir_exists_ok('wandb')
  56. with open(os.path.join('wandb', 'settings'), 'w+') as f:
  57. yield f
Tip!

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

Comments

Loading...