Esempio n. 1
0
    def test_draw_legend_inherit_not_overriden(self):
        """
		Test that drawing legend labels, any value that is not overriden is inherited.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        values = [{
            'value': 10,
            'label': 'label'
        }, {
            'value': 10,
            'label': 'another',
            'style': {
                'color': '#00FF00'
            },
            'label_style': {
                'color': '#FFFF00'
            }
        }]
        label_style = {'color': '#0000FF', 'alpha': 0.5}
        bars = bar.draw(values,
                        'label',
                        color='#FF0000',
                        label_style=label_style)
        self.assertEqual(2, len(viz.legend.lines[0]))
        _, annotation = viz.legend.lines[0][0]
        self.assertEqual('#0000FF', annotation.lines[0][0].get_color())
        self.assertEqual(0.5, annotation.lines[0][0].get_alpha())
        _, annotation = viz.legend.lines[0][1]
        self.assertEqual('#FFFF00', annotation.lines[0][0].get_color())
        self.assertEqual(0.5, annotation.lines[0][0].get_alpha())
Esempio n. 2
0
    def test_to_dict_mix(self):
        """
		Test converting a mixed list of floats and dictionaries to a dictionary.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        values = [
            10, {
                'value': 5
            }, {
                'style': {
                    'color': 'red'
                }
            }, {
                'value': 2,
                'style': {
                    'color': 'blue'
                }
            }
        ]
        dicts = bar._to_dict(values)
        self.assertEqual([10, 5, 0, 2], [value['value'] for value in dicts])
        self.assertEqual([{}, {}, {
            'color': 'red'
        }, {
            'color': 'blue'
        }], [value['style'] for value in dicts])
Esempio n. 3
0
    def test_draw_legend_repeated_labels(self):
        """
		Test that when providing repeated labels, only the first one is drawn.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        values = [{
            'value': 10,
            'label': 'A'
        }, {
            'value': 10,
            'label': 'B'
        }, {
            'value': 10,
            'label': 'C'
        }, {
            'value': 10,
            'label': 'A'
        }]
        bars = bar.draw(values, 'label')
        self.assertEqual(3, len(viz.legend.lines[0]))
        self.assertEqual(
            ['A', 'B', 'C'],
            [str(annotation) for _, annotation in viz.legend.lines[0]])
Esempio n. 4
0
    def test_draw_legend_bar_label_style_overrides_label_style(self):
        """
		Test that drawing legend labels, the bar's specific label style overrides the general label style.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        values = [{
            'value': 10,
            'label': 'label'
        }, {
            'value': 10,
            'label': 'another',
            'style': {
                'color': '#00FF00'
            },
            'label_style': {
                'color': '#FFFF00'
            }
        }]
        label_style = {'color': '#0000FF'}
        bars = bar.draw(values,
                        'label',
                        color='#FF0000',
                        label_style=label_style)
        self.assertEqual(2, len(viz.legend.lines[0]))
        _, annotation = viz.legend.lines[0][0]
        self.assertEqual('#0000FF', annotation.lines[0][0].get_color())
        _, annotation = viz.legend.lines[0][1]
        self.assertEqual('#FFFF00', annotation.lines[0][0].get_color())
Esempio n. 5
0
    def test_draw_legend_labels(self):
        """
		Test that when providing labels, they are drawn in the legend.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        values = [{
            'value': 10,
            'label': 'A'
        }, {
            'value': 10,
            'label': 'B'
        }, {
            'value': 10,
            'label': 'C'
        }, {
            'value': 10,
            'label': 'D'
        }]
        bars = bar.draw(values, 'label')
        self.assertEqual(4, len(viz.legend.lines[0]))
        self.assertEqual(
            ['A', 'B', 'C', 'D'],
            [str(annotation) for _, annotation in viz.legend.lines[0]])
Esempio n. 6
0
    def test_draw_override_pad(self):
        """
		Test that when drawing bars, padding can be overriden through the style.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        values = [{
            'value': 10
        }, {
            'value': 10,
            'style': {}
        }, {
            'value': 10,
            'style': {
                'pad': 0
            }
        }, {
            'value': 10
        }]
        bars = bar.draw(values, 'label', pad=1)
        self.assertEqual(
            24, round(util.get_bb(viz.figure, viz.axes, bars[1]).width, 10))
        self.assertEqual(
            25, round(util.get_bb(viz.figure, viz.axes, bars[2]).width, 10))
Esempio n. 7
0
    def test_to_100_min_percentage_100(self):
        """
		Test that when the minimum percentage is 100, percentage conversion does not raise a ValueError.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertTrue(bar._to_100([1], 100))
Esempio n. 8
0
    def test_to_100_add_up_to_100(self):
        """
		Test that when converting values to percentages, the returned percentages add up to 100%.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertEqual(100, sum(bar._to_100([10] * 3)))
Esempio n. 9
0
    def test_to_100_zero_values(self):
        """
		Test that when zero values are given to be converted to percentages, the same list is returned.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertEqual([0, 0], bar._to_100([0, 0]))
Esempio n. 10
0
    def test_to_100_empty_values(self):
        """
		Test that when no values are given to be converted to percentages, an empty list is returned again.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertEqual([], bar._to_100([]))
Esempio n. 11
0
    def test_pad_below_percentage(self):
        """
        Test that when the padding is below the percentage, no ValueError is raised.
        """

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertEqual(10, bar._pad(50, 20))
Esempio n. 12
0
    def test_draw_min_percentage_0(self):
        """
		Test that when the minimum percentage is 0, drawing does not raise a ValueError.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertTrue(bar.draw([1], 'label', min_percentage=0))
Esempio n. 13
0
    def test_pad_no_space(self):
        """
		Test that when the minimum percentage is equal to the percentage, the original percentage is returned.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertEqual(0, bar._pad(50, 10, 50))
Esempio n. 14
0
    def test_to_100_min_percentage_equals_100(self):
        """
		Test that when the minimum percentage multiplied by the number of values is equal to 100, percentage conversion does not raise a ValueError.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertTrue(bar._to_100([1, 1], 50))
Esempio n. 15
0
    def test_draw_empty_label(self):
        """
		Test that when drawing bars, the label cannot be empty.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertRaises(ValueError, bar.draw, [1, 1], '')
Esempio n. 16
0
    def test_too_much_pad(self):
        """
		Test that when too much padding is given, not all of it is used.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertEqual(15, bar._pad(50, 50, 20))
Esempio n. 17
0
    def test_pad_all_space(self):
        """
		Test that padding and the left-over percentage fill in all the space.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertEqual(50, bar._pad(50, 10, 20) * 2 + 40)
Esempio n. 18
0
    def test_pad_one_side(self):
        """
		Test that the returned padding is half of the amount of padding applied.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertEqual(5, bar._pad(50, 10, 20))
Esempio n. 19
0
    def test_to_100_min_percentage_above_100(self):
        """
		Test that when the minimum percentage is above 100, percentage conversion raises a ValueError.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertRaises(ValueError, bar._to_100, [1], 101)
Esempio n. 20
0
    def test_pad_pad_below_0(self):
        """
		Test that when the padding is below 0, padding raises a ValueError.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertRaises(ValueError, bar._pad, 0, -1, 0)
Esempio n. 21
0
    def test_to_100_min_percentage_exceeds_100(self):
        """
		Test that when the minimum percentage multiplied by the number of values exceeds 100, percentage conversion raises a ValueError.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertRaises(ValueError, bar._to_100, [1, 1], 75)
Esempio n. 22
0
    def test_pad_no_padding(self):
        """
		Test that when applying no padding, zero is returned.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertEqual(0, bar._pad(50, 0, 20))
Esempio n. 23
0
    def test_to_100_min_percentage_sums_100(self):
        """
		Test that when converting values to percentages with a minimum percentage, the values still add up to 100%.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertEqual(100, sum(bar._to_100([1, 2], 50)))
Esempio n. 24
0
    def test_pad_min_percentage_above_100(self):
        """
		Test that when the minimum percentage is above 100, padding raises a ValueError.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertRaises(ValueError, bar._pad, 0, 0, 101)
Esempio n. 25
0
    def test_pad_pad_0(self):
        """
		Test that when the padding is 0, padding does not raise a ValueError.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertEqual(0, bar._pad(10, 0, 0))
Esempio n. 26
0
    def test_pad_more_than_percentage(self):
        """
        Test that when too much padding is given, a ValueError is raised.
        """

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertRaises(ValueError, bar._pad, 50, 60)
Esempio n. 27
0
    def test_pad_min_percentage_100(self):
        """
		Test that when the minimum percentage is 100, padding does not raise a ValueError.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertEqual(0, bar._pad(100, 0, 100))
Esempio n. 28
0
    def test_pad_equal_percentage(self):
        """
        Test that when the padding is equal to the percentage, no ValueError is raised.
        """

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertTrue(bar._pad(50, 50))
Esempio n. 29
0
    def test_pad_min_percentage_exceeds_percentage(self):
        """
		Test that when the minimum percentage exceeds the percentage, padding raises a ValueError.
		"""

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertRaises(ValueError, bar._pad, 50, 0, 51)
Esempio n. 30
0
    def test_draw_min_percentage_below_0(self):
        """
        Test that when the minimum percentage is below 0, drawing raises a ValueError.
        """

        viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
        bar = Bar100(viz)
        self.assertRaises(ValueError, bar.draw, [ 1 ], 'label', min_percentage=-1)