Changeset 103:adf3cd83bf7a


Ignore:
Timestamp:
Sep 2, 2013, 11:05:25 AM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
rebase_source:
8228a2ec776e4c9c2bcc3f95d733e7bee7629d75
Message:

Support a common stylistic variation

Location:
nagslang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/tests/test_yamlish.py

    r102 r103  
    88
    99from nagslang.yamlish import load, dump
     10
     11
     12class TestParse(TestCase):
     13    def assertParsesAs(self, yaml, expected):
     14        f = StringIO(yaml.strip())
     15        self.assertEqual(load(f), expected)
     16
     17    def test_dict_list_1(self):
     18        self.assertParsesAs('''
     19foo:
     20- bar
     21- baz
     22        ''', {'foo': ['bar', 'baz']})
     23
     24    def test_dict_list_2(self):
     25        self.assertParsesAs('''
     26foo:
     27  - bar
     28  - baz
     29        ''', {'foo': ['bar', 'baz']})
    1030
    1131
  • nagslang/yamlish.py

    r102 r103  
    6464
    6565        if len(spaces) > indent():
    66             # Nested dict
    67             assert dm
    6866            assert parent_key
    69             stack.append((len(spaces), {}))
     67            if dm:
     68                # Nested dict
     69                stack.append((len(spaces), {}))
     70            elif lm:
     71                # Over-indented list in a dict
     72                stack.append((len(spaces), []))
    7073            stack[-2][1][parent_key] = obj()
    7174            parent_key = None
Note: See TracChangeset for help on using the changeset viewer.