• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2.4
2#
3# Copyright 2008 Google Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""Tests for bar_chart.py."""
18
19import warnings
20
21from graphy import common
22from graphy import bar_chart
23from graphy import graphy_test
24from graphy.backends import google_chart_api
25
26
27class BarChartTest(graphy_test.GraphyTest):
28
29  def setUp(self):
30    self.chart = google_chart_api.BarChart()
31
32  def tearDown(self):
33    warnings.resetwarnings()
34
35  # TODO: remove once the deprecation warning is removed
36  def testBarStyleStillExists(self):
37    warnings.filterwarnings('ignore')
38    x = bar_chart.BarStyle(None, None, None)
39
40  # TODO: remove once the deprecation warning is removed
41  def testAddBarArgumentOrder(self):
42    # Deprecated approach
43    chart = bar_chart.BarChart()
44    warnings.filterwarnings('error')
45    self.assertRaises(DeprecationWarning, chart.AddBars, [1, 2, 3],
46      '0000FF', 'label')
47
48    # New order
49    chart = bar_chart.BarChart()
50    chart.AddBars([1, 2, 3], 'label', '0000FF')
51    self.assertEqual('label', chart.data[0].label)
52    self.assertEqual('0000FF', chart.data[0].style.color)
53
54  def testGetDependentIndependentAxes(self):
55    c = self.chart
56    c.vertical = True
57    self.assertEqual([c.left, c.right], c.GetDependentAxes())
58    self.assertEqual([c.top, c.bottom], c.GetIndependentAxes())
59    c.vertical = False
60    self.assertEqual([c.top, c.bottom], c.GetDependentAxes())
61    self.assertEqual([c.left, c.right], c.GetIndependentAxes())
62
63    right2 = c.AddAxis(common.AxisPosition.RIGHT, common.Axis())
64    bottom2 = c.AddAxis(common.AxisPosition.BOTTOM, common.Axis())
65
66    c.vertical = True
67    self.assertEqual([c.left, c.right, right2], c.GetDependentAxes())
68    self.assertEqual([c.top, c.bottom, bottom2], c.GetIndependentAxes())
69    c.vertical = False
70    self.assertEqual([c.top, c.bottom, bottom2], c.GetDependentAxes())
71    self.assertEqual([c.left, c.right, right2], c.GetIndependentAxes())
72
73  def testDependentIndependentAxis(self):
74    self.chart.vertical = True
75    self.assertTrue(self.chart.left is self.chart.GetDependentAxis())
76    self.assertTrue(self.chart.bottom is self.chart.GetIndependentAxis())
77    self.chart.vertical = False
78    self.assertTrue(self.chart.bottom, self.chart.GetDependentAxis())
79    self.assertTrue(self.chart.left, self.chart.GetIndependentAxis())
80
81
82if __name__ == '__main__':
83  graphy_test.main()
84