Prepare unit tests for Python 3.12 (#16099)

pull/16194/head
V02460 2023-08-25 21:05:10 +02:00 committed by GitHub
parent ed6de4b2d4
commit 84f441f88f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 94 additions and 84 deletions

View File

@ -47,10 +47,9 @@ if not IS_PR:
"database": "sqlite", "database": "sqlite",
"extras": "all", "extras": "all",
} }
for version in ("3.9", "3.10", "3.11") for version in ("3.9", "3.10", "3.11", "3.12.0-rc.1")
) )
trial_postgres_tests = [ trial_postgres_tests = [
{ {
"python-version": "3.8", "python-version": "3.8",

1
changelog.d/16099.misc Normal file
View File

@ -0,0 +1 @@
Prepare unit tests for Python 3.12.

22
poetry.lock generated
View File

@ -1,4 +1,4 @@
# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. # This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand.
[[package]] [[package]]
name = "alabaster" name = "alabaster"
@ -544,13 +544,13 @@ files = [
[[package]] [[package]]
name = "elementpath" name = "elementpath"
version = "4.1.0" version = "4.1.5"
description = "XPath 1.0/2.0/3.0/3.1 parsers and selectors for ElementTree and lxml" description = "XPath 1.0/2.0/3.0/3.1 parsers and selectors for ElementTree and lxml"
optional = true optional = true
python-versions = ">=3.7" python-versions = ">=3.7"
files = [ files = [
{file = "elementpath-4.1.0-py3-none-any.whl", hash = "sha256:2b1b524223d70fd6dd63a36b9bc32e4919c96a272c2d1454094c4d85086bc6f8"}, {file = "elementpath-4.1.5-py3-none-any.whl", hash = "sha256:2ac1a2fb31eb22bbbf817f8cf6752f844513216263f0e3892c8e79782fe4bb55"},
{file = "elementpath-4.1.0.tar.gz", hash = "sha256:dbd7eba3cf0b3b4934f627ba24851a3e0798ef2bc9104555a4cd831f2e6e8e14"}, {file = "elementpath-4.1.5.tar.gz", hash = "sha256:c2d6dc524b29ef751ecfc416b0627668119d8812441c555d7471da41d4bacb8d"},
] ]
[package.extras] [package.extras]
@ -3207,22 +3207,22 @@ files = [
[[package]] [[package]]
name = "xmlschema" name = "xmlschema"
version = "2.2.2" version = "2.4.0"
description = "An XML Schema validator and decoder" description = "An XML Schema validator and decoder"
optional = true optional = true
python-versions = ">=3.7" python-versions = ">=3.7"
files = [ files = [
{file = "xmlschema-2.2.2-py3-none-any.whl", hash = "sha256:557f3632b54b6ff10576736bba62e43db84eb60f6465a83818576cd9ffcc1799"}, {file = "xmlschema-2.4.0-py3-none-any.whl", hash = "sha256:dc87be0caaa61f42649899189aab2fd8e0d567f2cf548433ba7b79278d231a4a"},
{file = "xmlschema-2.2.2.tar.gz", hash = "sha256:0caa96668807b4b51c42a0fe2b6610752bc59f069615df3e34dcfffb962973fd"}, {file = "xmlschema-2.4.0.tar.gz", hash = "sha256:d74cd0c10866ac609e1ef94a5a69b018ad16e39077bc6393408b40c6babee793"},
] ]
[package.dependencies] [package.dependencies]
elementpath = ">=4.0.0,<5.0.0" elementpath = ">=4.1.5,<5.0.0"
[package.extras] [package.extras]
codegen = ["elementpath (>=4.0.0,<5.0.0)", "jinja2"] codegen = ["elementpath (>=4.1.5,<5.0.0)", "jinja2"]
dev = ["Sphinx", "coverage", "elementpath (>=4.0.0,<5.0.0)", "flake8", "jinja2", "lxml", "lxml-stubs", "memory-profiler", "mypy", "sphinx-rtd-theme", "tox"] dev = ["Sphinx", "coverage", "elementpath (>=4.1.5,<5.0.0)", "flake8", "jinja2", "lxml", "lxml-stubs", "memory-profiler", "mypy", "sphinx-rtd-theme", "tox"]
docs = ["Sphinx", "elementpath (>=4.0.0,<5.0.0)", "jinja2", "sphinx-rtd-theme"] docs = ["Sphinx", "elementpath (>=4.1.5,<5.0.0)", "jinja2", "sphinx-rtd-theme"]
[[package]] [[package]]
name = "zipp" name = "zipp"

View File

@ -44,6 +44,7 @@ _IGNORED_LOG_RECORD_ATTRIBUTES = {
"processName", "processName",
"relativeCreated", "relativeCreated",
"stack_info", "stack_info",
"taskName",
"thread", "thread",
"threadName", "threadName",
} }

View File

@ -122,50 +122,50 @@ class DeviceTestCase(unittest.HomeserverTestCase):
self.assertEqual(3, len(res)) self.assertEqual(3, len(res))
device_map = {d["device_id"]: d for d in res} device_map = {d["device_id"]: d for d in res}
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"user_id": user1, "user_id": user1,
"device_id": "xyz", "device_id": "xyz",
"display_name": "display 0", "display_name": "display 0",
"last_seen_ip": None, "last_seen_ip": None,
"last_seen_ts": None, "last_seen_ts": None,
}, }.items(),
device_map["xyz"], device_map["xyz"].items(),
) )
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"user_id": user1, "user_id": user1,
"device_id": "fco", "device_id": "fco",
"display_name": "display 1", "display_name": "display 1",
"last_seen_ip": "ip1", "last_seen_ip": "ip1",
"last_seen_ts": 1000000, "last_seen_ts": 1000000,
}, }.items(),
device_map["fco"], device_map["fco"].items(),
) )
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"user_id": user1, "user_id": user1,
"device_id": "abc", "device_id": "abc",
"display_name": "display 2", "display_name": "display 2",
"last_seen_ip": "ip3", "last_seen_ip": "ip3",
"last_seen_ts": 3000000, "last_seen_ts": 3000000,
}, }.items(),
device_map["abc"], device_map["abc"].items(),
) )
def test_get_device(self) -> None: def test_get_device(self) -> None:
self._record_users() self._record_users()
res = self.get_success(self.handler.get_device(user1, "abc")) res = self.get_success(self.handler.get_device(user1, "abc"))
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"user_id": user1, "user_id": user1,
"device_id": "abc", "device_id": "abc",
"display_name": "display 2", "display_name": "display 2",
"last_seen_ip": "ip3", "last_seen_ip": "ip3",
"last_seen_ts": 3000000, "last_seen_ts": 3000000,
}, }.items(),
res, res.items(),
) )
def test_delete_device(self) -> None: def test_delete_device(self) -> None:

View File

@ -581,8 +581,9 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
body, body,
) )
self.assertEqual(channel.code, 403, channel.result) self.assertEqual(channel.code, 403, channel.result)
self.assertDictContainsSubset( self.assertLessEqual(
{"errcode": Codes.LIMIT_EXCEEDED, "extra": "value"}, channel.json_body {"errcode": Codes.LIMIT_EXCEEDED, "extra": "value"}.items(),
channel.json_body.items(),
) )

View File

@ -75,7 +75,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
self.assertEqual(channel.code, 200, msg=channel.result) self.assertEqual(channel.code, 200, msg=channel.result)
det_data = {"user_id": user_id, "home_server": self.hs.hostname} det_data = {"user_id": user_id, "home_server": self.hs.hostname}
self.assertDictContainsSubset(det_data, channel.json_body) self.assertLessEqual(det_data.items(), channel.json_body.items())
def test_POST_appservice_registration_no_type(self) -> None: def test_POST_appservice_registration_no_type(self) -> None:
as_token = "i_am_an_app_service" as_token = "i_am_an_app_service"
@ -136,7 +136,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
"device_id": device_id, "device_id": device_id,
} }
self.assertEqual(channel.code, 200, msg=channel.result) self.assertEqual(channel.code, 200, msg=channel.result)
self.assertDictContainsSubset(det_data, channel.json_body) self.assertLessEqual(det_data.items(), channel.json_body.items())
@override_config({"enable_registration": False}) @override_config({"enable_registration": False})
def test_POST_disabled_registration(self) -> None: def test_POST_disabled_registration(self) -> None:
@ -157,7 +157,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
det_data = {"home_server": self.hs.hostname, "device_id": "guest_device"} det_data = {"home_server": self.hs.hostname, "device_id": "guest_device"}
self.assertEqual(channel.code, 200, msg=channel.result) self.assertEqual(channel.code, 200, msg=channel.result)
self.assertDictContainsSubset(det_data, channel.json_body) self.assertLessEqual(det_data.items(), channel.json_body.items())
def test_POST_disabled_guest_registration(self) -> None: def test_POST_disabled_guest_registration(self) -> None:
self.hs.config.registration.allow_guest_access = False self.hs.config.registration.allow_guest_access = False
@ -267,7 +267,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
"device_id": device_id, "device_id": device_id,
} }
self.assertEqual(channel.code, 200, msg=channel.result) self.assertEqual(channel.code, 200, msg=channel.result)
self.assertDictContainsSubset(det_data, channel.json_body) self.assertLessEqual(det_data.items(), channel.json_body.items())
# Check the `completed` counter has been incremented and pending is 0 # Check the `completed` counter has been incremented and pending is 0
res = self.get_success( res = self.get_success(

View File

@ -570,7 +570,7 @@ class RelationsTestCase(BaseRelationsTestCase):
) )
self.assertEqual(200, channel.code, channel.json_body) self.assertEqual(200, channel.code, channel.json_body)
event_result = channel.json_body event_result = channel.json_body
self.assertDictContainsSubset(original_body, event_result["content"]) self.assertLessEqual(original_body.items(), event_result["content"].items())
# also check /context, which returns the *edited* event # also check /context, which returns the *edited* event
channel = self.make_request( channel = self.make_request(
@ -587,14 +587,14 @@ class RelationsTestCase(BaseRelationsTestCase):
(context_result, "/context"), (context_result, "/context"),
): ):
# The reference metadata should still be intact. # The reference metadata should still be intact.
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"m.relates_to": { "m.relates_to": {
"event_id": self.parent_id, "event_id": self.parent_id,
"rel_type": "m.reference", "rel_type": "m.reference",
} }
}, }.items(),
result_event_dict["content"], result_event_dict["content"].items(),
desc, desc,
) )
@ -1372,9 +1372,11 @@ class BundledAggregationsTestCase(BaseRelationsTestCase):
latest_event_in_thread = thread_summary["latest_event"] latest_event_in_thread = thread_summary["latest_event"]
# The latest event in the thread should have the edit appear under the # The latest event in the thread should have the edit appear under the
# bundled aggregations. # bundled aggregations.
self.assertDictContainsSubset( self.assertLessEqual(
{"event_id": edit_event_id, "sender": "@alice:test"}, {"event_id": edit_event_id, "sender": "@alice:test"}.items(),
latest_event_in_thread["unsigned"]["m.relations"][RelationTypes.REPLACE], latest_event_in_thread["unsigned"]["m.relations"][
RelationTypes.REPLACE
].items(),
) )
def test_aggregation_get_event_for_annotation(self) -> None: def test_aggregation_get_event_for_annotation(self) -> None:
@ -1637,9 +1639,9 @@ class RelationRedactionTestCase(BaseRelationsTestCase):
################################################## ##################################################
self.assertEqual(self._get_related_events(), list(reversed(thread_replies))) self.assertEqual(self._get_related_events(), list(reversed(thread_replies)))
relations = self._get_bundled_aggregations() relations = self._get_bundled_aggregations()
self.assertDictContainsSubset( self.assertLessEqual(
{"count": 3, "current_user_participated": True}, {"count": 3, "current_user_participated": True}.items(),
relations[RelationTypes.THREAD], relations[RelationTypes.THREAD].items(),
) )
# The latest event is the last sent event. # The latest event is the last sent event.
self.assertEqual( self.assertEqual(
@ -1658,9 +1660,9 @@ class RelationRedactionTestCase(BaseRelationsTestCase):
# The thread should still exist, but the latest event should be updated. # The thread should still exist, but the latest event should be updated.
self.assertEqual(self._get_related_events(), list(reversed(thread_replies))) self.assertEqual(self._get_related_events(), list(reversed(thread_replies)))
relations = self._get_bundled_aggregations() relations = self._get_bundled_aggregations()
self.assertDictContainsSubset( self.assertLessEqual(
{"count": 2, "current_user_participated": True}, {"count": 2, "current_user_participated": True}.items(),
relations[RelationTypes.THREAD], relations[RelationTypes.THREAD].items(),
) )
# And the latest event is the last unredacted event. # And the latest event is the last unredacted event.
self.assertEqual( self.assertEqual(
@ -1677,9 +1679,9 @@ class RelationRedactionTestCase(BaseRelationsTestCase):
# Nothing should have changed (except the thread count). # Nothing should have changed (except the thread count).
self.assertEqual(self._get_related_events(), thread_replies) self.assertEqual(self._get_related_events(), thread_replies)
relations = self._get_bundled_aggregations() relations = self._get_bundled_aggregations()
self.assertDictContainsSubset( self.assertLessEqual(
{"count": 1, "current_user_participated": True}, {"count": 1, "current_user_participated": True}.items(),
relations[RelationTypes.THREAD], relations[RelationTypes.THREAD].items(),
) )
# And the latest event is the last unredacted event. # And the latest event is the last unredacted event.
self.assertEqual( self.assertEqual(
@ -1774,12 +1776,12 @@ class RelationRedactionTestCase(BaseRelationsTestCase):
event_ids = self._get_related_events() event_ids = self._get_related_events()
relations = self._get_bundled_aggregations() relations = self._get_bundled_aggregations()
self.assertEqual(len(event_ids), 1) self.assertEqual(len(event_ids), 1)
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"count": 1, "count": 1,
"current_user_participated": True, "current_user_participated": True,
}, }.items(),
relations[RelationTypes.THREAD], relations[RelationTypes.THREAD].items(),
) )
self.assertEqual( self.assertEqual(
relations[RelationTypes.THREAD]["latest_event"]["event_id"], relations[RelationTypes.THREAD]["latest_event"]["event_id"],

View File

@ -65,15 +65,15 @@ class ClientIpStoreTestCase(unittest.HomeserverTestCase):
) )
r = result[(user_id, device_id)] r = result[(user_id, device_id)]
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"user_id": user_id, "user_id": user_id,
"device_id": device_id, "device_id": device_id,
"ip": "ip", "ip": "ip",
"user_agent": "user_agent", "user_agent": "user_agent",
"last_seen": 12345678000, "last_seen": 12345678000,
}, }.items(),
r, r.items(),
) )
def test_insert_new_client_ip_none_device_id(self) -> None: def test_insert_new_client_ip_none_device_id(self) -> None:
@ -526,15 +526,15 @@ class ClientIpStoreTestCase(unittest.HomeserverTestCase):
) )
r = result[(user_id, device_id)] r = result[(user_id, device_id)]
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"user_id": user_id, "user_id": user_id,
"device_id": device_id, "device_id": device_id,
"ip": None, "ip": None,
"user_agent": None, "user_agent": None,
"last_seen": None, "last_seen": None,
}, }.items(),
r, r.items(),
) )
# Register the background update to run again. # Register the background update to run again.
@ -561,15 +561,15 @@ class ClientIpStoreTestCase(unittest.HomeserverTestCase):
) )
r = result[(user_id, device_id)] r = result[(user_id, device_id)]
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"user_id": user_id, "user_id": user_id,
"device_id": device_id, "device_id": device_id,
"ip": "ip", "ip": "ip",
"user_agent": "user_agent", "user_agent": "user_agent",
"last_seen": 0, "last_seen": 0,
}, }.items(),
r, r.items(),
) )
def test_old_user_ips_pruned(self) -> None: def test_old_user_ips_pruned(self) -> None:
@ -640,15 +640,15 @@ class ClientIpStoreTestCase(unittest.HomeserverTestCase):
) )
r = result2[(user_id, device_id)] r = result2[(user_id, device_id)]
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"user_id": user_id, "user_id": user_id,
"device_id": device_id, "device_id": device_id,
"ip": "ip", "ip": "ip",
"user_agent": "user_agent", "user_agent": "user_agent",
"last_seen": 0, "last_seen": 0,
}, }.items(),
r, r.items(),
) )
def test_invalid_user_agents_are_ignored(self) -> None: def test_invalid_user_agents_are_ignored(self) -> None:
@ -777,13 +777,13 @@ class ClientIpAuthTestCase(unittest.HomeserverTestCase):
self.store.get_last_client_ip_by_device(self.user_id, device_id) self.store.get_last_client_ip_by_device(self.user_id, device_id)
) )
r = result[(self.user_id, device_id)] r = result[(self.user_id, device_id)]
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"user_id": self.user_id, "user_id": self.user_id,
"device_id": device_id, "device_id": device_id,
"ip": expected_ip, "ip": expected_ip,
"user_agent": "Mozzila pizza", "user_agent": "Mozzila pizza",
"last_seen": 123456100, "last_seen": 123456100,
}, }.items(),
r, r.items(),
) )

View File

@ -58,13 +58,13 @@ class DeviceStoreTestCase(HomeserverTestCase):
res = self.get_success(self.store.get_device("user_id", "device_id")) res = self.get_success(self.store.get_device("user_id", "device_id"))
assert res is not None assert res is not None
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"user_id": "user_id", "user_id": "user_id",
"device_id": "device_id", "device_id": "device_id",
"display_name": "display_name", "display_name": "display_name",
}, }.items(),
res, res.items(),
) )
def test_get_devices_by_user(self) -> None: def test_get_devices_by_user(self) -> None:
@ -80,21 +80,21 @@ class DeviceStoreTestCase(HomeserverTestCase):
res = self.get_success(self.store.get_devices_by_user("user_id")) res = self.get_success(self.store.get_devices_by_user("user_id"))
self.assertEqual(2, len(res.keys())) self.assertEqual(2, len(res.keys()))
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"user_id": "user_id", "user_id": "user_id",
"device_id": "device1", "device_id": "device1",
"display_name": "display_name 1", "display_name": "display_name 1",
}, }.items(),
res["device1"], res["device1"].items(),
) )
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"user_id": "user_id", "user_id": "user_id",
"device_id": "device2", "device_id": "device2",
"display_name": "display_name 2", "display_name": "display_name 2",
}, }.items(),
res["device2"], res["device2"].items(),
) )
def test_count_devices_by_users(self) -> None: def test_count_devices_by_users(self) -> None:

View File

@ -38,7 +38,7 @@ class EndToEndKeyStoreTestCase(HomeserverTestCase):
self.assertIn("user", res) self.assertIn("user", res)
self.assertIn("device", res["user"]) self.assertIn("device", res["user"])
dev = res["user"]["device"] dev = res["user"]["device"]
self.assertDictContainsSubset(json, dev) self.assertLessEqual(json.items(), dev.items())
def test_reupload_key(self) -> None: def test_reupload_key(self) -> None:
now = 1470174257070 now = 1470174257070
@ -71,8 +71,12 @@ class EndToEndKeyStoreTestCase(HomeserverTestCase):
self.assertIn("user", res) self.assertIn("user", res)
self.assertIn("device", res["user"]) self.assertIn("device", res["user"])
dev = res["user"]["device"] dev = res["user"]["device"]
self.assertDictContainsSubset( self.assertLessEqual(
{"key": "value", "unsigned": {"device_display_name": "display_name"}}, dev {
"key": "value",
"unsigned": {"device_display_name": "display_name"},
}.items(),
dev.items(),
) )
def test_multiple_devices(self) -> None: def test_multiple_devices(self) -> None:

View File

@ -44,13 +44,13 @@ class RoomStoreTestCase(HomeserverTestCase):
def test_get_room(self) -> None: def test_get_room(self) -> None:
res = self.get_success(self.store.get_room(self.room.to_string())) res = self.get_success(self.store.get_room(self.room.to_string()))
assert res is not None assert res is not None
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"room_id": self.room.to_string(), "room_id": self.room.to_string(),
"creator": self.u_creator.to_string(), "creator": self.u_creator.to_string(),
"is_public": True, "is_public": True,
}, }.items(),
res, res.items(),
) )
def test_get_room_unknown_room(self) -> None: def test_get_room_unknown_room(self) -> None:
@ -59,13 +59,13 @@ class RoomStoreTestCase(HomeserverTestCase):
def test_get_room_with_stats(self) -> None: def test_get_room_with_stats(self) -> None:
res = self.get_success(self.store.get_room_with_stats(self.room.to_string())) res = self.get_success(self.store.get_room_with_stats(self.room.to_string()))
assert res is not None assert res is not None
self.assertDictContainsSubset( self.assertLessEqual(
{ {
"room_id": self.room.to_string(), "room_id": self.room.to_string(),
"creator": self.u_creator.to_string(), "creator": self.u_creator.to_string(),
"public": True, "public": True,
}, }.items(),
res, res.items(),
) )
def test_get_room_with_stats_unknown_room(self) -> None: def test_get_room_with_stats_unknown_room(self) -> None:

View File

@ -85,7 +85,9 @@ class TermsTestCase(unittest.HomeserverTestCase):
} }
} }
self.assertIsInstance(channel.json_body["params"], dict) self.assertIsInstance(channel.json_body["params"], dict)
self.assertDictContainsSubset(channel.json_body["params"], expected_params) self.assertLessEqual(
channel.json_body["params"].items(), expected_params.items()
)
# We have to complete the dummy auth stage before completing the terms stage # We have to complete the dummy auth stage before completing the terms stage
request_data = { request_data = {