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

hydra_resolvers_test.py 1.3 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 unittest
  2. from omegaconf import OmegaConf
  3. from super_gradients.common.environment.env_helpers import register_hydra_resolvers
  4. class HydraResolversTest(unittest.TestCase):
  5. def setUp(self) -> None:
  6. register_hydra_resolvers()
  7. def test_add(self):
  8. conf = OmegaConf.create({
  9. "a": 1,
  10. "b": 2,
  11. "c": 3,
  12. "a_plus_b": "${add: ${a},${b}}",
  13. "a_plus_b_plus_c": "${add: ${a}, ${b}, ${c}}"
  14. })
  15. assert conf["a_plus_b"] == 3
  16. assert conf["a_plus_b_plus_c"] == 6
  17. def test_list(self):
  18. conf = OmegaConf.create({
  19. "my_list": [10, 20, 30, 40, 50],
  20. "third_of_list": "${getitem: ${my_list}, 2}",
  21. "first_of_list": "${first: ${my_list}}",
  22. "last_of_list": "${last: ${my_list}}",
  23. })
  24. self.assertEqual(conf["third_of_list"], 30)
  25. self.assertEqual(conf["first_of_list"], 10)
  26. self.assertEqual(conf["last_of_list"], 50)
  27. def test_cond(self):
  28. conf = OmegaConf.create({
  29. "boolean": True,
  30. "a": "red_pill",
  31. "b": "blue_pill",
  32. "result": "${cond:${boolean}, ${a}, ${b}}",
  33. })
  34. assert conf["result"] == "red_pill"
  35. conf["boolean"] = False
  36. assert conf["result"] == "blue_pill"
Tip!

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

Comments

Loading...