def test_to_obj(): value_0 = 0 value_1 = 1 value_2 = '2' value_empty = '' assert to_obj(None) is None assert to_obj(None, default_value='') == '' assert to_obj(value_0) == '0' assert to_obj(value_0, obj_type=bool) is False assert to_obj(value_1) == '1' assert to_obj(value_2, obj_type=int) == 2 assert to_obj(value_empty) == '' assert to_obj(value_empty, obj_type=int) is None assert to_obj(value_empty, obj_type=int, default_value=0) == 0 assert to_obj(value_empty, obj_type=bool) is False
def set_attr(self, key, value): """Set an attribute. It takes care of converting the value if needed. :param key: the attribute key :type key: str :param value: the attribute value :type value: str """ if hasattr(self, key): if key in ['tvdb_id']: # # Set as int setattr(self, key, to_obj(value, obj_type=int)) elif key in ['wanted_languages']: # Must be returned as a list of values setattr(self, key, to_list(value, default_value=[])) elif key in ['refine', 'hearing_impaired', 'utf8_encoding']: # Set as bool setattr(self, key, to_obj(value, obj_type=bool)) else: # Use default value setattr(self, key, value)
def set_attr(self, key, value): """Set an attribute. It takes care of converting the value if needed. :param key: the attribute key :type key: str :param value: the attribute value :type value: str """ if hasattr(self, key): if key in ['tvdb_id', 'year']: # # Set as int setattr(self, key, to_obj(value, obj_type=int)) else: # Use default value setattr(self, key, value)
def set_attr(self, key, value): """Set an attribute. It takes care of converting the value if needed. :param key: the attribute key :type key: str :param value: the attribute value :type value: str """ if hasattr(self, key): if key in ['languages']: # Must be returned as a list of values setattr(self, key, to_list(value, default_value=[])) elif key in ['tvdbid']: setattr(self, key, to_obj(value, obj_type=int)) else: super(WantedItem, self).set_attr(key, value)
def set_attr(self, key, value): """Set an attribute. It takes care of converting the value if needed. :param key: the attribute key :type key: str :param value: the attribute value :type value: str """ if hasattr(self, key): if key in ['year']: # # Set as int setattr(self, key, to_obj(value, obj_type=int)) elif key in ['missing_languages']: # Must be returned as a list of values setattr(self, key, to_list(value, default_value=[])) else: # Use default value setattr(self, key, value)
def set_attr(self, key, value): """Set an attribute. It takes care of converting the value if needed. :param key: the attribute key :type key: str :param value: the attribute value :type value: str """ if hasattr(self, key): if key in ['year', 'season']: # Set as int setattr(self, key, to_obj(value, int)) elif key in ['episode']: # Can be returned as a list of int values setattr(self, key, to_obj_or_list(value, int)) elif key in ['source', 'codec']: # Can be returned as a list of text values setattr(self, key, to_obj_or_list(value)) else: # Use default value setattr(self, key, value)