Ejemplo n.º 1
0
 def __init__(self, *args, **kw):
     # type: (Any, Any) -> None
     if hasattr(self, '_od'):
         raise_immutable(self)
     try:
         self._od = ordereddict(*args, **kw)
     except TypeError:
         raise
Ejemplo n.º 2
0
    def test_omap_out(self):
        # ordereddict mapped to !!omap
        import ruyaml  # NOQA
        from ruyaml.compat import ordereddict

        x = ordereddict([('a', 1), ('b', 2)])
        res = round_trip_dump(x, default_flow_style=False)
        assert res == dedent("""
        !!omap
        - a: 1
        - b: 2
        """)
Ejemplo n.º 3
0
    def test_dump_ruamel_ordereddict(self):
        from ruamel.ordereddict import ordereddict

        import ruyaml  # NOQA

        # OrderedDict mapped to !!omap
        x = ordereddict([('a', 1), ('b', 2)])
        res = ruyaml.dump(x,
                          Dumper=ruyaml.RoundTripDumper,
                          default_flow_style=False)
        assert res == dedent("""
        !!omap
        - a: 1
        - b: 2
        """)
Ejemplo n.º 4
0
    def test_map(self):
        from ruyaml.comments import CommentedMap
        from ruyaml.compat import ordereddict
        from ruyaml.scalarstring import DoubleQuotedScalarString as dq
        from ruyaml.scalarstring import SingleQuotedScalarString as sq
        from ruyaml.scalarstring import preserve_literal, walk_tree

        data = CommentedMap()
        data[1] = 'a'
        data[2] = 'with\nnew : line\n'
        data[3] = '${abc}'
        data[4] = 'almost:mapping'
        m = ordereddict([('\n', preserve_literal), ('${', sq), (':', dq)])
        walk_tree(data, map=m)
        exp = """\
        1: a
        2: |
          with
          new : line
        3: '${abc}'
        4: "almost:mapping"
        """
        assert round_trip_dump(data) == dedent(exp)
Ejemplo n.º 5
0
 def __init__(self, values=None):
     # type: (Any) -> None
     self.odict = ordereddict()
     MutableSet.__init__(self)
     if values is not None:
         self |= values  # type: ignore