michael@0: #!/usr/bin/env python michael@0: michael@0: """ michael@0: test .ini parsing michael@0: michael@0: ensure our .ini parser is doing what we want; to be deprecated for michael@0: python's standard ConfigParser when 2.7 is reality so OrderedDict michael@0: is the default: michael@0: michael@0: http://docs.python.org/2/library/configparser.html michael@0: """ michael@0: michael@0: import unittest michael@0: from manifestparser import read_ini michael@0: from ConfigParser import ConfigParser michael@0: from StringIO import StringIO michael@0: michael@0: class IniParserTest(unittest.TestCase): michael@0: michael@0: def test_inline_comments(self): michael@0: """ michael@0: We have no inline comments; so we're testing to ensure we don't: michael@0: https://bugzilla.mozilla.org/show_bug.cgi?id=855288 michael@0: """ michael@0: michael@0: # test '#' inline comments (really, the lack thereof) michael@0: string = """[test_felinicity.py] michael@0: kittens = true # This test requires kittens michael@0: """ michael@0: buffer = StringIO() michael@0: buffer.write(string) michael@0: buffer.seek(0) michael@0: result = read_ini(buffer)[0][1]['kittens'] michael@0: self.assertEqual(result, "true # This test requires kittens") michael@0: michael@0: # compare this to ConfigParser michael@0: # python 2.7 ConfigParser does not support '#' as an michael@0: # inline comment delimeter (for "backwards compatability"): michael@0: # http://docs.python.org/2/library/configparser.html michael@0: buffer.seek(0) michael@0: parser = ConfigParser() michael@0: parser.readfp(buffer) michael@0: control = parser.get('test_felinicity.py', 'kittens') michael@0: self.assertEqual(result, control) michael@0: michael@0: # test ';' inline comments (really, the lack thereof) michael@0: string = string.replace('#', ';') michael@0: buffer = StringIO() michael@0: buffer.write(string) michael@0: buffer.seek(0) michael@0: result = read_ini(buffer)[0][1]['kittens'] michael@0: self.assertEqual(result, "true ; This test requires kittens") michael@0: michael@0: # compare this to ConfigParser michael@0: # python 2.7 ConfigParser *does* support ';' as an michael@0: # inline comment delimeter (ibid). michael@0: # Python 3.x configparser, OTOH, does not support michael@0: # inline-comments by default. It does support their specification, michael@0: # though they are weakly discouraged: michael@0: # http://docs.python.org/dev/library/configparser.html michael@0: buffer.seek(0) michael@0: parser = ConfigParser() michael@0: parser.readfp(buffer) michael@0: control = parser.get('test_felinicity.py', 'kittens') michael@0: self.assertNotEqual(result, control) michael@0: michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main()