Example #1
0
    def test_convert_error(self):
        with pytest.raises(InvalidConfigError) as excinfo:
            data = load("""
            - {}
            """)
            target_factory._convert_to_named_list(data)
        assert "invalid empty dict as list item" in excinfo.value.msg

        with pytest.raises(InvalidConfigError) as excinfo:
            data = load("""
            - "error"
            """)
            target_factory._convert_to_named_list(data)
        assert "invalid list item type <class 'str'> (should be dict)" in excinfo.value.msg

        with pytest.raises(InvalidConfigError) as excinfo:
            data = load("""
            - name: "bar"
              extra: "baz"
            """)
            target_factory._convert_to_named_list(data)
        assert "missing 'cls' key in OrderedDict(" in excinfo.value.msg

        with pytest.raises(InvalidConfigError) as excinfo:
            data = load("""
            - one:
            - two: {}
            """)
            target_factory._convert_to_named_list(data)
        assert "invalid list item, add empty dict for no arguments" in excinfo.value.msg
Example #2
0
 def test_convert_explicit_list(self):
     data = load("""
     - cls: FooPort
     - cls: BarPort
       name: bar
     """)
     l = target_factory._convert_to_named_list(data)
     assert l == [
         {
             'cls': 'FooPort',
             'name': None,
         },
         {
             'cls': 'BarPort',
             'name': 'bar'
         },
     ]
Example #3
0
 def test_convert_simple_list(self):
     data = load("""
     - FooPort: {}
     - BarPort:
         name: bar
     """)
     l = target_factory._convert_to_named_list(data)
     assert l == [
         {
             'cls': 'FooPort',
             'name': None,
         },
         {
             'cls': 'BarPort',
             'name': 'bar'
         },
     ]