Mercurial > hg > configuration
annotate tests/unit.py @ 37:a1f8dec4d4f9
we has another broken test
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 27 Mar 2012 09:52:51 -0700 |
parents | d218df4d0b4c |
children | 8909ae1cc4ea |
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 | |
32
da4d5c5831c6
serialization testing stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
10 import tempfile |
0 | 11 import unittest |
12 | |
32
da4d5c5831c6
serialization testing stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
13 try: |
da4d5c5831c6
serialization testing stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
14 import json |
da4d5c5831c6
serialization testing stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
15 except ImportError: |
da4d5c5831c6
serialization testing stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
16 import simplejson as json |
da4d5c5831c6
serialization testing stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
17 |
19
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
18 from example import ExampleConfiguration # example configuration to test |
11
e00afe2c83bf
stubbing configuration parser
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
19 |
0 | 20 # globals |
21 here = os.path.dirname(os.path.abspath(__file__)) | |
22 | |
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
|
23 class ConfigurationUnitTest(unittest.TestCase): |
0 | 24 |
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
|
25 def test_cli(self): |
28
c516ab813079
begin stubbing serialization/deserialization
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
26 """test command line interface""" |
c516ab813079
begin stubbing serialization/deserialization
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
27 |
19
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
28 example = ExampleConfiguration() |
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
29 |
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
30 # parse command line arguments |
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
31 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
|
32 |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
33 # ensure that the options appropriately get set |
19
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
34 self.assertEqual(bool(args), False) # no arguments |
cadc9514f60a
we have a legitimately failing test!
Jeff Hammel <jhammel@mozilla.com>
parents:
11
diff
changeset
|
35 self.assertEqual(options.develop, True) |
25
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
36 self.assertEqual(options.activeTests, ['ts']) |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
37 self.assertEqual(options.browser_path, '/home/jhammel/bin/firefox') |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
38 |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
39 # ensure that the configuration appropriately gets updated |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
40 self.assertEqual(example.config['develop'], True) |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
41 self.assertEqual(example.config['activeTests'], ['ts']) |
b39e550402ea
we now update configuration correctly
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
42 self.assertEqual(example.config['browser_path'], '/home/jhammel/bin/firefox') |
0 | 43 |
28
c516ab813079
begin stubbing serialization/deserialization
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
44 def test_configuration_providers(self): |
c516ab813079
begin stubbing serialization/deserialization
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
45 """test file-based configuration providers""" |
30
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
46 # require json/simplejson and pyyaml to be installed |
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
47 |
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
48 example = ExampleConfiguration() |
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
49 |
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
50 # see what providers you got |
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
51 json_provider = example.configuration_provider('json') |
b27a7cb2dd5b
stub test for configuration providers
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
52 self.assertTrue(isinstance(json_provider, configuration.JSON)) |
28
c516ab813079
begin stubbing serialization/deserialization
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
53 |
33
b7d6a90b0bb5
setup for serialization testing
Jeff Hammel <jhammel@mozilla.com>
parents:
32
diff
changeset
|
54 # serialize to a temporary file |
37
a1f8dec4d4f9
we has another broken test
Jeff Hammel <jhammel@mozilla.com>
parents:
36
diff
changeset
|
55 filename = tempfile.mktemp(suffix='.json') |
a1f8dec4d4f9
we has another broken test
Jeff Hammel <jhammel@mozilla.com>
parents:
36
diff
changeset
|
56 self.assertFalse(os.path.exists(filename)) |
34
79aca36abd9a
fill in defaults if not present
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
57 config = {'browser_path': '/home/jhammel/bin/firefox', |
79aca36abd9a
fill in defaults if not present
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
58 'activeTests': ['ts']} |
79aca36abd9a
fill in defaults if not present
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
59 example(config) |
79aca36abd9a
fill in defaults if not present
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
60 config['test_timeout'] = 1200 # default |
79aca36abd9a
fill in defaults if not present
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
61 self.assertEqual(config, example.config) |
37
a1f8dec4d4f9
we has another broken test
Jeff Hammel <jhammel@mozilla.com>
parents:
36
diff
changeset
|
62 example.serialize(filename) |
a1f8dec4d4f9
we has another broken test
Jeff Hammel <jhammel@mozilla.com>
parents:
36
diff
changeset
|
63 self.assertTrue(os.path.exists(filename)) |
33
b7d6a90b0bb5
setup for serialization testing
Jeff Hammel <jhammel@mozilla.com>
parents:
32
diff
changeset
|
64 if os.path.exists(filename): |
b7d6a90b0bb5
setup for serialization testing
Jeff Hammel <jhammel@mozilla.com>
parents:
32
diff
changeset
|
65 os.remove(filename) |
b7d6a90b0bb5
setup for serialization testing
Jeff Hammel <jhammel@mozilla.com>
parents:
32
diff
changeset
|
66 |
36
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
67 def test_required(self): |
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
68 """ensure you have to have required values""" |
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
69 |
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
70 example = ExampleConfiguration() |
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
71 |
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
72 # ensure you get an exception |
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
73 missingvalueexception = None |
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
74 try: |
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
75 example() |
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
76 except configuration.MissingValueException, e: |
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
77 missingvalueexception = e |
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
78 self.assertTrue(isinstance(e, configuration.MissingValueException)) |
d218df4d0b4c
add test for missing values
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
79 |
0 | 80 if __name__ == '__main__': |
81 unittest.main() | |
82 |