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:
parent
d50412c7f7
commit
6a6f15707a
1 changed files with 9945 additions and 9945 deletions
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
## logging configuration for tests ##
|
||||
from sat.core import log_config
|
||||
log_config.satConfigure()
|
||||
log_config.sat_configure()
|
||||
|
||||
import logging
|
||||
from sat.core.log import getLogger
|
||||
|
|
@ -52,14 +52,14 @@ def b2s(value):
|
|||
return "True" if value else "False"
|
||||
|
||||
|
||||
def muteLogging():
|
||||
def mute_logging():
|
||||
"""Temporarily set the logging level to CRITICAL to not pollute the output with expected errors."""
|
||||
logger = getLogger()
|
||||
logger.original_level = logger.getEffectiveLevel()
|
||||
logger.setLevel(logging.CRITICAL)
|
||||
|
||||
|
||||
def unmuteLogging():
|
||||
def unmute_logging():
|
||||
"""Restore the logging level after it has been temporarily disabled."""
|
||||
logger = getLogger()
|
||||
logger.setLevel(logger.original_level)
|
||||
|
|
@ -97,17 +97,17 @@ class FakeSAT(object):
|
|||
self.plugins = {}
|
||||
self.profiles = {}
|
||||
|
||||
def delContact(self, to, profile_key):
|
||||
def contact_del(self, to, profile_key):
|
||||
#TODO
|
||||
pass
|
||||
|
||||
def registerCallback(self, callback, *args, **kwargs):
|
||||
def register_callback(self, callback, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def messageSend(self, to_s, msg, subject=None, mess_type='auto', extra={}, profile_key='@NONE@'):
|
||||
self.sendAndStoreMessage({"to": JID(to_s)})
|
||||
def message_send(self, to_s, msg, subject=None, mess_type='auto', extra={}, profile_key='@NONE@'):
|
||||
self.send_and_store_message({"to": JID(to_s)})
|
||||
|
||||
def _sendMessageToStream(self, mess_data, client):
|
||||
def _send_message_to_stream(self, mess_data, client):
|
||||
"""Save the information to check later to whom messages have been sent.
|
||||
|
||||
@param mess_data: message data dictionnary
|
||||
|
|
@ -116,7 +116,7 @@ class FakeSAT(object):
|
|||
client.xmlstream.send(mess_data['xml'])
|
||||
return mess_data
|
||||
|
||||
def _storeMessage(self, mess_data, client):
|
||||
def _store_message(self, mess_data, client):
|
||||
"""Save the information to check later if entries have been added to the history.
|
||||
|
||||
@param mess_data: message data dictionnary
|
||||
|
|
@ -125,7 +125,7 @@ class FakeSAT(object):
|
|||
self.stored_messages.append(mess_data["to"])
|
||||
return mess_data
|
||||
|
||||
def sendMessageToBridge(self, mess_data, client):
|
||||
def send_message_to_bridge(self, mess_data, client):
|
||||
"""Simulate the message being sent to the frontends.
|
||||
|
||||
@param mess_data: message data dictionnary
|
||||
|
|
@ -133,33 +133,33 @@ class FakeSAT(object):
|
|||
"""
|
||||
return mess_data # TODO
|
||||
|
||||
def getProfileName(self, profile_key):
|
||||
def get_profile_name(self, profile_key):
|
||||
"""Get the profile name from the profile_key"""
|
||||
return profile_key
|
||||
|
||||
def getClient(self, profile_key):
|
||||
def get_client(self, profile_key):
|
||||
"""Convenient method to get client from profile key
|
||||
@return: client or None if it doesn't exist"""
|
||||
profile = self.memory.getProfileName(profile_key)
|
||||
profile = self.memory.get_profile_name(profile_key)
|
||||
if not profile:
|
||||
raise exceptions.ProfileKeyUnknown
|
||||
if profile not in self.profiles:
|
||||
self.profiles[profile] = FakeClient(self, profile)
|
||||
return self.profiles[profile]
|
||||
|
||||
def getJidNStream(self, profile_key):
|
||||
def get_jid_n_stream(self, profile_key):
|
||||
"""Convenient method to get jid and stream from profile key
|
||||
@return: tuple (jid, xmlstream) from profile, can be None"""
|
||||
return (C.PROFILE_DICT[profile_key], None)
|
||||
|
||||
def isConnected(self, profile):
|
||||
def is_connected(self, profile):
|
||||
return True
|
||||
|
||||
def getSentMessages(self, profile_index):
|
||||
def get_sent_messages(self, profile_index):
|
||||
"""Return all the sent messages (in the order they have been sent) and
|
||||
empty the list. Called by tests. FakeClient instances associated to each
|
||||
profile must have been previously initialized with the method
|
||||
FakeSAT.getClient.
|
||||
FakeSAT.get_client.
|
||||
|
||||
@param profile_index: index of the profile to consider (cf. C.PROFILE)
|
||||
@return: the sent messages for given profile, or None"""
|
||||
|
|
@ -170,10 +170,10 @@ class FakeSAT(object):
|
|||
except IndexError:
|
||||
return None
|
||||
|
||||
def getSentMessage(self, profile_index):
|
||||
def get_sent_message(self, profile_index):
|
||||
"""Pop and return the sent message in first position (works like a FIFO).
|
||||
Called by tests. FakeClient instances associated to each profile must have
|
||||
been previously initialized with the method FakeSAT.getClient.
|
||||
been previously initialized with the method FakeSAT.get_client.
|
||||
|
||||
@param profile_index: index of the profile to consider (cf. C.PROFILE)
|
||||
@return: the sent message for given profile, or None"""
|
||||
|
|
@ -182,20 +182,20 @@ class FakeSAT(object):
|
|||
except IndexError:
|
||||
return None
|
||||
|
||||
def getSentMessageXml(self, profile_index):
|
||||
def get_sent_message_xml(self, profile_index):
|
||||
"""Pop and return the sent message in first position (works like a FIFO).
|
||||
Called by tests. FakeClient instances associated to each profile must have
|
||||
been previously initialized with the method FakeSAT.getClient.
|
||||
been previously initialized with the method FakeSAT.get_client.
|
||||
@return: XML representation of the sent message for given profile, or None"""
|
||||
entry = self.getSentMessage(profile_index)
|
||||
entry = self.get_sent_message(profile_index)
|
||||
return entry.toXml() if entry else None
|
||||
|
||||
def findFeaturesSet(self, features, identity=None, jid_=None, profile=C.PROF_KEY_NONE):
|
||||
"""Call self.addFeature from your tests to change the return value.
|
||||
def find_features_set(self, features, identity=None, jid_=None, profile=C.PROF_KEY_NONE):
|
||||
"""Call self.add_feature from your tests to change the return value.
|
||||
|
||||
@return: a set of entities
|
||||
"""
|
||||
client = self.getClient(profile)
|
||||
client = self.get_client(profile)
|
||||
if jid_ is None:
|
||||
jid_ = JID(client.jid.host)
|
||||
try:
|
||||
|
|
@ -205,12 +205,12 @@ class FakeSAT(object):
|
|||
pass
|
||||
return defer.succeed(set())
|
||||
|
||||
def addFeature(self, jid_, feature, profile_key):
|
||||
def add_feature(self, jid_, feature, profile_key):
|
||||
"""Add a feature to an entity.
|
||||
|
||||
To be called from your tests when needed.
|
||||
"""
|
||||
client = self.getClient(profile_key)
|
||||
client = self.get_client(profile_key)
|
||||
if not hasattr(client, 'features'):
|
||||
client.features = {}
|
||||
if jid_ not in client.features:
|
||||
|
|
@ -224,13 +224,13 @@ class FakeBridge(object):
|
|||
def __init__(self):
|
||||
self.expected_calls = {}
|
||||
|
||||
def expectCall(self, name, *check_args, **check_kwargs):
|
||||
def expect_call(self, name, *check_args, **check_kwargs):
|
||||
if hasattr(self, name): # queue this new call as one already exists
|
||||
self.expected_calls.setdefault(name, [])
|
||||
self.expected_calls[name].append((check_args, check_kwargs))
|
||||
return
|
||||
|
||||
def checkCall(*args, **kwargs):
|
||||
def check_call(*args, **kwargs):
|
||||
if args != check_args or kwargs != check_kwargs:
|
||||
print("\n\n--------------------")
|
||||
print("Args are not equals:")
|
||||
|
|
@ -244,19 +244,19 @@ class FakeBridge(object):
|
|||
args, kwargs = self.expected_calls[name].pop(0)
|
||||
if len(self.expected_calls[name]) == 0:
|
||||
del self.expected_calls[name]
|
||||
self.expectCall(name, *args, **kwargs)
|
||||
self.expect_call(name, *args, **kwargs)
|
||||
|
||||
setattr(self, name, checkCall)
|
||||
setattr(self, name, check_call)
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc=None):
|
||||
def add_method(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc=None):
|
||||
pass
|
||||
|
||||
def addSignal(self, name, int_suffix, signature):
|
||||
def add_signal(self, name, int_suffix, signature):
|
||||
pass
|
||||
|
||||
def addTestCallback(self, name, method):
|
||||
def add_test_callback(self, name, method):
|
||||
"""This can be used to register callbacks for bridge methods AND signals.
|
||||
Contrary to expectCall, this will not check if the method or signal is
|
||||
Contrary to expect_call, this will not check if the method or signal is
|
||||
called/sent with the correct arguments, it will instead run the callback
|
||||
of your choice."""
|
||||
setattr(self, name, method)
|
||||
|
|
@ -271,16 +271,16 @@ class FakeParams(Params):
|
|||
Params.__init__(self, host, storage)
|
||||
self.params = {} # naive simulation of values storage
|
||||
|
||||
def setParam(self, name, value, category, security_limit=-1, profile_key='@NONE@'):
|
||||
profile = self.getProfileName(profile_key)
|
||||
def param_set(self, name, value, category, security_limit=-1, profile_key='@NONE@'):
|
||||
profile = self.get_profile_name(profile_key)
|
||||
self.params.setdefault(profile, {})
|
||||
self.params[profile_key][(category, name)] = value
|
||||
|
||||
def getParamA(self, name, category, attr="value", profile_key='@NONE@'):
|
||||
profile = self.getProfileName(profile_key)
|
||||
def param_get_a(self, name, category, attr="value", profile_key='@NONE@'):
|
||||
profile = self.get_profile_name(profile_key)
|
||||
return self.params[profile][(category, name)]
|
||||
|
||||
def getProfileName(self, profile_key, return_profile_keys=False):
|
||||
def get_profile_name(self, profile_key, return_profile_keys=False):
|
||||
if profile_key == '@DEFAULT@':
|
||||
return C.PROFILE[0]
|
||||
elif profile_key == '@NONE@':
|
||||
|
|
@ -288,7 +288,7 @@ class FakeParams(Params):
|
|||
else:
|
||||
return profile_key
|
||||
|
||||
def loadIndParams(self, profile, cache=None):
|
||||
def load_ind_params(self, profile, cache=None):
|
||||
self.params[profile] = {}
|
||||
return defer.succeed(None)
|
||||
|
||||
|
|
@ -301,7 +301,7 @@ class FakeMemory(Memory):
|
|||
# manipulating basic stuff, the others should be overwritten when needed
|
||||
self.host = host
|
||||
self.params = FakeParams(host, None)
|
||||
self.config = tools_config.parseMainConf()
|
||||
self.config = tools_config.parse_main_conf()
|
||||
self.reinit()
|
||||
|
||||
def reinit(self):
|
||||
|
|
@ -312,29 +312,29 @@ class FakeMemory(Memory):
|
|||
self.params.frontends_cache = []
|
||||
self.entities_data = {}
|
||||
|
||||
def getProfileName(self, profile_key, return_profile_keys=False):
|
||||
return self.params.getProfileName(profile_key, return_profile_keys)
|
||||
def get_profile_name(self, profile_key, return_profile_keys=False):
|
||||
return self.params.get_profile_name(profile_key, return_profile_keys)
|
||||
|
||||
def addToHistory(self, from_jid, to_jid, message, _type='chat', extra=None, timestamp=None, profile="@NONE@"):
|
||||
def add_to_history(self, from_jid, to_jid, message, _type='chat', extra=None, timestamp=None, profile="@NONE@"):
|
||||
pass
|
||||
|
||||
def addContact(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'):
|
||||
def contact_add(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'):
|
||||
pass
|
||||
|
||||
def setPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'):
|
||||
def set_presence_status(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'):
|
||||
pass
|
||||
|
||||
def addWaitingSub(self, type_, contact_jid, profile_key):
|
||||
def add_waiting_sub(self, type_, contact_jid, profile_key):
|
||||
pass
|
||||
|
||||
def delWaitingSub(self, contact_jid, profile_key):
|
||||
def del_waiting_sub(self, contact_jid, profile_key):
|
||||
pass
|
||||
|
||||
def updateEntityData(self, entity_jid, key, value, silent=False, profile_key="@NONE@"):
|
||||
def update_entity_data(self, entity_jid, key, value, silent=False, profile_key="@NONE@"):
|
||||
self.entities_data.setdefault(entity_jid, {})
|
||||
self.entities_data[entity_jid][key] = value
|
||||
|
||||
def getEntityData(self, entity_jid, keys, profile_key):
|
||||
def entity_data_get(self, entity_jid, keys, profile_key):
|
||||
result = {}
|
||||
for key in keys:
|
||||
result[key] = self.entities_data[entity_jid][key]
|
||||
|
|
@ -358,9 +358,9 @@ class FakeRosterProtocol(SatRosterProtocol):
|
|||
SatRosterProtocol.__init__(self, host)
|
||||
self.parent = parent
|
||||
self._jids = {}
|
||||
self.addItem(parent.jid.userhostJID())
|
||||
self.add_item(parent.jid.userhostJID())
|
||||
|
||||
def addItem(self, jid, *args, **kwargs):
|
||||
def add_item(self, jid, *args, **kwargs):
|
||||
if not args and not kwargs:
|
||||
# defaults values setted for the tests only
|
||||
kwargs["subscriptionTo"] = True
|
||||
|
|
@ -369,9 +369,9 @@ class FakeRosterProtocol(SatRosterProtocol):
|
|||
attrs = {'to': b2s(roster_item.subscriptionTo), 'from': b2s(roster_item.subscriptionFrom), 'ask': b2s(roster_item.pendingOut)}
|
||||
if roster_item.name:
|
||||
attrs['name'] = roster_item.name
|
||||
self.host.bridge.expectCall("newContact", jid.full(), attrs, roster_item.groups, self.parent.profile)
|
||||
self.host.bridge.expect_call("contact_new", jid.full(), attrs, roster_item.groups, self.parent.profile)
|
||||
self._jids[jid] = roster_item
|
||||
self._registerItem(roster_item)
|
||||
self._register_item(roster_item)
|
||||
|
||||
|
||||
class FakeXmlStream(object):
|
||||
|
|
@ -420,8 +420,8 @@ class FakeClient(object):
|
|||
|
||||
class SatTestCase(unittest.TestCase):
|
||||
|
||||
def assertEqualXML(self, xml, expected, ignore_blank=False):
|
||||
def equalElt(got_elt, exp_elt):
|
||||
def assert_equal_xml(self, xml, expected, ignore_blank=False):
|
||||
def equal_elt(got_elt, exp_elt):
|
||||
if ignore_blank:
|
||||
for elt in got_elt, exp_elt:
|
||||
for attr in ('text', 'tail'):
|
||||
|
|
@ -449,7 +449,7 @@ class SatTestCase(unittest.TestCase):
|
|||
print("children len: got %d expected: %d" % (len(got_elt), len(exp_elt)))
|
||||
return False
|
||||
for idx, child in enumerate(got_elt):
|
||||
if not equalElt(child, exp_elt[idx]):
|
||||
if not equal_elt(child, exp_elt[idx]):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -460,7 +460,7 @@ class SatTestCase(unittest.TestCase):
|
|||
xml_elt = etree.fromstring(remove_blank(xml) if ignore_blank else xml)
|
||||
expected_elt = etree.fromstring(remove_blank(expected) if ignore_blank else expected)
|
||||
|
||||
if not equalElt(xml_elt, expected_elt):
|
||||
if not equal_elt(xml_elt, expected_elt):
|
||||
print("---")
|
||||
print("XML are not equals:")
|
||||
print("got:\n-\n%s\n-\n\n" % etree.tostring(xml_elt, encoding='utf-8'))
|
||||
|
|
@ -468,7 +468,7 @@ class SatTestCase(unittest.TestCase):
|
|||
print("---")
|
||||
raise DifferentXMLException
|
||||
|
||||
def assertEqualUnsortedList(self, a, b, msg):
|
||||
def assert_equal_unsorted_list(self, a, b, msg):
|
||||
counter_a = Counter(a)
|
||||
counter_b = Counter(b)
|
||||
if counter_a != counter_b:
|
||||
|
|
|
|||
Loading…
Reference in a new issue