-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_manager.py
87 lines (71 loc) · 4.29 KB
/
test_manager.py
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
85
86
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.
from pyiron_base._tests import TestWithProject
from pyiron_base import state
import os
class TestDatabaseManager(TestWithProject):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.dbm = state.database
cls.s = state.settings
def test_database_is_disabled(self):
self.assertEqual(self.s.configuration["disable_database"], self.dbm.database_is_disabled,
msg="Database manager should be initialized by settings.")
self.dbm._database_is_disabled = True
try:
self.assertNotEqual(self.s.configuration["disable_database"], self.dbm.database_is_disabled,
msg="But after that it should be independent from the settings")
finally:
self.dbm._database_is_disabled = False # Re-enable it at the end of the test
def test_file_top_path(self):
# Store settings
check_before = self.s.configuration["project_check_enabled"]
paths_before = list(self.s.configuration["project_paths"])
disable_before = self.s.configuration["disable_database"]
try:
new_root_path = self.s.convert_path_to_abs_posix(os.getcwd())
self.s.configuration["project_check_enabled"] = True
self.s.configuration["project_paths"] = [new_root_path]
self.s.configuration["disable_database"] = False
with self.subTest('enabled'):
# Otherwise has the chance to override project_check_enabled... Thus:
self.assertTrue(self.dbm.top_path(self.project_path + "/test") in self.project_path)
with self.subTest("enabled: test Project.root_path and Project.project_path for a new sub-Project"):
sub_pr = self.project.open('sub_project')
self.assertEqual(sub_pr.root_path, new_root_path + '/')
self.assertEqual(sub_pr.project_path,
os.path.join(os.path.relpath(self.project_path, os.getcwd()),
'sub_project').replace("\\", '/') + '/')
with self.subTest("enabled: path not in config"):
self.assertRaises(ValueError, self.dbm.top_path, os.path.abspath('..'))
self.s.configuration["project_check_enabled"] = False
with self.subTest('disabled'):
# Otherwise has the chance to override project_check_enabled... Thus:
self.assertTrue(self.dbm.top_path(self.project_path + "/test") in self.project_path)
with self.subTest("disabled: test Project.root_path and Project.project_path for a new sub-Project"):
sub_pr = self.project.open('sub_project')
self.assertEqual(sub_pr.root_path, new_root_path + '/')
self.assertEqual(sub_pr.project_path,
os.path.join(os.path.relpath(self.project_path, os.getcwd()),
'sub_project').replace("\\", '/') + '/')
with self.subTest("disabled: path not in config"):
self.assertIs(self.dbm.top_path(os.path.abspath('..')), None,
msg="Non-None top_path for path not in the config and project_check_enabled is False.")
self.s.configuration["project_paths"] = []
with self.subTest("test setting for old 'project_check_enabled is False' behavior"):
sub_pr = self.project.open('sub_project')
self.assertIs(sub_pr.root_path, None)
self.assertEqual(sub_pr.project_path, self.project_path + '/sub_project/')
finally:
# Put things back the way you found them
self.s.configuration["project_check_enabled"] = check_before
self.s.configuration["project_paths"] = paths_before
self.s.configuration["disable_database"] = disable_before
def test_update_project_coupling(self):
self.dbm.update()
self.assertIs(
self.dbm.database, self.project.db,
msg="Expected the database access instance to stay coupled between state and project."
)