forked from openml/openml-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_config.py
More file actions
57 lines (40 loc) · 2.47 KB
/
test_config.py
File metadata and controls
57 lines (40 loc) · 2.47 KB
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
# License: BSD 3-Clause
import os
import openml.config
import openml.testing
class TestConfig(openml.testing.TestBase):
def test_config_loading(self):
self.assertTrue(os.path.exists(openml.config.config_file))
self.assertTrue(os.path.isdir(os.path.expanduser('~/.openml')))
class TestConfigurationForExamples(openml.testing.TestBase):
def test_switch_to_example_configuration(self):
""" Verifies the test configuration is loaded properly. """
# Below is the default test key which would be used anyway, but just for clarity:
openml.config.apikey = "610344db6388d9ba34f6db45a3cf71de"
openml.config.server = self.production_server
openml.config.start_using_configuration_for_example()
self.assertEqual(openml.config.apikey, "c0c42819af31e706efe1f4b88c23c6c1")
self.assertEqual(openml.config.server, self.test_server)
def test_switch_from_example_configuration(self):
""" Verifies the previous configuration is loaded after stopping. """
# Below is the default test key which would be used anyway, but just for clarity:
openml.config.apikey = "610344db6388d9ba34f6db45a3cf71de"
openml.config.server = self.production_server
openml.config.start_using_configuration_for_example()
openml.config.stop_using_configuration_for_example()
self.assertEqual(openml.config.apikey, "610344db6388d9ba34f6db45a3cf71de")
self.assertEqual(openml.config.server, self.production_server)
def test_example_configuration_stop_before_start(self):
""" Verifies an error is raised is `stop_...` is called before `start_...`. """
error_regex = ".*stop_use_example_configuration.*start_use_example_configuration.*first"
self.assertRaisesRegex(RuntimeError, error_regex,
openml.config.stop_using_configuration_for_example)
def test_example_configuration_start_twice(self):
""" Checks that the original config can be returned to if `start..` is called twice. """
openml.config.apikey = "610344db6388d9ba34f6db45a3cf71de"
openml.config.server = self.production_server
openml.config.start_using_configuration_for_example()
openml.config.start_using_configuration_for_example()
openml.config.stop_using_configuration_for_example()
self.assertEqual(openml.config.apikey, "610344db6388d9ba34f6db45a3cf71de")
self.assertEqual(openml.config.server, self.production_server)