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