configparser.test 1.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
Some tests of the basic config-file parser:

First, an example that illustrates a well-formed configuration::

  [s1]
  a = 1

  [   s2  ]         # a comment
  long = a
      b

      c
  l2 =


      a


      # not a comment

  # comment
  ; also a coment

      b

        c


  empty =

  c=1

  b    += 1

  [s3]; comment
  x =           a b        

.. -> text

40 41 42
    >>> try: import StringIO
    ... except ImportError: import io as StringIO
    >>> import pprint, zc.buildout.configparser
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    >>> pprint.pprint(zc.buildout.configparser.parse(StringIO.StringIO(
    ...     text), 'test'))
    {'s1': {'a': '1'},
     's2': {'b    +': '1',
            'c': '1',
            'empty': '',
            'l2': 'a\n\n\n# not a comment\n\n\nb\n\n  c',
            'long': 'a\nb\nc'},
     's3': {'x': 'a b'}}

Here's an example with leading blank lines:

    >>> text = '\n\n[buildout]\nz=1\n\n'
    >>> pprint.pprint(zc.buildout.configparser.parse(StringIO.StringIO(
    ...     text), 'test'))
    {'buildout': {'z': '1'}}

Some examples that should error: