Skip to content

Commit

Permalink
add: PyYAML 6.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Liu Xue Yan committed Nov 9, 2021
1 parent 0cf6389 commit 8aa4fc7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package_dir =
packages = find:
python_requires = >=3.5
install_requires =
PyYAML>=5.1,<6.0
PyYAML>=5.1,<7.0
tests_require =
toml

Expand Down
2 changes: 1 addition & 1 deletion tests/_internel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
warn(Warning(err))
else:
YAML_LOADERS += [CBaseLoader, CSafeLoader, CLoader]
elif '5.0' <= yaml.__version__ < '6.0':
elif '5.0' <= yaml.__version__ < '7.0':
from yaml import BaseLoader, SafeLoader, Loader, FullLoader, UnsafeLoader

YAML_LOADERS = [BaseLoader, SafeLoader, Loader, FullLoader, UnsafeLoader]
Expand Down
24 changes: 15 additions & 9 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ class DefaultLoaderTestCase(unittest.TestCase):
def setUp(self):
YamlIncludeConstructor.add_to_loader_class()

def test_no_loader_class_argument(self):
yml = '!include tests/data/include.d/1.yaml'
if yaml.__version__ >= '5.0' and PYTHON_VERSION_MAYOR_MINOR >= '3.2':
with self.assertWarns(yaml.YAMLLoadWarning):
if yaml.__version__ < '6.0':

def test_no_loader_class_argument(self):
yml = '!include tests/data/include.d/1.yaml'
if yaml.__version__ >= '5.0' and PYTHON_VERSION_MAYOR_MINOR >= '3.2':
with self.assertWarns(yaml.YAMLLoadWarning):
data = yaml.load(StringIO(yml))
else:
data = yaml.load(StringIO(yml))
else:
data = yaml.load(StringIO(yml))
self.assertDictEqual(data, YAML1)
self.assertDictEqual(data, YAML1)


class MultiLoadersTestCase(unittest.TestCase):
Expand Down Expand Up @@ -310,7 +312,9 @@ def setUp(self):

def test_txt(self):
yml = 'text: !include tests/data/include.d/1.txt'
if yaml.__version__ >= '5.0' and PYTHON_VERSION_MAYOR_MINOR >= '3.2':
if yaml.__version__ >= '6.0':
data = yaml.load(StringIO(yml), yaml.Loader)
elif yaml.__version__ >= '5.0' and PYTHON_VERSION_MAYOR_MINOR >= '3.2':
with self.assertWarns(yaml.YAMLLoadWarning):
data = yaml.load(StringIO(yml))
else:
Expand All @@ -327,7 +331,9 @@ def setUp(self):

def test_txt(self):
yml = 'text: !include {pathname: tests/data/include.d/1.json, reader: txt}'
if yaml.__version__ >= '5.0' and PYTHON_VERSION_MAYOR_MINOR >= '3.2':
if yaml.__version__ >= '6.0':
data = yaml.load(StringIO(yml), yaml.Loader)
elif '6.0' > yaml.__version__ >= '5.0' and PYTHON_VERSION_MAYOR_MINOR >= '3.2':
with self.assertWarns(yaml.YAMLLoadWarning):
data = yaml.load(StringIO(yml))
else:
Expand Down

0 comments on commit 8aa4fc7

Please sign in to comment.