[testing] testing the error messages for plotting

This commit is contained in:
mzwiessele 2015-11-30 10:49:49 +00:00
parent 065ab725ff
commit 3c618c1525
2 changed files with 16 additions and 9 deletions

View file

@ -1,11 +1,9 @@
# Copyright (c) 2014, GPy authors (see AUTHORS.txt).
# Licensed under the BSD 3-clause license (see LICENSE.txt)
from ConfigParser import NoOptionError
current_lib = [None]
supported_libraries = ['matplotlib', 'plotly', 'none']
error_suggestion = "Please make sure you specify your plotting library in your configuration file.\n\n[plotting]\nlibrary = <library>\n\nCurrently supported libraries: {}".format(", ".join(supported_libraries))
error_suggestion = "Please make sure you specify your plotting library in your configuration file (<User>/.config/GPy/user.cfg).\n\n[plotting]\nlibrary = <library>\n\nCurrently supported libraries: {}".format(", ".join(supported_libraries))
def change_plotting_library(lib):
try:
@ -15,7 +13,7 @@ def change_plotting_library(lib):
# This is hooking the library in
# for the usage in GPy:
if lib not in supported_libraries:
raise NoOptionError("Warning: Plotting library {} not recognized, currently supported libraries are: \n {}".format(lib, ", ".join(supported_libraries)))
raise ValueError("Warning: Plotting library {} not recognized, currently supported libraries are: \n {}".format(lib, ", ".join(supported_libraries)))
if lib == 'matplotlib':
import matplotlib
from .matplot_dep.plot_definitions import MatplotlibPlots
@ -31,15 +29,15 @@ def change_plotting_library(lib):
except (ImportError, NameError):
config.set('plotting', 'library', 'none')
import warnings
warnings.warn(ImportWarning("{} not available, install newest version of {} for plotting".format(lib, lib)))
warnings.warn(ImportWarning("You spevified {} in your configuration, but is not available. Install newest version of {} for plotting".format(lib, lib)))
from ConfigParser import NoOptionError
from ..util.config import config
try:
lib = config.get('plotting', 'library')
change_plotting_library(lib)
except NoOptionError:
print("No plotting library was specified. \n{}".format(error_suggestion))
print("No plotting library was specified in config file. \n{}".format(error_suggestion))
def plotting_library():
if current_lib[0] is None: