mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[5.1.x] Fixed #35666 -- Documented stacklevel usage and testing, and adjusted test suite accordingly.
Over the years we've had multiple instances of hit and misses when
emitting warnings: either setting the wrong stacklevel or not setting
it at all.
This work adds assertions for the existing warnings that were declaring
the correct stacklevel, but were lacking tests for it.
Backport of 57307bbc7d from main.
This commit is contained in:
@@ -972,6 +972,7 @@ class DeprecationTests(SimpleTestCase):
|
||||
def test_coord_setter_deprecation(self):
|
||||
geom = OGRGeometry("POINT (1 2)")
|
||||
msg = "coord_dim setter is deprecated. Use set_3d() instead."
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
|
||||
geom.coord_dim = 3
|
||||
self.assertEqual(geom.coord_dim, 3)
|
||||
self.assertEqual(ctx.filename, __file__)
|
||||
|
||||
@@ -207,16 +207,18 @@ class GeoLite2Test(SimpleTestCase):
|
||||
def test_coords_deprecation_warning(self):
|
||||
g = GeoIP2()
|
||||
msg = "GeoIP2.coords() is deprecated. Use GeoIP2.lon_lat() instead."
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
|
||||
e1, e2 = g.coords(self.ipv4_str)
|
||||
self.assertIsInstance(e1, float)
|
||||
self.assertIsInstance(e2, float)
|
||||
self.assertEqual(ctx.filename, __file__)
|
||||
|
||||
def test_open_deprecation_warning(self):
|
||||
msg = "GeoIP2.open() is deprecated. Use GeoIP2() instead."
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
|
||||
g = GeoIP2.open(settings.GEOIP_PATH, GeoIP2.MODE_AUTO)
|
||||
self.assertTrue(g._reader)
|
||||
self.assertEqual(ctx.filename, __file__)
|
||||
|
||||
|
||||
@skipUnless(HAS_GEOIP2, "GeoIP2 is required.")
|
||||
|
||||
Reference in New Issue
Block a user