sketchingpy.test.test_geo

 1import unittest
 2
 3import sketchingpy.geo
 4
 5
 6class GeoTests(unittest.TestCase):
 7
 8    def setUp(self):
 9        # Center the map on San Francisco and place in middle of sketch
10        center_longitude = -122.418343
11        center_latitude = 37.761842
12        center_x = 250
13        center_y = 250
14        map_scale = 100
15
16        # Create a geo transformation that ties pixel to geo coordinates
17        self._transformation = sketchingpy.geo.GeoTransformation(
18            sketchingpy.geo.GeoPoint(center_longitude, center_latitude),  # Where to center geographically
19            sketchingpy.geo.PixelOffset(center_x, center_y),  # Where to center in terms of pixels
20            map_scale  # How much zoom
21        )
22
23
24    def test_point(self):
25        point = sketchingpy.geo.GeoPoint(-122.262938, 37.873139)
26        self.assertAlmostEqual(point.get_x(transform=self._transformation), 422.9960546672828)
27        self.assertAlmostEqual(point.get_y(transform=self._transformation), 93.16413302587421)
28
29    def test_polygon(self):
30        points = [
31            sketchingpy.geo.GeoPoint(-122, 38),
32            sketchingpy.geo.GeoPoint(-121, 38),
33            sketchingpy.geo.GeoPoint(-121, 37),
34            sketchingpy.geo.GeoPoint(-122, 37)
35        ]
36        geo_polygon = sketchingpy.geo.GeoPolygon(points)
37        shape = geo_polygon.to_shape(transform=self._transformation)
38        self.assertAlmostEqual(shape.get_start_x(), 715.6972973692973)
39        self.assertAlmostEqual(shape.get_start_y(), -85.89322991684298)
40
41    def test_parse_geojson(self):
42        test_source = {
43            'features': [{
44                'geometry': {
45                    'type': 'Polygon',
46                    'coordinates': [[
47                        [-122, 38],
48                        [-121, 38],
49                        [-121, 37],
50                        [-122, 37],
51                    ]]
52                }
53            }]
54        }
55        polygons = sketchingpy.geo.parse_geojson(test_source)
56
57        self.assertEqual(len(polygons), 1)
58        polygon = polygons[0]
59
60        self.assertEqual(len(polygon), 4)
61        first_point = polygon[0]
62        self.assertAlmostEqual(first_point[0], -122)
63        self.assertAlmostEqual(first_point[1], 38)
class GeoTests(unittest.case.TestCase):
 7class GeoTests(unittest.TestCase):
 8
 9    def setUp(self):
10        # Center the map on San Francisco and place in middle of sketch
11        center_longitude = -122.418343
12        center_latitude = 37.761842
13        center_x = 250
14        center_y = 250
15        map_scale = 100
16
17        # Create a geo transformation that ties pixel to geo coordinates
18        self._transformation = sketchingpy.geo.GeoTransformation(
19            sketchingpy.geo.GeoPoint(center_longitude, center_latitude),  # Where to center geographically
20            sketchingpy.geo.PixelOffset(center_x, center_y),  # Where to center in terms of pixels
21            map_scale  # How much zoom
22        )
23
24
25    def test_point(self):
26        point = sketchingpy.geo.GeoPoint(-122.262938, 37.873139)
27        self.assertAlmostEqual(point.get_x(transform=self._transformation), 422.9960546672828)
28        self.assertAlmostEqual(point.get_y(transform=self._transformation), 93.16413302587421)
29
30    def test_polygon(self):
31        points = [
32            sketchingpy.geo.GeoPoint(-122, 38),
33            sketchingpy.geo.GeoPoint(-121, 38),
34            sketchingpy.geo.GeoPoint(-121, 37),
35            sketchingpy.geo.GeoPoint(-122, 37)
36        ]
37        geo_polygon = sketchingpy.geo.GeoPolygon(points)
38        shape = geo_polygon.to_shape(transform=self._transformation)
39        self.assertAlmostEqual(shape.get_start_x(), 715.6972973692973)
40        self.assertAlmostEqual(shape.get_start_y(), -85.89322991684298)
41
42    def test_parse_geojson(self):
43        test_source = {
44            'features': [{
45                'geometry': {
46                    'type': 'Polygon',
47                    'coordinates': [[
48                        [-122, 38],
49                        [-121, 38],
50                        [-121, 37],
51                        [-122, 37],
52                    ]]
53                }
54            }]
55        }
56        polygons = sketchingpy.geo.parse_geojson(test_source)
57
58        self.assertEqual(len(polygons), 1)
59        polygon = polygons[0]
60
61        self.assertEqual(len(polygon), 4)
62        first_point = polygon[0]
63        self.assertAlmostEqual(first_point[0], -122)
64        self.assertAlmostEqual(first_point[1], 38)

A class whose instances are single test cases.

By default, the test code itself should be placed in a method named 'runTest'.

If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.

Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.

If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.

When subclassing TestCase, you can set these attributes:

  • failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
  • longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
  • maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
def setUp(self):
 9    def setUp(self):
10        # Center the map on San Francisco and place in middle of sketch
11        center_longitude = -122.418343
12        center_latitude = 37.761842
13        center_x = 250
14        center_y = 250
15        map_scale = 100
16
17        # Create a geo transformation that ties pixel to geo coordinates
18        self._transformation = sketchingpy.geo.GeoTransformation(
19            sketchingpy.geo.GeoPoint(center_longitude, center_latitude),  # Where to center geographically
20            sketchingpy.geo.PixelOffset(center_x, center_y),  # Where to center in terms of pixels
21            map_scale  # How much zoom
22        )

Hook method for setting up the test fixture before exercising it.

def test_point(self):
25    def test_point(self):
26        point = sketchingpy.geo.GeoPoint(-122.262938, 37.873139)
27        self.assertAlmostEqual(point.get_x(transform=self._transformation), 422.9960546672828)
28        self.assertAlmostEqual(point.get_y(transform=self._transformation), 93.16413302587421)
def test_polygon(self):
30    def test_polygon(self):
31        points = [
32            sketchingpy.geo.GeoPoint(-122, 38),
33            sketchingpy.geo.GeoPoint(-121, 38),
34            sketchingpy.geo.GeoPoint(-121, 37),
35            sketchingpy.geo.GeoPoint(-122, 37)
36        ]
37        geo_polygon = sketchingpy.geo.GeoPolygon(points)
38        shape = geo_polygon.to_shape(transform=self._transformation)
39        self.assertAlmostEqual(shape.get_start_x(), 715.6972973692973)
40        self.assertAlmostEqual(shape.get_start_y(), -85.89322991684298)
def test_parse_geojson(self):
42    def test_parse_geojson(self):
43        test_source = {
44            'features': [{
45                'geometry': {
46                    'type': 'Polygon',
47                    'coordinates': [[
48                        [-122, 38],
49                        [-121, 38],
50                        [-121, 37],
51                        [-122, 37],
52                    ]]
53                }
54            }]
55        }
56        polygons = sketchingpy.geo.parse_geojson(test_source)
57
58        self.assertEqual(len(polygons), 1)
59        polygon = polygons[0]
60
61        self.assertEqual(len(polygon), 4)
62        first_point = polygon[0]
63        self.assertAlmostEqual(first_point[0], -122)
64        self.assertAlmostEqual(first_point[1], 38)
Inherited Members
unittest.case.TestCase
TestCase
failureException
longMessage
maxDiff
addTypeEqualityFunc
addCleanup
addClassCleanup
tearDown
setUpClass
tearDownClass
countTestCases
defaultTestResult
shortDescription
id
subTest
run
doCleanups
doClassCleanups
debug
skipTest
fail
assertFalse
assertTrue
assertRaises
assertWarns
assertLogs
assertNoLogs
assertEqual
assertNotEqual
assertAlmostEqual
assertNotAlmostEqual
assertSequenceEqual
assertListEqual
assertTupleEqual
assertSetEqual
assertIn
assertNotIn
assertIs
assertIsNot
assertDictEqual
assertDictContainsSubset
assertCountEqual
assertMultiLineEqual
assertLess
assertLessEqual
assertGreater
assertGreaterEqual
assertIsNone
assertIsNotNone
assertIsInstance
assertNotIsInstance
assertRaisesRegex
assertWarnsRegex
assertRegex
assertNotRegex
failUnlessRaises
failIf
assertRaisesRegexp
assertRegexpMatches
assertNotRegexpMatches
failUnlessEqual
assertEquals
failIfEqual
assertNotEquals
failUnlessAlmostEqual
assertAlmostEquals
failIfAlmostEqual
assertNotAlmostEquals
failUnless
assert_