~canonical-django/canonical-django/project-template

« back to all changes in this revision

Viewing changes to trunk/python-packages/django/contrib/gis/tests/test_gdal_envelope.py

  • Committer: Matthew Nuzum
  • Date: 2008-11-13 05:46:03 UTC
  • Revision ID: matthew.nuzum@canonical.com-20081113054603-v0kvr6z6xyexvqt3
adding to version control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import unittest
 
2
from django.contrib.gis.gdal import Envelope, OGRException
 
3
 
 
4
class EnvelopeTest(unittest.TestCase):
 
5
 
 
6
    def test01_init(self):
 
7
        "Testing Envelope initilization."
 
8
        e1 = Envelope((0, 0, 5, 5))
 
9
        e2 = Envelope(0, 0, 5, 5)
 
10
        e3 = Envelope(0, '0', '5', 5) # Thanks to ww for this
 
11
        e4 = Envelope(e1._envelope)
 
12
        self.assertRaises(OGRException, Envelope, (5, 5, 0, 0))
 
13
        self.assertRaises(OGRException, Envelope, 5, 5, 0, 0)
 
14
        self.assertRaises(OGRException, Envelope, (0, 0, 5, 5, 3))
 
15
        self.assertRaises(OGRException, Envelope, ())
 
16
        self.assertRaises(ValueError, Envelope, 0, 'a', 5, 5)
 
17
        self.assertRaises(TypeError, Envelope, u'foo')
 
18
 
 
19
    def test02_properties(self):
 
20
        "Testing Envelope properties."
 
21
        e = Envelope(0, 0, 2, 3)
 
22
        self.assertEqual(0, e.min_x)
 
23
        self.assertEqual(0, e.min_y)
 
24
        self.assertEqual(2, e.max_x)
 
25
        self.assertEqual(3, e.max_y)
 
26
        self.assertEqual((0, 0), e.ll)
 
27
        self.assertEqual((2, 3), e.ur)
 
28
        self.assertEqual((0, 0, 2, 3), e.tuple)
 
29
        self.assertEqual('POLYGON((0.0 0.0,0.0 3.0,2.0 3.0,2.0 0.0,0.0 0.0))', e.wkt)
 
30
        self.assertEqual('(0.0, 0.0, 2.0, 3.0)', str(e))
 
31
 
 
32
    def test03_equivalence(self):
 
33
        "Testing Envelope equivalence."
 
34
        e1 = Envelope(0.523, 0.217, 253.23, 523.69)
 
35
        e2 = Envelope((0.523, 0.217, 253.23, 523.69))
 
36
        self.assertEqual(e1, e2)
 
37
        self.assertEqual((0.523, 0.217, 253.23, 523.69), e1)
 
38
 
 
39
def suite():
 
40
    s = unittest.TestSuite()
 
41
    s.addTest(unittest.makeSuite(EnvelopeTest))
 
42
    return s
 
43
 
 
44
def run(verbosity=2):
 
45
    unittest.TextTestRunner(verbosity=verbosity).run(suite())