Skip to content

Commit d0e6cbb

Browse files
author
Martin Pauly
committed
Also move geo imports into test functions
1 parent c86893c commit d0e6cbb

File tree

9 files changed

+40
-13
lines changed

9 files changed

+40
-13
lines changed

test_haystack/elasticsearch2_tests/test_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import elasticsearch
1111
from django.apps import apps
1212
from django.conf import settings
13-
from django.contrib.gis.geos import Point
1413
from django.test import TestCase
1514
from django.test.utils import override_settings
1615

@@ -582,6 +581,7 @@ def test_search(self):
582581
settings.HAYSTACK_LIMIT_TO_REGISTERED_MODELS = old_limit_to_registered_models
583582

584583
def test_spatial_search_parameters(self):
584+
from django.contrib.gis.geos import Point
585585
p1 = Point(1.23, 4.56)
586586
kwargs = self.sb.build_search_kwargs(
587587
"*:*",

test_haystack/elasticsearch2_tests/test_query.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import datetime
55

66
import elasticsearch
7-
from django.contrib.gis.geos import Point
87
from django.contrib.gis.measure import D
98
from django.test import TestCase
109

@@ -140,7 +139,7 @@ def test_clean(self):
140139
self.assertEqual(self.sq.clean("hello AND world"), "hello and world")
141140
self.assertEqual(
142141
self.sq.clean(
143-
'hello AND OR NOT TO + - && || ! ( ) { } [ ] ^ " ~ * ? : \ / world'
142+
r'hello AND OR NOT TO + - && || ! ( ) { } [ ] ^ " ~ * ? : \ / world'
144143
),
145144
'hello and or not to \\+ \\- \\&& \\|| \\! \\( \\) \\{ \\} \\[ \\] \\^ \\" \\~ \\* \\? \\: \\\\ \\/ world',
146145
)
@@ -198,6 +197,8 @@ def test_build_query_with_dwithin_range(self):
198197
"""
199198
Test build_search_kwargs with dwithin range for Elasticsearch versions < 1.0.0
200199
"""
200+
from django.contrib.gis.geos import Point
201+
201202
search_kwargs = self.backend.build_search_kwargs(
202203
"where",
203204
dwithin={
@@ -228,6 +229,8 @@ def test_build_query_with_dwithin_range(self):
228229
"""
229230
Test build_search_kwargs with dwithin range for Elasticsearch versions >= 1.0.0
230231
"""
232+
from django.contrib.gis.geos import Point
233+
231234
search_kwargs = self.backend.build_search_kwargs(
232235
"where",
233236
dwithin={

test_haystack/elasticsearch5_tests/test_backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import elasticsearch
1111
from django.apps import apps
1212
from django.conf import settings
13-
from django.contrib.gis.geos import Point
1413
from django.test import TestCase
1514
from django.test.utils import override_settings
1615

@@ -582,6 +581,8 @@ def test_search(self):
582581
settings.HAYSTACK_LIMIT_TO_REGISTERED_MODELS = old_limit_to_registered_models
583582

584583
def test_spatial_search_parameters(self):
584+
from django.contrib.gis.geos import Point
585+
585586
p1 = Point(1.23, 4.56)
586587
kwargs = self.sb.build_search_kwargs(
587588
"*:*",

test_haystack/elasticsearch5_tests/test_query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
import datetime
55

6-
import elasticsearch
7-
from django.contrib.gis.geos import Point
86
from django.contrib.gis.measure import D
97
from django.test import TestCase
108

@@ -140,7 +138,7 @@ def test_clean(self):
140138
self.assertEqual(self.sq.clean("hello AND world"), "hello and world")
141139
self.assertEqual(
142140
self.sq.clean(
143-
'hello AND OR NOT TO + - && || ! ( ) { } [ ] ^ " ~ * ? : \ / world'
141+
r'hello AND OR NOT TO + - && || ! ( ) { } [ ] ^ " ~ * ? : \ / world'
144142
),
145143
'hello and or not to \\+ \\- \\&& \\|| \\! \\( \\) \\{ \\} \\[ \\] \\^ \\" \\~ \\* \\? \\: \\\\ \\/ world',
146144
)
@@ -184,6 +182,8 @@ def test_narrow_sq(self):
184182
self.assertEqual(sqs.query.narrow_queries.pop(), "foo:(moof)")
185183

186184
def test_build_query_with_dwithin_range(self):
185+
from django.contrib.gis.geos import Point
186+
187187
backend = connections["elasticsearch"].get_backend()
188188
search_kwargs = backend.build_search_kwargs(
189189
"where",

test_haystack/elasticsearch_tests/test_elasticsearch_backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import elasticsearch
1212
from django.apps import apps
1313
from django.conf import settings
14-
from django.contrib.gis.geos import Point
1514
from django.test import TestCase
1615
from django.test.utils import override_settings
1716

@@ -622,6 +621,8 @@ def test_search(self):
622621
settings.HAYSTACK_LIMIT_TO_REGISTERED_MODELS = old_limit_to_registered_models
623622

624623
def test_spatial_search_parameters(self):
624+
from django.contrib.gis.geos import Point
625+
625626
p1 = Point(1.23, 4.56)
626627
kwargs = self.sb.build_search_kwargs(
627628
"*:*",

test_haystack/elasticsearch_tests/test_elasticsearch_query.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import datetime
66

77
import elasticsearch
8-
from django.contrib.gis.geos import Point
98
from django.contrib.gis.measure import D
109
from django.test import TestCase
1110

@@ -153,7 +152,7 @@ def test_clean(self):
153152
self.assertEqual(self.sq.clean("hello AND world"), "hello and world")
154153
self.assertEqual(
155154
self.sq.clean(
156-
'hello AND OR NOT TO + - && || ! ( ) { } [ ] ^ " ~ * ? : \ / world'
155+
r'hello AND OR NOT TO + - && || ! ( ) { } [ ] ^ " ~ * ? : \ / world'
157156
),
158157
'hello and or not to \\+ \\- \\&& \\|| \\! \\( \\) \\{ \\} \\[ \\] \\^ \\" \\~ \\* \\? \\: \\\\ \\/ world',
159158
)
@@ -220,6 +219,8 @@ def test_build_query_with_dwithin_range(self):
220219
"""
221220
Test build_search_kwargs with dwithin range for Elasticsearch versions < 1.0.0
222221
"""
222+
from django.contrib.gis.geos import Point
223+
223224
search_kwargs = self.backend.build_search_kwargs(
224225
"where",
225226
dwithin={
@@ -250,6 +251,8 @@ def test_build_query_with_dwithin_range(self):
250251
"""
251252
Test build_search_kwargs with dwithin range for Elasticsearch versions >= 1.0.0
252253
"""
254+
from django.contrib.gis.geos import Point
255+
253256
search_kwargs = self.backend.build_search_kwargs(
254257
"where",
255258
dwithin={

test_haystack/solr_tests/test_solr_backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import pysolr
1111
from django.conf import settings
12-
from django.contrib.gis.geos import Point
1312
from django.test import TestCase
1413
from django.test.utils import override_settings
1514
from mock import patch
@@ -561,6 +560,8 @@ def test_spelling(self):
561560
)
562561

563562
def test_spatial_search_parameters(self):
563+
from django.contrib.gis.geos import Point
564+
564565
p1 = Point(1.23, 4.56)
565566
kwargs = self.sb.build_search_kwargs(
566567
"*:*",

test_haystack/spatial/test_spatial.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import absolute_import, division, print_function, unicode_literals
44

5-
from django.contrib.gis.geos import GEOSGeometry, Point
65
from django.contrib.gis.measure import D
76
from django.test import TestCase
87

@@ -22,6 +21,8 @@
2221

2322
class SpatialUtilitiesTestCase(TestCase):
2423
def test_ensure_geometry(self):
24+
from django.contrib.gis.geos import GEOSGeometry, Point
25+
2526
self.assertRaises(
2627
SpatialError, ensure_geometry, [38.97127105172941, -95.23592948913574]
2728
)
@@ -30,6 +31,8 @@ def test_ensure_geometry(self):
3031
ensure_geometry(Point(-95.23592948913574, 38.97127105172941))
3132

3233
def test_ensure_point(self):
34+
from django.contrib.gis.geos import GEOSGeometry, Point
35+
3336
self.assertRaises(
3437
SpatialError, ensure_point, [38.97127105172941, -95.23592948913574]
3538
)
@@ -41,6 +44,8 @@ def test_ensure_point(self):
4144
ensure_point(Point(-95.23592948913574, 38.97127105172941))
4245

4346
def test_ensure_wgs84(self):
47+
from django.contrib.gis.geos import GEOSGeometry, Point
48+
4449
self.assertRaises(
4550
SpatialError,
4651
ensure_wgs84,
@@ -70,6 +75,8 @@ def test_ensure_distance(self):
7075
ensure_distance(D(mi=5))
7176

7277
def test_generate_bounding_box(self):
78+
from django.contrib.gis.geos import Point
79+
7380
downtown_bottom_left = Point(-95.23947, 38.9637903)
7481
downtown_top_right = Point(-95.23362278938293, 38.973081081164715)
7582
((min_lat, min_lng), (max_lat, max_lng)) = generate_bounding_box(
@@ -81,6 +88,8 @@ def test_generate_bounding_box(self):
8188
self.assertEqual(max_lng, -95.23362278938293)
8289

8390
def test_generate_bounding_box_crossing_line_date(self):
91+
from django.contrib.gis.geos import Point
92+
8493
downtown_bottom_left = Point(95.23947, 38.9637903)
8594
downtown_top_right = Point(-95.23362278938293, 38.973081081164715)
8695
((south, west), (north, east)) = generate_bounding_box(
@@ -97,6 +106,8 @@ class SpatialSolrTestCase(TestCase):
97106
using = "solr"
98107

99108
def setUp(self):
109+
from django.contrib.gis.geos import Point
110+
100111
super(SpatialSolrTestCase, self).setUp()
101112
self.ui = connections[self.using].get_unified_index()
102113
self.checkindex = self.ui.get_index(Checkin)

test_haystack/test_managers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import datetime
66

7-
from django.contrib.gis.geos import Point
87
from django.contrib.gis.measure import D
98
from django.test import TestCase
109
from test_haystack.core.models import MockModel
@@ -86,6 +85,8 @@ def test_order_by(self):
8685
self.assertTrue("foo" in sqs.query.order_by)
8786

8887
def test_order_by_distance(self):
88+
from django.contrib.gis.geos import Point
89+
8990
p = Point(1.23, 4.56)
9091
sqs = self.search_index.objects.distance("location", p).order_by("distance")
9192
self.assertTrue(isinstance(sqs, SearchQuerySet))
@@ -115,6 +116,8 @@ def test_facets(self):
115116
self.assertEqual(len(sqs.query.facets), 1)
116117

117118
def test_within(self):
119+
from django.contrib.gis.geos import Point
120+
118121
# This is a meaningless query but we're just confirming that the manager updates the parameters here:
119122
p1 = Point(-90, -90)
120123
p2 = Point(90, 90)
@@ -129,6 +132,8 @@ def test_within(self):
129132
)
130133

131134
def test_dwithin(self):
135+
from django.contrib.gis.geos import Point
136+
132137
p = Point(0, 0)
133138
distance = D(mi=500)
134139
sqs = self.search_index.objects.dwithin("location", p, distance)
@@ -142,6 +147,8 @@ def test_dwithin(self):
142147
)
143148

144149
def test_distance(self):
150+
from django.contrib.gis.geos import Point
151+
145152
p = Point(0, 0)
146153
sqs = self.search_index.objects.distance("location", p)
147154
self.assertTrue(isinstance(sqs, SearchQuerySet))

0 commit comments

Comments
 (0)