-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* YAML safe load and dump * SerializationSafetyError and deprecation warnings * Unit tests
- Loading branch information
Martin Kristiansen
authored
Nov 10, 2016
1 parent
99ccee2
commit 2969f95
Showing
3 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import unittest | ||
from baiji.serialization import yaml | ||
|
||
class UnsafeToDump(object): | ||
"""Python classes should not by default be YAML dumpable in safe mode""" | ||
pass | ||
|
||
unsafe_to_load = "!!python/name:baiji.serialization.test_yaml.UnsafeToDump ''\n" | ||
|
||
class TestYAML(unittest.TestCase): | ||
|
||
def test_yaml_unsafe_dumps(self): | ||
self.assertEqual(yaml.dumps(UnsafeToDump), unsafe_to_load) | ||
|
||
def test_yaml_unsafe_loads_uses_load(self): | ||
self.assertEqual(yaml.loads(unsafe_to_load), UnsafeToDump) | ||
|
||
def test_yaml_safe_dump_raises_on_unsafe(self): | ||
self.assertRaises( | ||
yaml.SerializationSafetyError, | ||
yaml.dumps, UnsafeToDump, safe=True) | ||
|
||
def test_yaml_safe_load_raises_on_unsafe(self): | ||
self.assertRaises( | ||
yaml.SerializationSafetyError, | ||
yaml.loads, unsafe_to_load, safe=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters