This repository has been archived by the owner on Mar 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from uber/jr-add-option-to-load-all-strings-as…
…-unicode Add support for loading yaml strings as unicode.
- Loading branch information
Showing
6 changed files
with
90 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
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,2 @@ | ||
foo: bar | ||
baz: foobar |
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,54 @@ | ||
from __future__ import absolute_import | ||
from sys import version_info | ||
|
||
import unittest | ||
from yaml import add_constructor | ||
from yaml.constructor import SafeConstructor | ||
|
||
from charlatan import file_format, testing | ||
|
||
|
||
class TestUnicodeLoad(testing.TestCase): | ||
|
||
def setUp(self): | ||
# preserve the original constructor for strings | ||
self.str_constructor = SafeConstructor.yaml_constructors[ | ||
u'tag:yaml.org,2002:str' | ||
] | ||
self.yaml = file_format.load_file( | ||
'./charlatan/tests/data/strings.yaml', | ||
unicode_output=True, | ||
) | ||
|
||
def tearDown(self): | ||
# reset the constructor | ||
add_constructor(u'tag:yaml.org,2002:str', self.str_constructor) | ||
|
||
@unittest.skipIf(version_info[0] == 3, 'Unicode is undefined in Python 3') | ||
def test_strings_are_unicode(self): | ||
"""Assert all strings are loaded as unicode""" | ||
for key, val in self.yaml.items(): | ||
self.assertTrue(isinstance(key, unicode)) # noqa | ||
self.assertTrue(isinstance(val, unicode)) # noqa | ||
|
||
|
||
class TestStringLoad(testing.TestCase): | ||
|
||
def setUp(self): | ||
self.yaml = file_format.load_file( | ||
'./charlatan/tests/data/strings.yaml', | ||
) | ||
|
||
@unittest.skipIf(version_info[0] == 3, 'Iteration has changed in Python 3') | ||
def test_strings_are_strings(self): | ||
"""Assert all strings are loaded as strings""" | ||
for key, val in self.yaml.items(): | ||
self.assertTrue(isinstance(key, str)) | ||
self.assertTrue(isinstance(val, str)) | ||
|
||
@unittest.skipIf(version_info[0] == 2, 'Iteration has changed in Python 3') | ||
def test_strings_are_strings_python3(self): | ||
"""Assert all strings are loaded as strings""" | ||
for key, val in list(self.yaml.items()): | ||
self.assertTrue(isinstance(key, str)) | ||
self.assertTrue(isinstance(val, str)) |
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