summaryrefslogtreecommitdiffstats
path: root/tests/test_git_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_git_config.py')
-rw-r--r--tests/test_git_config.py318
1 files changed, 160 insertions, 158 deletions
diff --git a/tests/test_git_config.py b/tests/test_git_config.py
index 3b0aa8b4..a44dca0f 100644
--- a/tests/test_git_config.py
+++ b/tests/test_git_config.py
@@ -22,167 +22,169 @@ import git_config
22 22
23 23
24def fixture(*paths): 24def fixture(*paths):
25 """Return a path relative to test/fixtures. 25 """Return a path relative to test/fixtures."""
26 """ 26 return os.path.join(os.path.dirname(__file__), "fixtures", *paths)
27 return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
28 27
29 28
30class GitConfigReadOnlyTests(unittest.TestCase): 29class GitConfigReadOnlyTests(unittest.TestCase):
31 """Read-only tests of the GitConfig class.""" 30 """Read-only tests of the GitConfig class."""
32 31
33 def setUp(self): 32 def setUp(self):
34 """Create a GitConfig object using the test.gitconfig fixture. 33 """Create a GitConfig object using the test.gitconfig fixture."""
35 """ 34 config_fixture = fixture("test.gitconfig")
36 config_fixture = fixture('test.gitconfig') 35 self.config = git_config.GitConfig(config_fixture)
37 self.config = git_config.GitConfig(config_fixture) 36
38 37 def test_GetString_with_empty_config_values(self):
39 def test_GetString_with_empty_config_values(self): 38 """
40 """ 39 Test config entries with no value.
41 Test config entries with no value. 40
42 41 [section]
43 [section] 42 empty
44 empty 43
45 44 """
46 """ 45 val = self.config.GetString("section.empty")
47 val = self.config.GetString('section.empty') 46 self.assertEqual(val, None)
48 self.assertEqual(val, None) 47
49 48 def test_GetString_with_true_value(self):
50 def test_GetString_with_true_value(self): 49 """
51 """ 50 Test config entries with a string value.
52 Test config entries with a string value. 51
53 52 [section]
54 [section] 53 nonempty = true
55 nonempty = true 54
56 55 """
57 """ 56 val = self.config.GetString("section.nonempty")
58 val = self.config.GetString('section.nonempty') 57 self.assertEqual(val, "true")
59 self.assertEqual(val, 'true') 58
60 59 def test_GetString_from_missing_file(self):
61 def test_GetString_from_missing_file(self): 60 """
62 """ 61 Test missing config file
63 Test missing config file 62 """
64 """ 63 config_fixture = fixture("not.present.gitconfig")
65 config_fixture = fixture('not.present.gitconfig') 64 config = git_config.GitConfig(config_fixture)
66 config = git_config.GitConfig(config_fixture) 65 val = config.GetString("empty")
67 val = config.GetString('empty') 66 self.assertEqual(val, None)
68 self.assertEqual(val, None) 67
69 68 def test_GetBoolean_undefined(self):
70 def test_GetBoolean_undefined(self): 69 """Test GetBoolean on key that doesn't exist."""
71 """Test GetBoolean on key that doesn't exist.""" 70 self.assertIsNone(self.config.GetBoolean("section.missing"))
72 self.assertIsNone(self.config.GetBoolean('section.missing')) 71
73 72 def test_GetBoolean_invalid(self):
74 def test_GetBoolean_invalid(self): 73 """Test GetBoolean on invalid boolean value."""
75 """Test GetBoolean on invalid boolean value.""" 74 self.assertIsNone(self.config.GetBoolean("section.boolinvalid"))
76 self.assertIsNone(self.config.GetBoolean('section.boolinvalid')) 75
77 76 def test_GetBoolean_true(self):
78 def test_GetBoolean_true(self): 77 """Test GetBoolean on valid true boolean."""
79 """Test GetBoolean on valid true boolean.""" 78 self.assertTrue(self.config.GetBoolean("section.booltrue"))
80 self.assertTrue(self.config.GetBoolean('section.booltrue')) 79
81 80 def test_GetBoolean_false(self):
82 def test_GetBoolean_false(self): 81 """Test GetBoolean on valid false boolean."""
83 """Test GetBoolean on valid false boolean.""" 82 self.assertFalse(self.config.GetBoolean("section.boolfalse"))
84 self.assertFalse(self.config.GetBoolean('section.boolfalse')) 83
85 84 def test_GetInt_undefined(self):
86 def test_GetInt_undefined(self): 85 """Test GetInt on key that doesn't exist."""
87 """Test GetInt on key that doesn't exist.""" 86 self.assertIsNone(self.config.GetInt("section.missing"))
88 self.assertIsNone(self.config.GetInt('section.missing')) 87
89 88 def test_GetInt_invalid(self):
90 def test_GetInt_invalid(self): 89 """Test GetInt on invalid integer value."""
91 """Test GetInt on invalid integer value.""" 90 self.assertIsNone(self.config.GetBoolean("section.intinvalid"))
92 self.assertIsNone(self.config.GetBoolean('section.intinvalid')) 91
93 92 def test_GetInt_valid(self):
94 def test_GetInt_valid(self): 93 """Test GetInt on valid integers."""
95 """Test GetInt on valid integers.""" 94 TESTS = (
96 TESTS = ( 95 ("inthex", 16),
97 ('inthex', 16), 96 ("inthexk", 16384),
98 ('inthexk', 16384), 97 ("int", 10),
99 ('int', 10), 98 ("intk", 10240),
100 ('intk', 10240), 99 ("intm", 10485760),
101 ('intm', 10485760), 100 ("intg", 10737418240),
102 ('intg', 10737418240), 101 )
103 ) 102 for key, value in TESTS:
104 for key, value in TESTS: 103 self.assertEqual(value, self.config.GetInt("section.%s" % (key,)))
105 self.assertEqual(value, self.config.GetInt('section.%s' % (key,)))
106 104
107 105
108class GitConfigReadWriteTests(unittest.TestCase): 106class GitConfigReadWriteTests(unittest.TestCase):
109 """Read/write tests of the GitConfig class.""" 107 """Read/write tests of the GitConfig class."""
110 108
111 def setUp(self): 109 def setUp(self):
112 self.tmpfile = tempfile.NamedTemporaryFile() 110 self.tmpfile = tempfile.NamedTemporaryFile()
113 self.config = self.get_config() 111 self.config = self.get_config()
114 112
115 def get_config(self): 113 def get_config(self):
116 """Get a new GitConfig instance.""" 114 """Get a new GitConfig instance."""
117 return git_config.GitConfig(self.tmpfile.name) 115 return git_config.GitConfig(self.tmpfile.name)
118 116
119 def test_SetString(self): 117 def test_SetString(self):
120 """Test SetString behavior.""" 118 """Test SetString behavior."""
121 # Set a value. 119 # Set a value.
122 self.assertIsNone(self.config.GetString('foo.bar')) 120 self.assertIsNone(self.config.GetString("foo.bar"))
123 self.config.SetString('foo.bar', 'val') 121 self.config.SetString("foo.bar", "val")
124 self.assertEqual('val', self.config.GetString('foo.bar')) 122 self.assertEqual("val", self.config.GetString("foo.bar"))
125 123
126 # Make sure the value was actually written out. 124 # Make sure the value was actually written out.
127 config = self.get_config() 125 config = self.get_config()
128 self.assertEqual('val', config.GetString('foo.bar')) 126 self.assertEqual("val", config.GetString("foo.bar"))
129 127
130 # Update the value. 128 # Update the value.
131 self.config.SetString('foo.bar', 'valll') 129 self.config.SetString("foo.bar", "valll")
132 self.assertEqual('valll', self.config.GetString('foo.bar')) 130 self.assertEqual("valll", self.config.GetString("foo.bar"))
133 config = self.get_config() 131 config = self.get_config()
134 self.assertEqual('valll', config.GetString('foo.bar')) 132 self.assertEqual("valll", config.GetString("foo.bar"))
135 133
136 # Delete the value. 134 # Delete the value.
137 self.config.SetString('foo.bar', None) 135 self.config.SetString("foo.bar", None)
138 self.assertIsNone(self.config.GetString('foo.bar')) 136 self.assertIsNone(self.config.GetString("foo.bar"))
139 config = self.get_config() 137 config = self.get_config()
140 self.assertIsNone(config.GetString('foo.bar')) 138 self.assertIsNone(config.GetString("foo.bar"))
141 139
142 def test_SetBoolean(self): 140 def test_SetBoolean(self):
143 """Test SetBoolean behavior.""" 141 """Test SetBoolean behavior."""
144 # Set a true value. 142 # Set a true value.
145 self.assertIsNone(self.config.GetBoolean('foo.bar')) 143 self.assertIsNone(self.config.GetBoolean("foo.bar"))
146 for val in (True, 1): 144 for val in (True, 1):
147 self.config.SetBoolean('foo.bar', val) 145 self.config.SetBoolean("foo.bar", val)
148 self.assertTrue(self.config.GetBoolean('foo.bar')) 146 self.assertTrue(self.config.GetBoolean("foo.bar"))
149 147
150 # Make sure the value was actually written out. 148 # Make sure the value was actually written out.
151 config = self.get_config() 149 config = self.get_config()
152 self.assertTrue(config.GetBoolean('foo.bar')) 150 self.assertTrue(config.GetBoolean("foo.bar"))
153 self.assertEqual('true', config.GetString('foo.bar')) 151 self.assertEqual("true", config.GetString("foo.bar"))
154 152
155 # Set a false value. 153 # Set a false value.
156 for val in (False, 0): 154 for val in (False, 0):
157 self.config.SetBoolean('foo.bar', val) 155 self.config.SetBoolean("foo.bar", val)
158 self.assertFalse(self.config.GetBoolean('foo.bar')) 156 self.assertFalse(self.config.GetBoolean("foo.bar"))
159 157
160 # Make sure the value was actually written out. 158 # Make sure the value was actually written out.
161 config = self.get_config() 159 config = self.get_config()
162 self.assertFalse(config.GetBoolean('foo.bar')) 160 self.assertFalse(config.GetBoolean("foo.bar"))
163 self.assertEqual('false', config.GetString('foo.bar')) 161 self.assertEqual("false", config.GetString("foo.bar"))
164 162
165 # Delete the value. 163 # Delete the value.
166 self.config.SetBoolean('foo.bar', None) 164 self.config.SetBoolean("foo.bar", None)
167 self.assertIsNone(self.config.GetBoolean('foo.bar')) 165 self.assertIsNone(self.config.GetBoolean("foo.bar"))
168 config = self.get_config() 166 config = self.get_config()
169 self.assertIsNone(config.GetBoolean('foo.bar')) 167 self.assertIsNone(config.GetBoolean("foo.bar"))
170 168
171 def test_GetSyncAnalysisStateData(self): 169 def test_GetSyncAnalysisStateData(self):
172 """Test config entries with a sync state analysis data.""" 170 """Test config entries with a sync state analysis data."""
173 superproject_logging_data = {} 171 superproject_logging_data = {}
174 superproject_logging_data['test'] = False 172 superproject_logging_data["test"] = False
175 options = type('options', (object,), {})() 173 options = type("options", (object,), {})()
176 options.verbose = 'true' 174 options.verbose = "true"
177 options.mp_update = 'false' 175 options.mp_update = "false"
178 TESTS = ( 176 TESTS = (
179 ('superproject.test', 'false'), 177 ("superproject.test", "false"),
180 ('options.verbose', 'true'), 178 ("options.verbose", "true"),
181 ('options.mpupdate', 'false'), 179 ("options.mpupdate", "false"),
182 ('main.version', '1'), 180 ("main.version", "1"),
183 ) 181 )
184 self.config.UpdateSyncAnalysisState(options, superproject_logging_data) 182 self.config.UpdateSyncAnalysisState(options, superproject_logging_data)
185 sync_data = self.config.GetSyncAnalysisStateData() 183 sync_data = self.config.GetSyncAnalysisStateData()
186 for key, value in TESTS: 184 for key, value in TESTS:
187 self.assertEqual(sync_data[f'{git_config.SYNC_STATE_PREFIX}{key}'], value) 185 self.assertEqual(
188 self.assertTrue(sync_data[f'{git_config.SYNC_STATE_PREFIX}main.synctime']) 186 sync_data[f"{git_config.SYNC_STATE_PREFIX}{key}"], value
187 )
188 self.assertTrue(
189 sync_data[f"{git_config.SYNC_STATE_PREFIX}main.synctime"]
190 )