summaryrefslogtreecommitdiff
path: root/_test/test_issues.py
blob: f0a7edeb66a1c27221f15666b95734eb58bfb197 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
# coding: utf-8

from typing import Any

import pytest  # type: ignore  # NOQA


# cannot do "from .roundtrip" because of pytest, so mypy cannot find this
from roundtrip import (  # type: ignore
    round_trip,
    na_round_trip,
    round_trip_load,
    round_trip_dump,
    dedent,
    save_and_run,
    YAML,
)  # NOQA


class TestIssues:
    def test_issue_61(self) -> None:
        s = dedent(
            """
        def1: &ANCHOR1
            key1: value1
        def: &ANCHOR
            <<: *ANCHOR1
            key: value
        comb:
            <<: *ANCHOR
        """
        )
        data = round_trip_load(s)
        assert str(data['comb']) == str(data['def'])
        assert str(data['comb']) == "{'key': 'value', 'key1': 'value1'}"

    #    def test_issue_82(self, tmpdir):
    #        program_src = r'''
    #        from ruamel import yaml
    #        import re
    #
    #        class SINumber(yaml.YAMLObject):
    #            PREFIXES = {'k': 1e3, 'M': 1e6, 'G': 1e9}
    #            yaml_loader = yaml.Loader
    #            yaml_dumper = yaml.Dumper
    #            yaml_tag = '!si'
    #            yaml_implicit_pattern = re.compile(
    #                r'^(?P<value>[0-9]+(?:\.[0-9]+)?)(?P<prefix>[kMG])$')
    #
    #            @classmethod
    #            def from_yaml(cls, loader, node):
    #                return cls(node.value)
    #
    #            @classmethod
    #            def to_yaml(cls, dumper, data):
    #                return dumper.represent_scalar(cls.yaml_tag, str(data))
    #
    #            def __init__(self, *args):
    #                m = self.yaml_implicit_pattern.match(args[0])
    #                self.value = float(m.groupdict()['value'])
    #                self.prefix = m.groupdict()['prefix']
    #
    #            def __str__(self) -> None:
    #                return str(self.value)+self.prefix
    #
    #            def __int__(self) -> None:
    #                return int(self.value*self.PREFIXES[self.prefix])
    #
    #        # This fails:
    #        yaml.add_implicit_resolver(SINumber.yaml_tag, SINumber.yaml_implicit_pattern)
    #
    #        ret = yaml.load("""
    #        [1,2,3, !si 10k, 100G]
    #        """, Loader=yaml.Loader)
    #        for idx, l in enumerate([1, 2, 3, 10000, 100000000000]):
    #            assert int(ret[idx]) == l
    #        '''
    #        assert save_and_run(dedent(program_src), tmpdir) == 0

    def test_issue_82rt(self, tmpdir: Any) -> None:
        yaml_str = '[1, 2, 3, !si 10k, 100G]\n'
        x = round_trip(yaml_str, preserve_quotes=True)  # NOQA

    def test_issue_102(self) -> None:
        yaml_str = dedent(
            """
        var1: #empty
        var2: something #notempty
        var3: {} #empty object
        var4: {a: 1} #filled object
        var5: [] #empty array
        """
        )
        x = round_trip(yaml_str, preserve_quotes=True)  # NOQA

    def test_issue_150(self) -> None:
        from ruamel.yaml import YAML

        inp = """\
        base: &base_key
          first: 123
          second: 234

        child:
          <<: *base_key
          third: 345
        """
        yaml = YAML()
        data = yaml.load(inp)
        child = data['child']
        assert 'second' in dict(**child)

    def test_issue_160(self) -> None:
        from ruamel.yaml.compat import StringIO

        s = dedent(
            """\
        root:
            # a comment
            - {some_key: "value"}

        foo: 32
        bar: 32
        """
        )
        a = round_trip_load(s)
        del a['root'][0]['some_key']
        buf = StringIO()
        round_trip_dump(a, buf, block_seq_indent=4)
        exp = dedent(
            """\
        root:
            # a comment
            - {}

        foo: 32
        bar: 32
        """
        )
        assert buf.getvalue() == exp

    def test_issue_161(self) -> None:
        yaml_str = dedent(
            """\
        mapping-A:
          key-A:{}
        mapping-B:
        """
        )
        for comment in ['', ' # no-newline', '  # some comment\n', '\n']:
            s = yaml_str.format(comment)
            res = round_trip(s)  # NOQA

    def test_issue_161a(self) -> None:
        yaml_str = dedent(
            """\
        mapping-A:
          key-A:{}
        mapping-B:
        """
        )
        for comment in ['\n# between']:
            s = yaml_str.format(comment)
            res = round_trip(s)  # NOQA

    def test_issue_163(self) -> None:
        s = dedent(
            """\
        some-list:
        # List comment
        - {}
        """
        )
        x = round_trip(s, preserve_quotes=True)  # NOQA

    json_str = (
        r'{"sshKeys":[{"name":"AETROS\/google-k80-1","uses":0,"getLastUse":0,'
        '"fingerprint":"MD5:19:dd:41:93:a1:a3:f5:91:4a:8e:9b:d0:ae:ce:66:4c",'
        '"created":1509497961}]}'
    )

    json_str2 = '{"abc":[{"a":"1", "uses":0}]}'

    def test_issue_172(self) -> None:
        x = round_trip_load(TestIssues.json_str2)  # NOQA
        x = round_trip_load(TestIssues.json_str)  # NOQA

    def test_issue_176(self) -> None:
        # basic request by Stuart Berg
        from ruamel.yaml import YAML

        yaml = YAML()
        seq = yaml.load('[1,2,3]')
        seq[:] = [1, 2, 3, 4]

    def test_issue_176_preserve_comments_on_extended_slice_assignment(self) -> None:
        yaml_str = dedent(
            """\
        - a
        - b  # comment
        - c  # commment c
        # comment c+
        - d

        - e # comment
        """
        )
        seq = round_trip_load(yaml_str)
        seq[1::2] = ['B', 'D']
        res = round_trip_dump(seq)
        assert res == yaml_str.replace(' b ', ' B ').replace(' d\n', ' D\n')

    def test_issue_176_test_slicing(self) -> None:
        mss = round_trip_load('[0, 1, 2, 3, 4]')
        assert len(mss) == 5
        assert mss[2:2] == []
        assert mss[2:4] == [2, 3]
        assert mss[1::2] == [1, 3]

        # slice assignment
        m = mss[:]
        m[2:2] = [42]
        assert m == [0, 1, 42, 2, 3, 4]

        m = mss[:]
        m[:3] = [42, 43, 44]
        assert m == [42, 43, 44, 3, 4]
        m = mss[:]
        m[2:] = [42, 43, 44]
        assert m == [0, 1, 42, 43, 44]
        m = mss[:]
        m[:] = [42, 43, 44]
        assert m == [42, 43, 44]

        # extend slice assignment
        m = mss[:]
        m[2:4] = [42, 43, 44]
        assert m == [0, 1, 42, 43, 44, 4]
        m = mss[:]
        m[1::2] = [42, 43]
        assert m == [0, 42, 2, 43, 4]
        m = mss[:]
        with pytest.raises(TypeError, match='too many'):
            m[1::2] = [42, 43, 44]
        with pytest.raises(TypeError, match='not enough'):
            m[1::2] = [42]
        m = mss[:]
        m += [5]
        m[1::2] = [42, 43, 44]
        assert m == [0, 42, 2, 43, 4, 44]

        # deleting
        m = mss[:]
        del m[1:3]
        assert m == [0, 3, 4]
        m = mss[:]
        del m[::2]
        assert m == [1, 3]
        m = mss[:]
        del m[:]
        assert m == []

    def test_issue_184(self) -> None:
        yaml_str = dedent(
            """\
        test::test:
          # test
          foo:
            bar: baz
        """
        )
        d = round_trip_load(yaml_str)
        d['bar'] = 'foo'
        d.yaml_add_eol_comment('test1', 'bar')
        assert round_trip_dump(d) == yaml_str + 'bar: foo # test1\n'

    def test_issue_219(self) -> None:
        yaml_str = dedent(
            """\
        [StackName: AWS::StackName]
        """
        )
        d = round_trip_load(yaml_str)  # NOQA

    def test_issue_219a(self) -> None:
        yaml_str = dedent(
            """\
        [StackName:
        AWS::StackName]
        """
        )
        d = round_trip_load(yaml_str)  # NOQA

    def test_issue_220(self, tmpdir: Any) -> None:
        program_src = r'''
        from ruamel.yaml import YAML

        yaml_str = """\
        ---
        foo: ["bar"]
        """

        yaml = YAML(typ='safe', pure=True)
        d = yaml.load(yaml_str)
        print(d)
        '''
        assert save_and_run(dedent(program_src), tmpdir, optimized=True) == 0

    def test_issue_221_add(self) -> None:
        from ruamel.yaml.comments import CommentedSeq

        a = CommentedSeq([1, 2, 3])
        a + [4, 5]

    def test_issue_221_sort(self) -> None:
        from ruamel.yaml import YAML
        from ruamel.yaml.compat import StringIO

        yaml = YAML()
        inp = dedent(
            """\
        - d
        - a  # 1
        - c  # 3
        - e  # 5
        - b  # 2
        """
        )
        a = yaml.load(dedent(inp))
        a.sort()
        buf = StringIO()
        yaml.dump(a, buf)
        exp = dedent(
            """\
        - a  # 1
        - b  # 2
        - c  # 3
        - d
        - e  # 5
        """
        )
        assert buf.getvalue() == exp

    def test_issue_221_sort_reverse(self) -> None:
        from ruamel.yaml import YAML
        from ruamel.yaml.compat import StringIO

        yaml = YAML()
        inp = dedent(
            """\
        - d
        - a  # 1
        - c  # 3
        - e  # 5
        - b  # 2
        """
        )
        a = yaml.load(dedent(inp))
        a.sort(reverse=True)
        buf = StringIO()
        yaml.dump(a, buf)
        exp = dedent(
            """\
        - e  # 5
        - d
        - c  # 3
        - b  # 2
        - a  # 1
        """
        )
        assert buf.getvalue() == exp

    def test_issue_221_sort_key(self) -> None:
        from ruamel.yaml import YAML
        from ruamel.yaml.compat import StringIO

        yaml = YAML()
        inp = dedent(
            """\
        - four
        - One    # 1
        - Three  # 3
        - five   # 5
        - two    # 2
        """
        )
        a = yaml.load(dedent(inp))
        a.sort(key=str.lower)
        buf = StringIO()
        yaml.dump(a, buf)
        exp = dedent(
            """\
        - five   # 5
        - four
        - One    # 1
        - Three  # 3
        - two    # 2
        """
        )
        assert buf.getvalue() == exp

    def test_issue_221_sort_key_reverse(self) -> None:
        from ruamel.yaml import YAML
        from ruamel.yaml.compat import StringIO

        yaml = YAML()
        inp = dedent(
            """\
        - four
        - One    # 1
        - Three  # 3
        - five   # 5
        - two    # 2
        """
        )
        a = yaml.load(dedent(inp))
        a.sort(key=str.lower, reverse=True)
        buf = StringIO()
        yaml.dump(a, buf)
        exp = dedent(
            """\
        - two    # 2
        - Three  # 3
        - One    # 1
        - four
        - five   # 5
        """
        )
        assert buf.getvalue() == exp

    def test_issue_222(self) -> None:
        import ruamel.yaml
        from ruamel.yaml.compat import StringIO

        yaml = ruamel.yaml.YAML(typ='safe')
        buf = StringIO()
        yaml.dump(['012923'], buf)
        assert buf.getvalue() == "['012923']\n"

    def test_issue_223(self) -> None:
        import ruamel.yaml

        yaml = ruamel.yaml.YAML(typ='safe')
        yaml.load('phone: 0123456789')

    def test_issue_232(self) -> None:
        import ruamel.yaml

        yaml = YAML(typ='safe', pure=True)

        with pytest.raises(ruamel.yaml.parser.ParserError):
            yaml.load(']')
        with pytest.raises(ruamel.yaml.parser.ParserError):
            yaml.load('{]')

    def test_issue_233(self) -> None:
        from ruamel.yaml import YAML
        import json

        yaml = YAML()
        data = yaml.load('{}')
        json_str = json.dumps(data)  # NOQA

    def test_issue_233a(self) -> None:
        from ruamel.yaml import YAML
        import json

        yaml = YAML()
        data = yaml.load('[]')
        json_str = json.dumps(data)  # NOQA

    def test_issue_234(self) -> None:
        from ruamel.yaml import YAML

        inp = dedent(
            """\
        - key: key1
          ctx: [one, two]
          help: one
          cmd: >
            foo bar
            foo bar
        """
        )
        yaml = YAML(typ='safe', pure=True)
        data = yaml.load(inp)
        fold = data[0]['cmd']
        print(repr(fold))
        assert '\a' not in fold

    def test_issue_236(self) -> None:
        inp = """
        conf:
          xx: {a: "b", c: []}
          asd: "nn"
        """
        d = round_trip(inp, preserve_quotes=True)  # NOQA

    def test_issue_238(self, tmpdir: Any) -> None:
        program_src = r"""
        import ruamel.yaml
        from ruamel.yaml.compat import StringIO

        yaml = ruamel.yaml.YAML(typ='unsafe')


        class A:
            def __setstate__(self, d):
                self.__dict__ = d


        class B:
            pass


        a = A()
        b = B()

        a.x = b
        b.y = [b]
        assert a.x.y[0] == a.x

        buf = StringIO()
        yaml.dump(a, buf)

        data = yaml.load(buf.getvalue())
        assert data.x.y[0] == data.x
        """
        assert save_and_run(dedent(program_src), tmpdir) == 0

    def test_issue_239(self) -> None:
        inp = """
        first_name: Art
        occupation: Architect
        # I'm safe
        about: Art Vandelay is a fictional character that George invents...
        # we are not :(
        # help me!
        ---
        # what?!
        hello: world
        # someone call the Batman
        foo: bar # or quz
        # Lost again
        ---
        I: knew
        # final words
        """
        d = YAML().round_trip_all(inp)  # NOQA

    def test_issue_242(self) -> None:
        from ruamel.yaml.comments import CommentedMap

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

    def test_issue_245(self) -> None:
        from ruamel.yaml import YAML

        inp = """
        d: yes
        """
        for typ in ['safepure', 'rt', 'safe']:
            if typ.endswith('pure'):
                pure = True
                typ = typ[:-4]
            else:
                pure = None

            yaml = YAML(typ=typ, pure=pure)
            yaml.version = (1, 1)
            d = yaml.load(inp)
            print(typ, yaml.parser, yaml.resolver)
            assert d['d'] is True

    def test_issue_249(self) -> None:
        yaml = YAML()
        inp = dedent(
            """\
        # comment
        -
          - 1
          - 2
          - 3
        """
        )
        exp = dedent(
            """\
        # comment
        - - 1
          - 2
          - 3
        """
        )
        yaml.round_trip(inp, outp=exp)  # NOQA

    def test_issue_250(self) -> None:
        inp = """
        # 1.
        - - 1
        # 2.
        - map: 2
        # 3.
        - 4
        """
        d = round_trip(inp)  # NOQA

    # @pytest.mark.xfail(strict=True, reason='bla bla', raises=AssertionError)
    def test_issue_279(self) -> None:
        from ruamel.yaml import YAML
        from ruamel.yaml.compat import StringIO

        yaml = YAML()
        yaml.indent(sequence=4, offset=2)
        inp = dedent(
            """\
        experiments:
          - datasets:
        # ATLAS EWK
              - {dataset: ATLASWZRAP36PB, frac: 1.0}
              - {dataset: ATLASZHIGHMASS49FB, frac: 1.0}
        """
        )
        a = yaml.load(inp)
        buf = StringIO()
        yaml.dump(a, buf)
        print(buf.getvalue())
        assert buf.getvalue() == inp

    def test_issue_280(self) -> None:
        from ruamel.yaml import YAML
        from ruamel.yaml.representer import RepresenterError
        from collections import namedtuple
        from sys import stdout

        T = namedtuple('T', ('a', 'b'))
        t = T(1, 2)
        yaml = YAML()
        with pytest.raises(RepresenterError, match='cannot represent'):
            yaml.dump({'t': t}, stdout)

    def test_issue_282(self) -> None:
        # update from list of tuples caused AttributeError
        import ruamel.yaml

        yaml_data = ruamel.yaml.comments.CommentedMap([('a', 'apple'), ('b', 'banana')])
        yaml_data.update([('c', 'cantaloupe')])
        yaml_data.update({'d': 'date', 'k': 'kiwi'})
        assert 'c' in yaml_data.keys()
        assert 'c' in yaml_data._ok

    def test_issue_284(self) -> None:
        import ruamel.yaml

        inp = dedent(
            """\
        plain key: in-line value
        : # Both empty
        "quoted key":
        - entry
        """
        )
        yaml = ruamel.yaml.YAML(typ='rt')
        yaml.version = (1, 2)
        d = yaml.load(inp)
        assert d[None] is None

        yaml = ruamel.yaml.YAML(typ='rt')
        yaml.version = (1, 1)
        with pytest.raises(ruamel.yaml.parser.ParserError, match='expected <block end>'):
            d = yaml.load(inp)

    def test_issue_285(self) -> None:
        from ruamel.yaml import YAML

        yaml = YAML()
        inp = dedent(
            """\
        %YAML 1.1
        ---
        - y
        - n
        - Y
        - N
        """
        )
        a = yaml.load(inp)
        assert a[0]
        assert a[2]
        assert not a[1]
        assert not a[3]

    def test_issue_286(self) -> None:
        from ruamel.yaml import YAML
        from ruamel.yaml.compat import StringIO

        yaml = YAML()
        inp = dedent(
            """\
        parent_key:
        - sub_key: sub_value

        # xxx"""
        )
        a = yaml.load(inp)
        a['new_key'] = 'new_value'
        buf = StringIO()
        yaml.dump(a, buf)
        assert buf.getvalue().endswith('xxx\nnew_key: new_value\n')

    def test_issue_288(self) -> None:
        import sys
        from ruamel.yaml.compat import StringIO
        from ruamel.yaml import YAML

        yamldoc = dedent(
            """\
        ---
        # Reusable values
        aliases:
          # First-element comment
          - &firstEntry First entry
          # Second-element comment
          - &secondEntry Second entry

          # Third-element comment is
          # a multi-line value
          - &thirdEntry Third entry

        # EOF Comment
        """
        )

        yaml = YAML()
        yaml.indent(mapping=2, sequence=4, offset=2)
        yaml.explicit_start = True
        yaml.preserve_quotes = True
        yaml.width = sys.maxsize
        data = yaml.load(yamldoc)
        buf = StringIO()
        yaml.dump(data, buf)
        assert buf.getvalue() == yamldoc

    def test_issue_288a(self) -> None:
        import sys
        from ruamel.yaml.compat import StringIO
        from ruamel.yaml import YAML

        yamldoc = dedent(
            """\
        ---
        # Reusable values
        aliases:
          # First-element comment
          - &firstEntry First entry
          # Second-element comment
          - &secondEntry Second entry

          # Third-element comment is
           # a multi-line value
          - &thirdEntry Third entry

        # EOF Comment
        """
        )

        yaml = YAML()
        yaml.indent(mapping=2, sequence=4, offset=2)
        yaml.explicit_start = True
        yaml.preserve_quotes = True
        yaml.width = sys.maxsize
        data = yaml.load(yamldoc)
        buf = StringIO()
        yaml.dump(data, buf)
        assert buf.getvalue() == yamldoc

    def test_issue_290(self) -> None:
        import sys
        from ruamel.yaml.compat import StringIO
        from ruamel.yaml import YAML

        yamldoc = dedent(
            """\
        ---
        aliases:
          # Folded-element comment
          # for a multi-line value
          - &FoldedEntry >
            THIS IS A
            FOLDED, MULTI-LINE
            VALUE

          # Literal-element comment
          # for a multi-line value
          - &literalEntry |
            THIS IS A
            LITERAL, MULTI-LINE
            VALUE

          # Plain-element comment
          - &plainEntry Plain entry
        """
        )

        yaml = YAML()
        yaml.indent(mapping=2, sequence=4, offset=2)
        yaml.explicit_start = True
        yaml.preserve_quotes = True
        yaml.width = sys.maxsize
        data = yaml.load(yamldoc)
        buf = StringIO()
        yaml.dump(data, buf)
        assert buf.getvalue() == yamldoc

    def test_issue_290a(self) -> None:
        import sys
        from ruamel.yaml.compat import StringIO
        from ruamel.yaml import YAML

        yamldoc = dedent(
            """\
        ---
        aliases:
          # Folded-element comment
          # for a multi-line value
          - &FoldedEntry >
            THIS IS A
            FOLDED, MULTI-LINE
            VALUE

          # Literal-element comment
          # for a multi-line value
          - &literalEntry |
            THIS IS A
            LITERAL, MULTI-LINE
            VALUE

          # Plain-element comment
          - &plainEntry Plain entry
        """
        )

        yaml = YAML()
        yaml.indent(mapping=2, sequence=4, offset=2)
        yaml.explicit_start = True
        yaml.preserve_quotes = True
        yaml.width = sys.maxsize
        data = yaml.load(yamldoc)
        buf = StringIO()
        yaml.dump(data, buf)
        assert buf.getvalue() == yamldoc

    # @pytest.mark.xfail(strict=True, reason='should fail pre 0.15.100', raises=AssertionError)
    def test_issue_295(self) -> None:
        # deepcopy also makes a copy of the start and end mark, and these did not
        # have any comparison beyond their ID, which of course changed, breaking
        # some old merge_comment code
        import copy

        inp = dedent(
            """
        A:
          b:
          # comment
          - l1
          - l2

        C:
          d: e
          f:
          # comment2
          - - l31
            - l32
            - l33: '5'
        """
        )
        data = round_trip_load(inp)  # NOQA
        dc = copy.deepcopy(data)
        assert round_trip_dump(dc) == inp

    def test_issue_300(self) -> None:
        from ruamel.yaml import YAML

        inp = dedent(
            """
        %YAML 1.2
        %TAG ! tag:example.com,2019/path#fragment
        ---
        null
        """
        )
        YAML().load(inp)

    def test_issue_300a(self) -> None:
        import ruamel.yaml

        inp = dedent(
            """
        %YAML 1.1
        %TAG ! tag:example.com,2019/path#fragment
        ---
        null
        """
        )
        yaml = YAML()
        with pytest.raises(
            ruamel.yaml.scanner.ScannerError, match='while scanning a directive'
        ):
            yaml.load(inp)

    def test_issue_304(self) -> None:
        inp = """
        %YAML 1.2
        %TAG ! tag:example.com,2019:
        ---
        !foo null
        ...
        """
        d = na_round_trip(inp)  # NOQA

    def test_issue_305(self) -> None:
        inp = """
        %YAML 1.2
        ---
        !<tag:example.com,2019/path#foo> null
        ...
        """
        d = na_round_trip(inp)  # NOQA

    def test_issue_307(self) -> None:
        inp = """
        %YAML 1.2
        %TAG ! tag:example.com,2019/path#
        ---
        null
        ...
        """
        d = na_round_trip(inp)  # NOQA

    def test_issue_445(self) -> None:
        from ruamel.yaml import YAML
        from ruamel.yaml.compat import StringIO

        yaml = YAML()
        yaml.version = '1.1'
        data = yaml.load('quote: I have seen things')
        buf = StringIO()
        yaml.dump(data, buf)
        assert buf.getvalue() == '%YAML 1.1\n---\nquote: I have seen things\n'
        yaml = YAML()
        yaml.version = [1, 1]
        data = yaml.load('quote: I have seen things')
        buf = StringIO()
        yaml.dump(data, buf)
        assert buf.getvalue() == '%YAML 1.1\n---\nquote: I have seen things\n'

    def test_issue_447(self) -> None:
        from ruamel.yaml import YAML

        YAML().load('{\n\t"FOO": "BAR"\n}')

    def test_issue_449(self) -> None:
        inp = """\
        emoji_index: !!python/name:materialx.emoji.twemoji
        """
        d = na_round_trip(inp)  # NOQA

    def test_issue_455(self) -> None:
        from ruamel.yaml import YAML

        cm = YAML().map(a=97, b=98)
        cm.update({'c': 42, 'd': 196})
        cm.update(c=99, d=100)
        prev = None
        for k, v in cm.items():
            if prev is not None:
                assert prev + 1 == v
            prev = v
            assert ord(k) == v
        assert len(cm) == 4

    def test_issue_453(self) -> None:
        from io import StringIO
        from ruamel.yaml import YAML

        inp = dedent(
            """
        to-merge: &anchor
          merge-key: should not be duplicated

        to-merge2: &anchor2
          merge-key2: should not be duplicated

        usage:
          <<: [*anchor, *anchor2]
          usage-key: usage-value
        """
        )
        yaml = YAML()
        data = yaml.load(inp)
        data['usage'].insert(0, 'insert-key', 'insert-value')
        out_stream = StringIO()
        yaml.dump(data, out_stream)
        result = out_stream.getvalue()
        print(result)
        assert inp.replace('usage:\n', 'usage:\n  insert-key: insert-value\n') == result

    def test_issue_454(self) -> None:
        inp = """
        test1: 🎉
        test2: "🎉"
        test3: '🎉'
        """
        d = round_trip(inp, preserve_quotes=True)  # NOQA

    def test_so_75631454(self) -> None:
        from ruamel.yaml import YAML
        from ruamel.yaml.compat import StringIO

        inp = dedent(
            """
        test:
            long: "This is a sample text
                across two lines."
        """
        )
        yaml = YAML()
        yaml.preserve_quotes = True
        yaml.indent(mapping=4)
        yaml.width = 27
        data = yaml.load(inp)
        buf = StringIO()
        yaml.dump(data, buf)
        assert buf.getvalue() == inp

    def test_issue_458(self) -> None:
        from io import StringIO
        from ruamel.yaml import YAML

        yaml = YAML()
        out_stream = StringIO()
        in_string = 'a' * 128
        yaml.dump(in_string, out_stream)
        result = out_stream.getvalue()
        assert in_string == result.splitlines()[0]

    def test_issue_459(self) -> None:
        from io import StringIO
        from ruamel.yaml import YAML

        MYOBJ = {
            'data': dedent(
                """\
              example: "first"
              data:
                - flag: true
                  integer: 1
                  float: 1.0
                  string: "this is a string"
                  list:
                    - first
                    - second
                    - third
                  circle:
                    x: 10cm
                    y: 10cm
                    radius: 2.24cm

                - flag: false
                  integer: 2
                  float: 2.0
                  string: "this is another string"
                  list:
                    - first
                    - second
                    - third
                  circle:
                    x: 20cm
                    y: 20cm
                    radius: 2.24cm
              """
            )
        }
        yaml = YAML()
        yaml.width = 60
        out_stream = StringIO()
        yaml.dump([MYOBJ], out_stream)
        data = yaml.load(out_stream.getvalue())
        assert data[0]['data'] == MYOBJ['data']


#    @pytest.mark.xfail(strict=True, reason='bla bla', raises=AssertionError)
#    def test_issue_ xxx(self) -> None:
#        inp = """
#        """
#        d = round_trip(inp)  # NOQA