Mercurial > hg > configuration
annotate tests/unit.py @ 30:b27a7cb2dd5b
stub test for configuration providers
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 26 Mar 2012 17:05:02 -0700 |
parents | c516ab813079 |
children | da4d5c5831c6 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 | |
3 """ | |
4 unit tests | |
5 """ | |
6 | |
30
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
7 import configuration |
0 | 8 import os |
9 import sys | |
10 import unittest | |
11 | |
19
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
12 from example import ExampleConfiguration # example configuration to test |
11
e00afe2c83bf
stubbing configuration parser
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
13 |
0 | 14 # globals |
15 here = os.path.dirname(os.path.abspath(__file__)) | |
16 | |
24
39f2611db9be
rename a bunch of things and begin to work on the sanity of validation
Jeff Hammel <jhammel@mozilla.com>
parents:
19
diff
changeset
|
17 class ConfigurationUnitTest(unittest.TestCase): |
0 | 18 |
24
39f2611db9be
rename a bunch of things and begin to work on the sanity of validation
Jeff Hammel <jhammel@mozilla.com>
parents:
19
diff
changeset
|
19 def test_cli(self): |
28
c516ab813079
begin stubbing serialization/deserialization
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
20 """test command line interface""" |
c516ab813079
begin stubbing serialization/deserialization
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
21 |
19
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
22 example = ExampleConfiguration() |
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
23 |
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
24 # parse command line arguments |
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
25 options, args = example.parse(['-a', 'ts', '--develop', '-e', '/home/jhammel/bin/firefox']) |
25
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
26 |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
27 # ensure that the options appropriately get set |
19
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
28 self.assertEqual(bool(args), False) # no arguments |
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
29 self.assertEqual(options.develop, True) |
25
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
30 self.assertEqual(options.activeTests, ['ts']) |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
31 self.assertEqual(options.browser_path, '/home/jhammel/bin/firefox') |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
32 |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
33 # ensure that the configuration appropriately gets updated |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
34 self.assertEqual(example.config['develop'], True) |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
35 self.assertEqual(example.config['activeTests'], ['ts']) |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
36 self.assertEqual(example.config['browser_path'], '/home/jhammel/bin/firefox') |
0 | 37 |
28
c516ab813079
begin stubbing serialization/deserialization
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
38 def test_configuration_providers(self): |
c516ab813079
begin stubbing serialization/deserialization
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
39 """test file-based configuration providers""" |
30
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
40 # require json/simplejson and pyyaml to be installed |
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
41 |
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
42 example = ExampleConfiguration() |
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
43 |
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
44 # see what providers you got |
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
45 json_provider = example.configuration_provider('json') |
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
46 self.assertTrue(isinstance(json_provider, configuration.JSON)) |
28
c516ab813079
begin stubbing serialization/deserialization
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
47 |
0 | 48 if __name__ == '__main__': |
49 unittest.main() | |
50 |