|
1 #!/usr/bin/env python |
|
2 |
|
3 """ |
|
4 test .ini parsing |
|
5 |
|
6 ensure our .ini parser is doing what we want; to be deprecated for |
|
7 python's standard ConfigParser when 2.7 is reality so OrderedDict |
|
8 is the default: |
|
9 |
|
10 http://docs.python.org/2/library/configparser.html |
|
11 """ |
|
12 |
|
13 import unittest |
|
14 from manifestparser import read_ini |
|
15 from ConfigParser import ConfigParser |
|
16 from StringIO import StringIO |
|
17 |
|
18 class IniParserTest(unittest.TestCase): |
|
19 |
|
20 def test_inline_comments(self): |
|
21 """ |
|
22 We have no inline comments; so we're testing to ensure we don't: |
|
23 https://bugzilla.mozilla.org/show_bug.cgi?id=855288 |
|
24 """ |
|
25 |
|
26 # test '#' inline comments (really, the lack thereof) |
|
27 string = """[test_felinicity.py] |
|
28 kittens = true # This test requires kittens |
|
29 """ |
|
30 buffer = StringIO() |
|
31 buffer.write(string) |
|
32 buffer.seek(0) |
|
33 result = read_ini(buffer)[0][1]['kittens'] |
|
34 self.assertEqual(result, "true # This test requires kittens") |
|
35 |
|
36 # compare this to ConfigParser |
|
37 # python 2.7 ConfigParser does not support '#' as an |
|
38 # inline comment delimeter (for "backwards compatability"): |
|
39 # http://docs.python.org/2/library/configparser.html |
|
40 buffer.seek(0) |
|
41 parser = ConfigParser() |
|
42 parser.readfp(buffer) |
|
43 control = parser.get('test_felinicity.py', 'kittens') |
|
44 self.assertEqual(result, control) |
|
45 |
|
46 # test ';' inline comments (really, the lack thereof) |
|
47 string = string.replace('#', ';') |
|
48 buffer = StringIO() |
|
49 buffer.write(string) |
|
50 buffer.seek(0) |
|
51 result = read_ini(buffer)[0][1]['kittens'] |
|
52 self.assertEqual(result, "true ; This test requires kittens") |
|
53 |
|
54 # compare this to ConfigParser |
|
55 # python 2.7 ConfigParser *does* support ';' as an |
|
56 # inline comment delimeter (ibid). |
|
57 # Python 3.x configparser, OTOH, does not support |
|
58 # inline-comments by default. It does support their specification, |
|
59 # though they are weakly discouraged: |
|
60 # http://docs.python.org/dev/library/configparser.html |
|
61 buffer.seek(0) |
|
62 parser = ConfigParser() |
|
63 parser.readfp(buffer) |
|
64 control = parser.get('test_felinicity.py', 'kittens') |
|
65 self.assertNotEqual(result, control) |
|
66 |
|
67 |
|
68 if __name__ == '__main__': |
|
69 unittest.main() |