File: test_empty_collections.py

package info (click to toggle)
python-mpld3 0.3git%2B20140910dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,808 kB
  • ctags: 1,095
  • sloc: python: 3,595; makefile: 187
file content (24 lines) | stat: -rw-r--r-- 843 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import unittest
import numpy as np
import matplotlib.pyplot as plt
import mpld3

class empty_collection_tests(unittest.TestCase):
    """ Ensure that mpld3renderer filters out empty line collections. """

    def test_extra_contour(self):
        """ Create an empty line collection by requesting invalid contours, and
        check that a collection with length(paths) === 0 is not passed to the
        JavaScript.
        """
        fig, ax = plt.subplots()
        X, Y = np.mgrid[0:5, 0:5]
        Z = X**2 - Y**2
        ax.contour(X, Y, Z, range(-15, 18, 2))  # last contour level is 17
                                                # but Z.max() is 16
        jsondict = mpld3.fig_to_dict(fig)

        for collection in jsondict["axes"][0]["collections"]:
            self.assertTrue(len(collection["paths"]) != 0)
        return