testing/mozbase/manifestdestiny/tests/test_read_ini.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 #!/usr/bin/env python
     3 """
     4 test .ini parsing
     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:
    10 http://docs.python.org/2/library/configparser.html
    11 """
    13 import unittest
    14 from manifestparser import read_ini
    15 from ConfigParser import ConfigParser
    16 from StringIO import StringIO
    18 class IniParserTest(unittest.TestCase):
    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         """
    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")
    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)
    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")
    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)
    68 if __name__ == '__main__':
    69     unittest.main()

mercurial