Skip to content

Commit

Permalink
Added Parser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 25, 2016
1 parent 403a669 commit ca72def
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/testparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ def test_plot_opts_with_space_explicit(self):
Options(title_format='foo bar', fig_inches=(3, 3))}}
self.assertEqual(OptsSpec.parse(line), expected)

def test_plot_opts_dict_with_space(self):
line = "Curve [fontsize={'xlabel': 10, 'title': 20}]"
expected = {'Curve': {'plot': Options(fontsize={'xlabel': 10, 'title': 20})}}
self.assertEqual(OptsSpec.parse(line), expected)

def test_plot_opts_dict_without_space(self):
line = "Curve [fontsize=dict(xlabel=10,title=20)]"
expected = {'Curve': {'plot': Options(fontsize={'xlabel': 10, 'title': 20})}}
self.assertEqual(OptsSpec.parse(line), expected)

def test_plot_opts_nested_brackets(self):
line = "Curve [title_format=', '.join(('A', 'B'))]"
expected = {'Curve': {'plot': Options(title_format='A, B')}}
self.assertEqual(OptsSpec.parse(line), expected)


class OptsSpecStyleOptionsTests(ComparisonTestCase):
Expand Down Expand Up @@ -90,6 +104,38 @@ def test_style_opts_advanced(self):
color=Cycle(values=[1,2]))}}
self.assertEqual(OptsSpec.parse(line), expected)

def test_style_opts_dict_with_space(self):
line = "Curve (fontsize={'xlabel': 10, 'title': 20})"
expected = {'Curve': {'style': Options(fontsize={'xlabel': 10, 'title': 20})}}
self.assertEqual(OptsSpec.parse(line), expected)

def test_style_opts_dict_without_space(self):
line = "Curve (fontsize={'xlabel': 10,'title': 20})"
expected = {'Curve': {'style': Options(fontsize={'xlabel': 10, 'title': 20})}}
self.assertEqual(OptsSpec.parse(line), expected)

def test_style_opts_cycle_function(self):
# Explicitly compare because list of arrays do not compare correctly
import numpy as np
np.random.seed(42)
line = "Curve (color=Cycle(values=list(np.random.rand(3,3))))"
options = OptsSpec.parse(line, {'np': np, 'Cycle': Cycle})
self.assertTrue('Curve' in options)
self.assertTrue('style' in options['Curve'])
self.assertTrue('color' in options['Curve']['style'].kwargs)
self.assertTrue(isinstance(options['Curve']['style'].kwargs['color'], Cycle))
values = np.array([[ 0.37454012, 0.95071431, 0.73199394],
[ 0.59865848, 0.15601864, 0.15599452],
[ 0.05808361, 0.86617615, 0.60111501]])
expected = {'Curve': {'style': Options(color=Cycle(values=list(values)))}}
self.assertEqual(np.array(options['Curve']['style'].kwargs['color'].values),
values)

def test_style_opts_cycle_list(self):
line = "Curve (color=Cycle(values=['r', 'g', 'b']))"
expected = {'Curve': {'style': Options(color=Cycle(values=['r', 'g', 'b']))}}
self.assertEqual(OptsSpec.parse(line, {'Cycle': Cycle}), expected)



class OptsNormPlotOptionsTests(ComparisonTestCase):
Expand Down

0 comments on commit ca72def

Please sign in to comment.