kopia lustrzana https://github.com/wagtail/wagtail
Fix deep_update for Python 3.10
This is only used by the Elasticsearch backend, so we were missing test runs for it over all Python versions.stable/2.16.x
rodzic
6262090f89
commit
ae5d00f7a1
|
@ -10,6 +10,7 @@ from wagtail.core.utils import (
|
|||
accepts_kwarg, camelcase_to_underscore, cautious_slugify, find_available_slug,
|
||||
get_content_languages, get_dummy_request, get_supported_content_language_variant, multigetattr,
|
||||
safe_snake_case, string_to_ascii)
|
||||
from wagtail.utils.utils import deep_update
|
||||
|
||||
|
||||
class TestCamelCaseToUnderscore(TestCase):
|
||||
|
@ -374,3 +375,38 @@ class TestGetDummyRequest(TestCase):
|
|||
|
||||
request = get_dummy_request(site=site)
|
||||
self.assertEqual(request.get_host(), 'other.example.com:8888')
|
||||
|
||||
|
||||
class TestDeepUpdate(TestCase):
|
||||
def test_deep_update(self):
|
||||
val = {
|
||||
"captain": "picard",
|
||||
"beverage": {
|
||||
"type": "coffee",
|
||||
"temperature": "hot",
|
||||
},
|
||||
}
|
||||
|
||||
deep_update(
|
||||
val,
|
||||
{
|
||||
"beverage": {
|
||||
"type": "tea",
|
||||
"variant": "earl grey",
|
||||
},
|
||||
"starship": "enterprise",
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
val,
|
||||
{
|
||||
"captain": "picard",
|
||||
"beverage": {
|
||||
"type": "tea",
|
||||
"variant": "earl grey",
|
||||
"temperature": "hot",
|
||||
},
|
||||
"starship": "enterprise",
|
||||
},
|
||||
)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import collections
|
||||
from collections.abc import Mapping
|
||||
|
||||
|
||||
def deep_update(source, overrides):
|
||||
|
@ -7,7 +7,7 @@ def deep_update(source, overrides):
|
|||
Modify ``source`` in place.
|
||||
"""
|
||||
for key, value in overrides.items():
|
||||
if isinstance(value, collections.Mapping) and value:
|
||||
if isinstance(value, Mapping) and value:
|
||||
returned = deep_update(source.get(key, {}), value)
|
||||
source[key] = returned
|
||||
else:
|
||||
|
|
Ładowanie…
Reference in New Issue