1010data = OrderedDict ([('x' , 1 ), ('z' , 3 ), ('y' , 2 )])
1111
1212
13+ # this release was pulled from index, but still might be seen in the wild
14+ pyyaml_41 = yaml .pyyaml .__version__ == '4.1'
15+
16+
1317def test_dump ():
1418 assert yaml .dump (data ) == '{x: 1, z: 3, y: 2}\n '
1519
@@ -18,7 +22,7 @@ def test_safe_dump():
1822 assert yaml .safe_dump (data ) == '{x: 1, z: 3, y: 2}\n '
1923
2024
21- @pytest .mark .skipif (yaml . pyyaml . __version__ < '4' , reason = "requires PyYAML version >= 4 " )
25+ @pytest .mark .skipif (not pyyaml_41 , reason = "requires PyYAML version == 4.1 " )
2226def test_danger_dump ():
2327 assert yaml .danger_dump (data ) == '{x: 1, z: 3, y: 2}\n '
2428
@@ -27,14 +31,14 @@ def test_dump_all():
2731 assert yaml .dump_all (documents = [data , {}]) == '{x: 1, z: 3, y: 2}\n --- {}\n '
2832
2933
30- @pytest .mark .skipif (yaml . pyyaml . __version__ >= '4' , reason = "requires PyYAML version < 4 " )
34+ @pytest .mark .skipif (pyyaml_41 , reason = "requires PyYAML version != 4.1 " )
3135def test_dump_and_safe_dump_match ():
3236 mydict = {'x' : 1 , 'z' : 2 , 'y' : 3 }
3337 # don't know if mydict is ordered in the implementation or not (but don't care)
3438 assert yaml .dump (mydict ) == yaml .safe_dump (mydict )
3539
3640
37- @pytest .mark .skipif (yaml . pyyaml . __version__ < '4' , reason = "requires PyYAML version >= 4 " )
41+ @pytest .mark .skipif (not pyyaml_41 , reason = "requires PyYAML version == 4.1 " )
3842def test_danger_dump_and_safe_dump_match ():
3943 mydict = {'x' : 1 , 'z' : 2 , 'y' : 3 }
4044 assert yaml .danger_dump (mydict ) == yaml .safe_dump (mydict )
@@ -49,6 +53,11 @@ def test_load():
4953 assert loaded == {'x' : 1 , 'z' : 3 , 'y' : 2 }
5054
5155
56+ def test_safe_load ():
57+ loaded = yaml .safe_load ('{x: 1, z: 3, y: 2}' )
58+ assert loaded == {'x' : 1 , 'z' : 3 , 'y' : 2 }
59+
60+
5261def test_load_all ():
5362 gen = yaml .load_all ('{x: 1, z: 3, y: 2}\n --- {}\n ' )
5463 assert isinstance (gen , GeneratorType )
@@ -57,39 +66,50 @@ def test_load_all():
5766 assert ordered_data == data
5867
5968
60- @pytest .mark .skipif (sys .version_info >= (3 ,7 ), reason = "requires python3.6-" )
69+ @pytest .mark .skipif (sys .version_info >= (3 , 7 ), reason = "requires python3.6-" )
6170def test_loads_to_ordered_dict ():
6271 loaded = yaml .load ('{x: 1, z: 3, y: 2}' )
6372 assert isinstance (loaded , OrderedDict )
6473
6574
66- @pytest .mark .skipif (sys .version_info < (3 ,7 ), reason = "requires python3.7+" )
75+ @pytest .mark .skipif (sys .version_info < (3 , 7 ), reason = "requires python3.7+" )
6776def test_loads_to_std_dict ():
6877 loaded = yaml .load ('{x: 1, z: 3, y: 2}' )
6978 assert not isinstance (loaded , OrderedDict )
7079 assert isinstance (loaded , dict )
7180
7281
82+ @pytest .mark .skipif (sys .version_info >= (3 , 7 ), reason = "requires python3.6-" )
83+ def test_safe_loads_to_ordered_dict ():
84+ loaded = yaml .safe_load ('{x: 1, z: 3, y: 2}' )
85+ assert isinstance (loaded , OrderedDict )
86+
87+
88+ @pytest .mark .skipif (sys .version_info < (3 , 7 ), reason = "requires python3.7+" )
89+ def test_safe_loads_to_std_dict ():
90+ loaded = yaml .safe_load ('{x: 1, z: 3, y: 2}' )
91+ assert not isinstance (loaded , OrderedDict )
92+ assert isinstance (loaded , dict )
93+
94+
7395class MyOrderedDict (OrderedDict ):
7496 pass
7597
7698
77- @pytest .mark .skipif (yaml . pyyaml . __version__ >= '4' , reason = "requires PyYAML version < 4 " )
99+ @pytest .mark .skipif (pyyaml_41 , reason = "requires PyYAML version != 4.1 " )
78100def test_subclass_dump_pyyaml3 ():
79101 data = MyOrderedDict ([('x' , 1 ), ('y' , 2 )])
80102 assert '!!python/object/apply:test_oyaml.MyOrderedDict' in yaml .dump (data )
81- with pytest .raises (yaml .pyyaml .representer .RepresenterError ) as cm :
103+ with pytest .raises (yaml .pyyaml .representer .RepresenterError , match = 'cannot represent an object' ) as cm :
82104 yaml .safe_dump (data )
83- assert str (cm .value ) == "cannot represent an object: MyOrderedDict([('x', 1), ('y', 2)])"
84105
85106
86- @pytest .mark .skipif (yaml . pyyaml . __version__ < '4' , reason = "requires PyYAML version >= 4 " )
107+ @pytest .mark .skipif (not pyyaml_41 , reason = "requires PyYAML version == 4.1 " )
87108def test_subclass_dump_pyyaml4 ():
88109 data = MyOrderedDict ([('x' , 1 ), ('y' , 2 )])
89110 assert '!!python/object/apply:test_oyaml.MyOrderedDict' in yaml .danger_dump (data )
90- with pytest .raises (yaml .pyyaml .representer .RepresenterError ) as cm :
111+ with pytest .raises (yaml .pyyaml .representer .RepresenterError , match = 'cannot represent an object' ) as cm :
91112 yaml .dump (data )
92- assert str (cm .value ) == "('cannot represent an object', MyOrderedDict([('x', 1), ('y', 2)]))"
93113
94114
95115def test_anchors_and_references ():
0 commit comments