forked from spotify/chartify
-
Notifications
You must be signed in to change notification settings - Fork 0
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 spotify#115 from danielnorberg/support-pyyaml-5.2+
Support pyyaml 5.2+
- Loading branch information
Showing
3 changed files
with
67 additions
and
2 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
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 |