Skip to content

Commit

Permalink
takes into account changes from PyYaml 5.1
Browse files Browse the repository at this point in the history
fix #80
  • Loading branch information
Adrien Oyono committed Mar 18, 2019
1 parent 7436d3f commit 7b64652
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions eodag/config.py
Expand Up @@ -39,7 +39,7 @@ class SimpleYamlProxyConfig(object):
def __init__(self, conf_file_path):
with open(os.path.abspath(os.path.realpath(conf_file_path)), 'r') as fh:
try:
self.source = yaml.load(fh)
self.source = yaml.load(fh, Loader=yaml.SafeLoader)
utf8_everywhere(self.source)
except yaml.parser.ParserError as e:
print('Unable to load user configuration file')
Expand Down Expand Up @@ -178,7 +178,7 @@ def load_default_config():
try:
# Providers configs are stored in this file as separated yaml documents
# Load all of it
providers_configs = yaml.load_all(fh)
providers_configs = yaml.load_all(fh, Loader=yaml.Loader)
except yaml.parser.ParserError as e:
logger.error('Unable to load configuration')
raise e
Expand Down
24 changes: 12 additions & 12 deletions tests/test_config.py
Expand Up @@ -24,7 +24,7 @@
import yaml.parser
from six import StringIO

from .context import ValidationError, config
from tests.context import ValidationError, config


class TestProviderConfig(unittest.TestCase):
Expand All @@ -43,14 +43,14 @@ def test_provider_config_name(self):
EODAG_PRODUCT_TYPE: provider_product_type
'''.format(unslugified_provider_name)
)
provider_config = yaml.load(stream)
provider_config = yaml.load(stream, Loader=yaml.Loader)
self.assertEqual(provider_config.name, slugified_provider_name)

def test_provider_config_valid(self):
"""Provider config must be valid"""
# Not defining any plugin at all
invalid_stream = StringIO('''!provider\nname: my_provider''')
self.assertRaises(ValidationError, yaml.load, invalid_stream)
self.assertRaises(ValidationError, yaml.load, invalid_stream, Loader=yaml.Loader)

# Not defining a class for a plugin
invalid_stream = StringIO(
Expand All @@ -59,15 +59,15 @@ def test_provider_config_valid(self):
search: !plugin
param: value
''')
self.assertRaises(ValidationError, yaml.load, invalid_stream)
self.assertRaises(ValidationError, yaml.load, invalid_stream, Loader=yaml.Loader)

# Not giving a name to the provider
invalid_stream = StringIO(
'''!provider
api: !plugin
type: MyPluginClass
''')
self.assertRaises(ValidationError, yaml.load, invalid_stream)
self.assertRaises(ValidationError, yaml.load, invalid_stream, Loader=yaml.Loader)

# Specifying an api plugin and a search or download or auth plugin at the same type
invalid_stream1 = StringIO(
Expand All @@ -91,9 +91,9 @@ def test_provider_config_valid(self):
auth: !plugin
type: MyPluginClass4
''')
self.assertRaises(ValidationError, yaml.load, invalid_stream1)
self.assertRaises(ValidationError, yaml.load, invalid_stream2)
self.assertRaises(ValidationError, yaml.load, invalid_stream3)
self.assertRaises(ValidationError, yaml.load, invalid_stream1, Loader=yaml.Loader)
self.assertRaises(ValidationError, yaml.load, invalid_stream2, Loader=yaml.Loader)
self.assertRaises(ValidationError, yaml.load, invalid_stream3, Loader=yaml.Loader)

def test_provider_config_update(self):
"""A provider config must be update-able with a dict"""
Expand All @@ -106,7 +106,7 @@ def test_provider_config_update(self):
plugin_param1: value1
pluginParam2: value2
''')
provider_config = yaml.load(valid_stream)
provider_config = yaml.load(valid_stream, Loader=yaml.Loader)
overrides = {
'provider_param': 'new val',
'api': {
Expand All @@ -130,14 +130,14 @@ def test_plugin_config_valid(self):
'''!plugin
param: value
''')
self.assertRaises(ValidationError, yaml.load, invalid_stream)
self.assertRaises(ValidationError, yaml.load, invalid_stream, Loader=yaml.Loader)

valid_stream = StringIO(
'''!plugin
type: MySearchPlugin
param1: value
''')
self.assertIsInstance(yaml.load(valid_stream), config.PluginConfig)
self.assertIsInstance(yaml.load(valid_stream, Loader=yaml.Loader), config.PluginConfig)

def test_plugin_config_update(self):
"""A plugin config must be update-able by a dict"""
Expand All @@ -149,7 +149,7 @@ def test_plugin_config_update(self):
sub_param1: v1
subParam_2: v2
''')
plugin_config = yaml.load(valid_stream)
plugin_config = yaml.load(valid_stream, Loader=yaml.Loader)
overrides = {
'type': 'MyOtherPlugin',
'new_plugin_param': 'a value',
Expand Down

0 comments on commit 7b64652

Please sign in to comment.