Skip to content

Commit

Permalink
Fixed #17212 -- Made GEOS version regular expression more robust. Tha…
Browse files Browse the repository at this point in the history
…nks, strk.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17682 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jbronn committed Mar 12, 2012
1 parent bf1112d commit 771fce4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions django/contrib/gis/geos/libgeos.py
Expand Up @@ -101,8 +101,8 @@ def get_pointer_arr(n):
geos_version.restype = c_char_p

# Regular expression should be able to parse version strings such as
# '3.0.0rc4-CAPI-1.3.3', or '3.0.0-CAPI-1.4.1'
version_regex = re.compile(r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))(rc(?P<release_candidate>\d+))?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)$')
# '3.0.0rc4-CAPI-1.3.3', '3.0.0-CAPI-1.4.1' or '3.4.0dev-CAPI-1.8.0'
version_regex = re.compile(r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)$')
def geos_version_info():
"""
Returns a dictionary containing the various version metadata parsed from
Expand Down
14 changes: 13 additions & 1 deletion django/contrib/gis/geos/tests/test_geos.py
Expand Up @@ -901,7 +901,7 @@ def test23_transform_nosrid(self):
# Keeping line-noise down by only printing the relevant
# warnings once.
warnings.simplefilter('once', UserWarning)
warnings.simplefilter('once', FutureWarning)
warnings.simplefilter('once', FutureWarning)

g = GEOSGeometry('POINT (-104.609 38.255)', srid=None)
g.transform(2774)
Expand Down Expand Up @@ -1049,6 +1049,18 @@ def test27_valid_reason(self):

print "\nEND - expecting GEOS_NOTICE; safe to ignore.\n"

def test28_geos_version(self):
"Testing the GEOS version regular expression."
from django.contrib.gis.geos.libgeos import version_regex
versions = [ ('3.0.0rc4-CAPI-1.3.3', '3.0.0'),
('3.0.0-CAPI-1.4.1', '3.0.0'),
('3.4.0dev-CAPI-1.8.0', '3.4.0') ]
for v, expected in versions:
m = version_regex.match(v)
self.assertTrue(m)
self.assertEqual(m.group('version'), expected)


def suite():
s = unittest.TestSuite()
s.addTest(unittest.makeSuite(GEOSTest))
Expand Down

0 comments on commit 771fce4

Please sign in to comment.