File: test_driver.py

package info (click to toggle)
python-django 3%3A3.2.19-1%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 56,696 kB
  • sloc: python: 264,418; javascript: 18,362; xml: 193; makefile: 178; sh: 43
file content (75 lines) | stat: -rw-r--r-- 2,241 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
import unittest
from unittest import mock

from django.contrib.gis.gdal import Driver, GDALException

valid_drivers = (
    # vector
    'ESRI Shapefile', 'MapInfo File', 'TIGER', 'S57', 'DGN', 'Memory', 'CSV',
    'GML', 'KML',
    # raster
    'GTiff', 'JPEG', 'MEM', 'PNG',
)

invalid_drivers = ('Foo baz', 'clucka', 'ESRI Shp', 'ESRI rast')

aliases = {
    'eSrI': 'ESRI Shapefile',
    'TigER/linE': 'TIGER',
    'SHAPE': 'ESRI Shapefile',
    'sHp': 'ESRI Shapefile',
    'tiFf': 'GTiff',
    'tIf': 'GTiff',
    'jPEg': 'JPEG',
    'jpG': 'JPEG',
}


class DriverTest(unittest.TestCase):

    def test01_valid_driver(self):
        "Testing valid GDAL/OGR Data Source Drivers."
        for d in valid_drivers:
            dr = Driver(d)
            self.assertEqual(d, str(dr))

    def test02_invalid_driver(self):
        "Testing invalid GDAL/OGR Data Source Drivers."
        for i in invalid_drivers:
            with self.assertRaises(GDALException):
                Driver(i)

    def test03_aliases(self):
        "Testing driver aliases."
        for alias, full_name in aliases.items():
            dr = Driver(alias)
            self.assertEqual(full_name, str(dr))

    @mock.patch('django.contrib.gis.gdal.driver.vcapi.get_driver_count')
    @mock.patch('django.contrib.gis.gdal.driver.rcapi.get_driver_count')
    @mock.patch('django.contrib.gis.gdal.driver.vcapi.register_all')
    @mock.patch('django.contrib.gis.gdal.driver.rcapi.register_all')
    def test_registered(self, rreg, vreg, rcount, vcount):
        """
        Prototypes are registered only if their respective driver counts are
        zero.
        """
        def check(rcount_val, vcount_val):
            vreg.reset_mock()
            rreg.reset_mock()
            rcount.return_value = rcount_val
            vcount.return_value = vcount_val
            Driver.ensure_registered()
            if rcount_val:
                self.assertFalse(rreg.called)
            else:
                rreg.assert_called_once_with()
            if vcount_val:
                self.assertFalse(vreg.called)
            else:
                vreg.assert_called_once_with()

        check(0, 0)
        check(120, 0)
        check(0, 120)
        check(120, 120)