File: tests.py

package info (click to toggle)
python-descartes 1.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 108 kB
  • sloc: python: 151; makefile: 5
file content (95 lines) | stat: -rw-r--r-- 3,158 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from shapely.geometry import Point, MultiPoint
import unittest

from descartes.patch import PolygonPatch


class PolygonTestCase(unittest.TestCase):

    polygon = Point(0, 0).buffer(10.0).difference(
        MultiPoint([(-5, 0), (5, 0)]).buffer(3.0))

    def test_patch(self):
        patch = PolygonPatch(self.polygon)
        self.failUnlessEqual(
            str(type(patch)), "<class 'matplotlib.patches.PathPatch'>")
        path = patch.get_path()
        self.failUnless(len(path.vertices) == len(path.codes) == 198)


class JSONPolygonTestCase(unittest.TestCase):

    polygon = Point(0, 0).buffer(10.0).difference(
        MultiPoint([(-5, 0), (5, 0)]).buffer(3.0))

    def test_patch(self):
        geo = self.polygon.__geo_interface__
        patch = PolygonPatch(geo)
        self.failUnlessEqual(
            str(type(patch)), "<class 'matplotlib.patches.PathPatch'>")
        path = patch.get_path()
        self.failUnless(len(path.vertices) == len(path.codes) == 198)


class GeoInterfacePolygonTestCase(unittest.TestCase):

    class GeoThing:
        __geo_interface__ = None

    thing = GeoThing()
    thing.__geo_interface__ = Point(0, 0).buffer(10.0).difference(
        MultiPoint([(-5, 0), (5, 0)]).buffer(3.0)).__geo_interface__

    def test_patch(self):
        patch = PolygonPatch(self.thing)
        self.failUnlessEqual(
            str(type(patch)), "<class 'matplotlib.patches.PathPatch'>")
        path = patch.get_path()
        self.failUnless(len(path.vertices) == len(path.codes) == 198)


class MultiPolygonTestCase(unittest.TestCase):

    polygon = Point(0, 0).buffer(10.0) .difference(
        MultiPoint([(-5, 0), (5, 0)]).buffer(3.0)).union(
        MultiPoint([(-10, 10), (10, -10)]).buffer(2.0))

    def test_patch(self):
        patch = PolygonPatch(self.polygon)
        self.failUnlessEqual(
            str(type(patch)), "<class 'matplotlib.patches.PathPatch'>")
        path = patch.get_path()
        self.failUnless(len(path.vertices) == len(path.codes) == 330)


class JSONMultiPolygonTestCase(unittest.TestCase):

    polygon = Point(0, 0).buffer(10.0).difference(
        MultiPoint([(-5, 0), (5, 0)]).buffer(3.0)).union(
        MultiPoint([(-10, 10), (10, -10)]).buffer(2.0))

    def test_patch(self):
        geo = self.polygon.__geo_interface__
        patch = PolygonPatch(geo)
        self.failUnlessEqual(
            str(type(patch)), "<class 'matplotlib.patches.PathPatch'>")
        path = patch.get_path()
        self.failUnless(len(path.vertices) == len(path.codes) == 330)


class GeoInterfaceMultiPolygonTestCase(unittest.TestCase):

    class GeoThing:
        __geo_interface__ = None

    thing = GeoThing()
    thing.__geo_interface__ = Point(0, 0).buffer(10.0).difference(
        MultiPoint([(-5, 0), (5, 0)]).buffer(3.0)).union(
        MultiPoint([(-10, 10), (10, -10)]).buffer(2.0)).__geo_interface__

    def test_patch(self):
        patch = PolygonPatch(self.thing)
        self.failUnlessEqual(
            str(type(patch)), "<class 'matplotlib.patches.PathPatch'>")
        path = patch.get_path()
        self.failUnless(len(path.vertices) == len(path.codes) == 330)