def test_before_top_map_from_scratch(self):
        from ruyaml.comments import CommentedMap

        data = CommentedMap()
        data['a'] = 1
        data['b'] = 2
        data.yaml_set_start_comment('Hello\nWorld\n')
        # print(data.ca)
        # print(data.ca._items)
        exp = """
            # Hello
            # World
            a: 1
            b: 2
            """
        compare(data, exp.format(comment='#'))
示例#2
0
    def test_add_anchor(self):
        from ruyaml.comments import CommentedMap

        data = CommentedMap()
        data_a = CommentedMap()
        data['a'] = data_a
        data_a['c'] = 3
        data['b'] = 2
        data.yaml_set_anchor('klm', always_dump=True)
        data['a'].yaml_set_anchor('xyz', always_dump=True)
        compare(
            data,
            """
        &klm
        a: &xyz
          c: 3
        b: 2
        """,
        )
    def test_before_nested_map_from_scratch(self):
        from ruyaml.comments import CommentedMap

        data = CommentedMap()
        datab = CommentedMap()
        data['a'] = 1
        data['b'] = datab
        datab['c'] = 2
        datab['d'] = 3
        data['b'].yaml_set_start_comment('Hello\nWorld\n')
        exp = """
        a: 1
        b:
        # Hello
        # World
          c: 2
          d: 3
        """
        compare(data, exp.format(comment='#'))
示例#4
0
    def test_basic(self):
        from ruyaml.comments import CommentedMap
        from ruyaml.scalarstring import walk_tree

        data = CommentedMap()
        data[1] = 'a'
        data[2] = 'with\nnewline\n'
        walk_tree(data)
        exp = """\
        1: a
        2: |
          with
          newline
        """
        assert round_trip_dump(data) == dedent(exp)
    def test_before_nested_seq_from_scratch_block_seq_indent(self):
        from ruyaml.comments import CommentedMap, CommentedSeq

        data = CommentedMap()
        datab = CommentedSeq()
        data['a'] = 1
        data['b'] = datab
        datab.append('c')
        datab.append('d')
        data['b'].yaml_set_start_comment('Hello\nWorld\n', indent=2)
        exp = """
        a: 1
        b:
          # Hello
          # World
          - c
          - d
        """
        compare(data, exp.format(comment='#'), indent=4, block_seq_indent=2)
示例#6
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)
示例#7
0
    def test_issue_242(self):
        from ruyaml.comments import CommentedMap

        d0 = CommentedMap([('a', 'b')])
        assert d0['a'] == 'b'