massive refactoring to switch from camelCase to snake_case:

historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.

However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.

To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.

This is a massive change, and may result in some bugs.
This commit is contained in:
Goffi 2023-04-08 13:54:42 +02:00
commit 6a6f15707a

View file

@ -27,22 +27,22 @@ class TestPubsubCache:
@ed
async def test_cache_is_used_transparently(self, host, client):
"""Cache is used when a pubsub getItems operation is done"""
"""Cache is used when a pubsub get_items operation is done"""
items_ret = defer.Deferred()
items_ret.callback(([], {}))
client.pubsub_client.items = MagicMock(return_value=items_ret)
host.memory.storage.getPubsubNode.return_value = None
pubsub_node = host.memory.storage.setPubsubNode.return_value = PubsubNode(
host.memory.storage.get_pubsub_node.return_value = None
pubsub_node = host.memory.storage.set_pubsub_node.return_value = PubsubNode(
sync_state = None
)
with patch.object(host.plugins["PUBSUB_CACHE"], "cacheNode") as cacheNode:
await host.plugins["XEP-0060"].getItems(
with patch.object(host.plugins["PUBSUB_CACHE"], "cache_node") as cache_node:
await host.plugins["XEP-0060"].get_items(
client,
None,
"urn:xmpp:microblog:0",
)
assert cacheNode.call_count == 1
assert cacheNode.call_args.args[-1] == pubsub_node
assert cache_node.call_count == 1
assert cache_node.call_args.args[-1] == pubsub_node
@ed
async def test_cache_is_skipped_with_use_cache_false(self, host, client):
@ -50,18 +50,18 @@ class TestPubsubCache:
items_ret = defer.Deferred()
items_ret.callback(([], {}))
client.pubsub_client.items = MagicMock(return_value=items_ret)
host.memory.storage.getPubsubNode.return_value = None
host.memory.storage.setPubsubNode.return_value = PubsubNode(
host.memory.storage.get_pubsub_node.return_value = None
host.memory.storage.set_pubsub_node.return_value = PubsubNode(
sync_state = None
)
with patch.object(host.plugins["PUBSUB_CACHE"], "cacheNode") as cacheNode:
await host.plugins["XEP-0060"].getItems(
with patch.object(host.plugins["PUBSUB_CACHE"], "cache_node") as cache_node:
await host.plugins["XEP-0060"].get_items(
client,
None,
"urn:xmpp:microblog:0",
extra = {C.KEY_USE_CACHE: False}
)
assert not cacheNode.called
assert not cache_node.called
@ed
async def test_cache_is_not_used_when_no_cache(self, host, client):
@ -70,17 +70,17 @@ class TestPubsubCache:
items_ret = defer.Deferred()
items_ret.callback(([], {}))
client.pubsub_client.items = MagicMock(return_value=items_ret)
host.memory.storage.getPubsubNode.return_value = None
host.memory.storage.setPubsubNode.return_value = PubsubNode(
host.memory.storage.get_pubsub_node.return_value = None
host.memory.storage.set_pubsub_node.return_value = PubsubNode(
sync_state = None
)
with patch.object(host.plugins["PUBSUB_CACHE"], "cacheNode") as cacheNode:
await host.plugins["XEP-0060"].getItems(
with patch.object(host.plugins["PUBSUB_CACHE"], "cache_node") as cache_node:
await host.plugins["XEP-0060"].get_items(
client,
None,
"urn:xmpp:microblog:0",
)
assert not cacheNode.called
assert not cache_node.called
@ed
@ -89,20 +89,20 @@ class TestPubsubCache:
items_ret = defer.Deferred()
items_ret.callback(([], {}))
client.pubsub_client.items = MagicMock(return_value=items_ret)
host.memory.storage.getPubsubNode.return_value = PubsubNode(
host.memory.storage.get_pubsub_node.return_value = PubsubNode(
sync_state = SyncState.COMPLETED
)
with patch.object(
host.plugins["PUBSUB_CACHE"],
"getItemsFromCache"
) as getItemsFromCache:
getItemsFromCache.return_value = ([], {})
await host.plugins["XEP-0060"].getItems(
"get_items_from_cache"
) as get_items_from_cache:
get_items_from_cache.return_value = ([], {})
await host.plugins["XEP-0060"].get_items(
client,
None,
"urn:xmpp:microblog:0",
)
assert getItemsFromCache.call_count == 1
assert get_items_from_cache.call_count == 1
assert not client.pubsub_client.items.called
@ed
@ -111,21 +111,21 @@ class TestPubsubCache:
items_ret = defer.Deferred()
items_ret.callback(([], {}))
client.pubsub_client.items = MagicMock(return_value=items_ret)
host.memory.storage.getPubsubNode.return_value = PubsubNode(
host.memory.storage.get_pubsub_node.return_value = PubsubNode(
sync_state = SyncState.IN_PROGRESS
)
with patch.object(host.plugins["PUBSUB_CACHE"], "analyseNode") as analyseNode:
analyseNode.return_value = {"to_sync": True}
with patch.object(host.plugins["PUBSUB_CACHE"], "analyse_node") as analyse_node:
analyse_node.return_value = {"to_sync": True}
with patch.object(
host.plugins["PUBSUB_CACHE"],
"getItemsFromCache"
) as getItemsFromCache:
getItemsFromCache.return_value = ([], {})
"get_items_from_cache"
) as get_items_from_cache:
get_items_from_cache.return_value = ([], {})
assert client.pubsub_client.items.call_count == 0
await host.plugins["XEP-0060"].getItems(
await host.plugins["XEP-0060"].get_items(
client,
None,
"urn:xmpp:microblog:0",
)
assert not getItemsFromCache.called
assert not get_items_from_cache.called
assert client.pubsub_client.items.call_count == 1