Mercurial > hg > configuration
comparison tests/unit.py @ 102:c530f6265deb
allow extensible configuration; also start using deepcopy heavily since otherwise you have artefacts
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Tue, 01 May 2012 10:33:37 -0700 |
| parents | 0804a706d6bf |
| children | a2184db43fe2 |
comparison
equal
deleted
inserted
replaced
| 101:f4590492cb4c | 102:c530f6265deb |
|---|---|
| 57 self.assertFalse(os.path.exists(filename)) | 57 self.assertFalse(os.path.exists(filename)) |
| 58 config = {'browser_path': '/home/jhammel/bin/firefox', | 58 config = {'browser_path': '/home/jhammel/bin/firefox', |
| 59 'activeTests': ['ts']} | 59 'activeTests': ['ts']} |
| 60 example(config) | 60 example(config) |
| 61 config['test_timeout'] = 1200 # default | 61 config['test_timeout'] = 1200 # default |
| 62 config['preferences'] = {"browser.bookmarks.max_backups": 0, | |
| 63 "browser.cache.disk.smart_size.enabled": False} | |
| 64 | |
| 65 # ensure they are equal | |
| 62 self.assertEqual(config, example.config) | 66 self.assertEqual(config, example.config) |
| 63 example.serialize(filename) | 67 example.serialize(filename) |
| 64 self.assertTrue(os.path.exists(filename)) | 68 self.assertTrue(os.path.exists(filename)) |
| 65 serialized = json.loads(file(filename).read()) | 69 serialized = json.loads(file(filename).read()) |
| 66 self.assertEqual(serialized, config) | 70 self.assertEqual(serialized, config) |
| 99 example() | 103 example() |
| 100 except configuration.MissingValueException, e: | 104 except configuration.MissingValueException, e: |
| 101 missingvalueexception = e | 105 missingvalueexception = e |
| 102 self.assertTrue(isinstance(e, configuration.MissingValueException)) | 106 self.assertTrue(isinstance(e, configuration.MissingValueException)) |
| 103 | 107 |
| 108 | |
| 104 def test_multiple_configurations(self): | 109 def test_multiple_configurations(self): |
| 105 """test having multiple configurations""" | 110 """test having multiple configurations""" |
| 106 | 111 |
| 107 # simple override | 112 # simple override |
| 108 args1 = ['-e', '/opt/bin/firefox'] | 113 args1 = ['-e', '/opt/bin/firefox'] |
| 139 # but we can override it back from the "command line" | 144 # but we can override it back from the "command line" |
| 140 example.parse_args(args1 + [json_file, '--test_timeout', '1200']) | 145 example.parse_args(args1 + [json_file, '--test_timeout', '1200']) |
| 141 config['test_timeout'] = 1200 | 146 config['test_timeout'] = 1200 |
| 142 self.assertEqual(example.config, config) | 147 self.assertEqual(example.config, config) |
| 143 | 148 |
| 149 def test_extend(self): | |
| 150 | |
| 151 # default preferences | |
| 152 example = ExampleConfiguration() | |
| 153 default_prefs = {"browser.bookmarks.max_backups": 0, | |
| 154 "browser.cache.disk.smart_size.enabled": False} | |
| 155 example.parse_args(['-a', 'ts', '-e', '/opt/bin/firefox']) | |
| 156 self.assertEqual(example.config['preferences'], default_prefs) | |
| 157 | |
| 158 # now extend them | |
| 159 example = ExampleConfiguration() | |
| 160 default_prefs['network.dns.ipv4OnlyDomains'] = 'localhost' | |
| 161 tf = tempfile.mktemp() | |
| 162 f = file(tf, 'w') | |
| 163 f.write(json.dumps({'preferences': {'network.dns.ipv4OnlyDomains': 'localhost'}})) | |
| 164 f.close() | |
| 165 example.parse_args(['-a', 'ts', '-e', '/opt/bin/firefox', tf]) | |
| 166 self.assertEqual(example.config['preferences'], default_prefs) | |
| 167 os.remove(tf) | |
| 168 | |
| 144 if __name__ == '__main__': | 169 if __name__ == '__main__': |
| 145 unittest.main() | 170 unittest.main() |
