testing/mozbase/manifestdestiny/tests/test_read_ini.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mozbase/manifestdestiny/tests/test_read_ini.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,69 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +"""
     1.7 +test .ini parsing
     1.8 +
     1.9 +ensure our .ini parser is doing what we want; to be deprecated for
    1.10 +python's standard ConfigParser when 2.7 is reality so OrderedDict
    1.11 +is the default:
    1.12 +
    1.13 +http://docs.python.org/2/library/configparser.html
    1.14 +"""
    1.15 +
    1.16 +import unittest
    1.17 +from manifestparser import read_ini
    1.18 +from ConfigParser import ConfigParser
    1.19 +from StringIO import StringIO
    1.20 +
    1.21 +class IniParserTest(unittest.TestCase):
    1.22 +
    1.23 +    def test_inline_comments(self):
    1.24 +        """
    1.25 +        We have no inline comments; so we're testing to ensure we don't:
    1.26 +        https://bugzilla.mozilla.org/show_bug.cgi?id=855288
    1.27 +        """
    1.28 +
    1.29 +        # test '#' inline comments (really, the lack thereof)
    1.30 +        string = """[test_felinicity.py]
    1.31 +kittens = true # This test requires kittens
    1.32 +"""
    1.33 +        buffer = StringIO()
    1.34 +        buffer.write(string)
    1.35 +        buffer.seek(0)
    1.36 +        result = read_ini(buffer)[0][1]['kittens']
    1.37 +        self.assertEqual(result, "true # This test requires kittens")
    1.38 +
    1.39 +        # compare this to ConfigParser
    1.40 +        # python 2.7 ConfigParser does not support '#' as an
    1.41 +        # inline comment delimeter (for "backwards compatability"):
    1.42 +        # http://docs.python.org/2/library/configparser.html
    1.43 +        buffer.seek(0)
    1.44 +        parser = ConfigParser()
    1.45 +        parser.readfp(buffer)
    1.46 +        control = parser.get('test_felinicity.py', 'kittens')
    1.47 +        self.assertEqual(result, control)
    1.48 +
    1.49 +        # test ';' inline comments (really, the lack thereof)
    1.50 +        string = string.replace('#', ';')
    1.51 +        buffer = StringIO()
    1.52 +        buffer.write(string)
    1.53 +        buffer.seek(0)
    1.54 +        result = read_ini(buffer)[0][1]['kittens']
    1.55 +        self.assertEqual(result, "true ; This test requires kittens")
    1.56 +
    1.57 +        # compare this to ConfigParser
    1.58 +        # python 2.7 ConfigParser *does* support ';' as an
    1.59 +        # inline comment delimeter (ibid).
    1.60 +        # Python 3.x configparser, OTOH, does not support
    1.61 +        # inline-comments by default.  It does support their specification,
    1.62 +        # though they are weakly discouraged:
    1.63 +        # http://docs.python.org/dev/library/configparser.html
    1.64 +        buffer.seek(0)
    1.65 +        parser = ConfigParser()
    1.66 +        parser.readfp(buffer)
    1.67 +        control = parser.get('test_felinicity.py', 'kittens')
    1.68 +        self.assertNotEqual(result, control)
    1.69 +
    1.70 +
    1.71 +if __name__ == '__main__':
    1.72 +    unittest.main()

mercurial