From 6114a1dd0e68da86c32243756e8749fb17d1238a Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Tue, 25 Oct 2016 17:51:07 +0100
Subject: [PATCH] Added Parser tests
---
tests/testparsers.py | 46 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/tests/testparsers.py b/tests/testparsers.py
index 2f5d1a4ab1..8aea7933bb 100644
--- a/tests/testparsers.py
+++ b/tests/testparsers.py
@@ -48,6 +48,30 @@ 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_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_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):
@@ -90,6 +114,28 @@ def test_style_opts_advanced(self):
color=Cycle(values=[1,2]))}}
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):