From 07a8b1e2c9187e0f1efa5f4ebd31fa1ee22c06f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20MOHIER?= Date: Sun, 25 Mar 2018 12:10:19 +0200 Subject: [PATCH] Try to improve coverage --- alignak/objects/config.py | 2 +- alignak/objects/host.py | 84 +++++++++++-------------------- alignak/objects/schedulingitem.py | 54 ++++++++++---------- alignak/objects/service.py | 54 ++++++++++---------- alignak/util.py | 45 +---------------- 5 files changed, 84 insertions(+), 155 deletions(-) diff --git a/alignak/objects/config.py b/alignak/objects/config.py index a304ecc50..6b654e73b 100644 --- a/alignak/objects/config.py +++ b/alignak/objects/config.py @@ -2770,7 +2770,7 @@ def prepare_for_sending(self): # Now serialize the whole configuration, for sending to spare arbiters self.spare_arbiter_conf = serialize(self) - def dump(self, dump_file=None): + def dump(self, dump_file=None): # pragma: no cover, not for unit tests... """Dump configuration to a file in a JSON format :param dump_file: the file to dump diff --git a/alignak/objects/host.py b/alignak/objects/host.py index 0841a2918..b8fd71d37 100644 --- a/alignak/objects/host.py +++ b/alignak/objects/host.py @@ -435,34 +435,6 @@ def get_hostgroups(self): """ return self.hostgroups - def get_host_tags(self): - """Accessor to tags attribute - - :return: tag list of host - :rtype: list - """ - return self.tags - - # def get_realm_name(self): - # """Accessor to realm attribute - # :return: realm object of host - # :rtype: alignak.objects.realm.Realm - # """ - # return self.realm_name - # - def is_linked_with_host(self, other): - """Check if other is in act_depend_of host attribute - - :param other: other host to search - :type other: alignak.objects.host.Host - :return: True if other in act_depend_of list, otherwise False - :rtype: bool - """ - for (host, _, _, _) in self.act_depend_of: - if host == other: - return True - return False - def add_service_link(self, service): """Add a service to the service list of this host @@ -908,34 +880,34 @@ def manage_stalking(self, check): if need_stalk: logger.info("Stalking %s: %s", self.get_name(), self.output) - def get_data_for_checks(self): - """Get data for a check - - :return: list containing a single host (this one) - :rtype: list - """ - return [self] - - def get_data_for_event_handler(self): - """Get data for an event handler - - :return: list containing a single host (this one) - :rtype: list - """ - return [self] - - def get_data_for_notifications(self, contact, notif): - """Get data for a notification - - :param contact: The contact to return - :type contact: - :param notif: the notification to return - :type notif: - :return: list containing a the host and the given parameters - :rtype: list - """ - return [self, contact, notif] - + # def get_data_for_checks(self): + # """Get data for a check + # + # :return: list containing a single host (this one) + # :rtype: list + # """ + # return [self] + # + # def get_data_for_event_handler(self): + # """Get data for an event handler + # + # :return: list containing a single host (this one) + # :rtype: list + # """ + # return [self] + # + # def get_data_for_notifications(self, contact, notif): + # """Get data for a notification + # + # :param contact: The contact to return + # :type contact: + # :param notif: the notification to return + # :type notif: + # :return: list containing a the host and the given parameters + # :rtype: list + # """ + # return [self, contact, notif] + # def notification_is_blocked_by_contact(self, notifways, timeperiods, notif, contact): """Check if the notification is blocked by this contact. diff --git a/alignak/objects/schedulingitem.py b/alignak/objects/schedulingitem.py index ed14327d3..3114bc728 100644 --- a/alignak/objects/schedulingitem.py +++ b/alignak/objects/schedulingitem.py @@ -2942,33 +2942,33 @@ def raise_notification_log_entry(self, notif, contact, host_ref): # pragma: no """ pass - def get_data_for_checks(self): # pragma: no cover, base function - """Get data for a check - - :return: list containing the service and the linked host - :rtype: list - """ - pass - - def get_data_for_event_handler(self): # pragma: no cover, base function - """Get data for an event handler - - :return: list containing a single item (this one) - :rtype: list - """ - pass - - def get_data_for_notifications(self, contact, notif): # pragma: no cover, base function - """Get data for a notification - - :param contact: The contact to return - :type contact: - :param notif: the notification to return - :type notif: - :return: list - :rtype: list - """ - pass + # def get_data_for_checks(self): # pragma: no cover, base function + # """Get data for a check + # + # :return: list containing the service and the linked host + # :rtype: list + # """ + # pass + # + # def get_data_for_event_handler(self): # pragma: no cover, base function + # """Get data for an event handler + # + # :return: list containing a single item (this one) + # :rtype: list + # """ + # pass + # + # def get_data_for_notifications(self, contact, notif): # pragma: no cover, base function + # """Get data for a notification + # + # :param contact: The contact to return + # :type contact: + # :param notif: the notification to return + # :type notif: + # :return: list + # :rtype: list + # """ + # pass def set_impact_state(self): """We just go an impact, so we go unreachable diff --git a/alignak/objects/service.py b/alignak/objects/service.py index b6e31a934..db9217a05 100644 --- a/alignak/objects/service.py +++ b/alignak/objects/service.py @@ -929,33 +929,33 @@ def manage_stalking(self, check): if need_stalk: logger.info("Stalking %s: %s", self.get_name(), check.output) - def get_data_for_checks(self): - """Get data for a check - - :return: list containing the service and the linked host - :rtype: list - """ - return [self.host, self] - - def get_data_for_event_handler(self): - """Get data for an event handler - - :return: list containing the service and the linked host - :rtype: list - """ - return [self.host, self] - - def get_data_for_notifications(self, contact, notif): - """Get data for a notification - - :param contact: The contact to return - :type contact: - :param notif: the notification to return - :type notif: - :return: list containing the service, the host and the given parameters - :rtype: list - """ - return [self.host, self, contact, notif] + # def get_data_for_checks(self): + # """Get data for a check + # + # :return: list containing the service and the linked host + # :rtype: list + # """ + # return [self.host, self] + # + # def get_data_for_event_handler(self): + # """Get data for an event handler + # + # :return: list containing the service and the linked host + # :rtype: list + # """ + # return [self.host, self] + # + # def get_data_for_notifications(self, contact, notif): + # """Get data for a notification + # + # :param contact: The contact to return + # :type contact: + # :param notif: the notification to return + # :type notif: + # :return: list containing the service, the host and the given parameters + # :rtype: list + # """ + # return [self.host, self, contact, notif] def notification_is_blocked_by_contact(self, notifways, timeperiods, notif, contact): """Check if the notification is blocked by this contact. diff --git a/alignak/util.py b/alignak/util.py index 938a57518..e20ae9782 100644 --- a/alignak/util.py +++ b/alignak/util.py @@ -165,7 +165,7 @@ def split_semicolon(line, maxsplit=None): return split_line -def jsonify_r(obj): +def jsonify_r(obj): # pragma: no cover, not for unit tests... """Convert an object into json (recursively on attribute) :param obj: obj to jsonify @@ -245,20 +245,6 @@ def get_end_of_day(year, month_id, day): return end_time_epoch -def print_date(timestamp): - """Get date (local) in asc format from timestamp - - example : 'Thu Jan 1 01:00:00 1970' (for timestamp=0 in a EUW server) - - :param timestamp: timestamp - :type timestamp; int - :return: formatted time - :rtype: int - TODO: Missing timezone - """ - return time.asctime(time.localtime(timestamp)) - - def get_day(timestamp): """Get timestamp of the beginning of the day (local) given by timestamp @@ -669,21 +655,6 @@ def to_svc_hst_distinct_lists(ref, tab): # pragma: no cover, to be deprectaed? return res -def get_obj_name(obj): - """Get object name (call get_name) if not a string - - :param obj: obj we want the name - :type obj: object - :return: object name - :rtype: str - """ - # Maybe we do not have a real object but already a string. If so - # return the string - if isinstance(obj, basestring): - return obj - return obj.get_name() - - def get_obj_name_two_args_and_void(obj, value): # pylint: disable=W0613 """Get value name (call get_name) if not a string @@ -700,20 +671,6 @@ def get_obj_name_two_args_and_void(obj, value): # pylint: disable=W0613 return '' -def get_obj_full_name(obj): - """Wrapper to call obj.get_full_name or obj.get_name - - :param obj: object name - :type obj: object - :return: object name - :rtype: str - """ - try: - return obj.get_full_name() - except AttributeError: - return obj.get_name() - - def get_customs_keys(dic): # pragma: no cover, to be deprectaed? """Get a list of keys of the custom dict without the first char