Skip to content

Commit

Permalink
Merge pull request spotify#115 from danielnorberg/support-pyyaml-5.2+
Browse files Browse the repository at this point in the history
Support pyyaml 5.2+
  • Loading branch information
danielnorberg authored Oct 16, 2020
2 parents 36bdcb0 + c4127b9 commit 8fe14fb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
3 changes: 2 additions & 1 deletion chartify/_core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def _from_yaml(self, filename):
Overwrites any options that are specified in the yaml file.
"""
yaml_options = yaml.load(open(filename), Loader=yaml.FullLoader)
# Note: We assume that the contents of the config file are trusted
yaml_options = yaml.load(open(filename), Loader=yaml.UnsafeLoader)
self._options.update(yaml_options)


Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ selenium>=3.7.0,<=3.8.0
bokeh>=2.0.0,<3.0.0
scipy>=1.0.0,<2.0.0
ipykernel>=5.0
ipython>=7.0
ipython>=7.0
pyyaml>=5.3.1
63 changes: 63 additions & 0 deletions tests/test_options_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017-2020 Spotify AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from tempfile import TemporaryDirectory

OPTIONS_CONFIG = '''\
!!python/object/apply:collections.OrderedDict
- - - style.color_palette_categorical
- !!python/object:chartify._core.options.OptionValue
value: My Palette
- - style.color_palette_sequential
- !!python/object:chartify._core.options.OptionValue
value: Midnight Orange Sequential
- - style.color_palette_diverging
- !!python/object:chartify._core.options.OptionValue
value: Midnight Orange Diverging
- - style.color_palette_accent
- !!python/object:chartify._core.options.OptionValue
value: My Palette
- - style.color_palette_accent_default_color
- !!python/object:chartify._core.options.OptionValue
value: light grey
'''

EXPECTED_CONFIG = {
'style.color_palette_categorical': 'My Palette',
'style.color_palette_sequential': 'Midnight Orange Sequential',
'style.color_palette_diverging': 'Midnight Orange Diverging',
'style.color_palette_accent': 'My Palette',
'style.color_palette_accent_default_color': 'light grey',
}


def test_options_config(monkeypatch):
with TemporaryDirectory() as tmp:
with open(os.path.join(tmp, 'options_config.yaml'), 'w') as f:
f.write(OPTIONS_CONFIG)

# XXX (dano): CHARTIFY_CONFIG_DIR must end with /
monkeypatch.setenv('CHARTIFY_CONFIG_DIR', os.path.join(tmp, ''))

# (re-)import options module to reload configuration
import chartify._core.options
import importlib
chartify = importlib.reload(chartify._core.options)

config = {key: chartify.options.get_option(key)
for key in EXPECTED_CONFIG}
assert config == EXPECTED_CONFIG

0 comments on commit 8fe14fb

Please sign in to comment.