def _common_fixtures(fixture): """Generate common fixtures and return global dictionary of executed common fixtures. """ dynamic_fixtures.generate_common_fixtures(fixture) if isinstance(fixture, tuple): fixture, _ = fixture fixture = dynamic_fixtures.dict_executed_fixtures[fixture] return (help_utils.get_single_obj(fixture) if not help_utils.is_multiple_objs(fixture) else fixture)
def _common_fixtures(fixture): """Generate common fixtures and return global dictionary of executed common fixtures. """ dynamic_fixtures.generate_common_fixtures(fixture) if isinstance(fixture, tuple): fixture, _ = fixture fixture = dynamic_fixtures.dict_executed_fixtures[fixture] return (help_utils.get_single_obj(fixture) if not help_utils.is_multiple_objs(fixture) else fixture)
def filter_objs_by_attrs(objs, **attrs): """Filter objects by attributes' items and return matched according to plurality. 'objs' - object or list objects; '**attrs' - items of attributes' names and values. """ list_objs = help_utils.convert_to_list(objs) matched_objs = [ obj for obj in list_objs if isinstance(obj, Entity.all_entities_classes()) and StringMethods.is_subset_of_dicts(dict(**attrs), obj.__dict__)] return (help_utils.get_single_obj(matched_objs) if not help_utils.is_multiple_objs(matched_objs) else matched_objs)
def filter_objs_by_attrs(objs, **attrs): """Filter objects by attributes' items and return matched according to plurality. 'objs' - object or list objects; '**attrs' - items of attributes' names and values. """ list_objs = help_utils.convert_to_list(objs) matched_objs = [ obj for obj in list_objs if isinstance(obj, Entity.all_entities_classes()) and StringMethods.is_subset_of_dicts(dict(**attrs), obj.__dict__)] return (help_utils.get_single_obj(matched_objs) if not help_utils.is_multiple_objs(matched_objs) else matched_objs)
def compare_comments(self_comments, other_comments): """Compare entities' 'comments' attributes due to specific dictionaries' format values in list comments. """ # pylint: disable=no-else-return if help_utils.is_multiple_objs( StringMethods.convert_list_elements_to_list( [self_comments, other_comments]), (dict, type(None))): if self_comments and other_comments: is_comments_equal_list = [] for self_comment, other_comment in zip(self_comments, other_comments): is_comments_equal = False if self_comment and other_comment: is_comments_equal = (all( (Representation.compare_datetime( self_comment.get("created_at"), other_comment.get("created_at")) if ( isinstance(_self, datetime) and isinstance(_other, datetime) ) else _self == _other) for _self, _other in zip(self_comment.iteritems( ), other_comment.iteritems()))) # convert datetime to unicode in order to get visible repr if self_comment.get("created_at"): self_comment["created_at"] = unicode( self_comment.get("created_at")) if other_comment.get("created_at"): other_comment["created_at"] = unicode( other_comment.get("created_at")) else: is_comments_equal = self_comment == other_comment is_comments_equal_list.append(is_comments_equal) return all(is_equal for is_equal in is_comments_equal_list) else: return self_comments == other_comments else: Representation.attrs_values_types_error( self_attr=self_comments, other_attr=other_comments, expected_types=(list.__name__, type(None).__name__))
def compare_comments(self_comments, other_comments): """Compare entities' 'comments' attributes due to specific dictionaries' format values in list comments. """ # pylint: disable=no-else-return if help_utils.is_multiple_objs( StringMethods.convert_list_elements_to_list( [self_comments, other_comments]), (dict, type(None))): if self_comments and other_comments: is_comments_equal_list = [] for self_comment, other_comment in zip(self_comments, other_comments): is_comments_equal = False if self_comment and other_comment: is_comments_equal = ( all((Representation.compare_datetime( self_comment.get("created_at"), other_comment.get("created_at") ) if (isinstance(_self, datetime) and isinstance(_other, datetime))else _self == _other) for _self, _other in zip( self_comment.iteritems(), other_comment.iteritems()))) # convert datetime to unicode in order to get visible repr if self_comment.get("created_at"): self_comment["created_at"] = unicode( self_comment.get("created_at")) if other_comment.get("created_at"): other_comment["created_at"] = unicode( other_comment.get("created_at")) else: is_comments_equal = self_comment == other_comment is_comments_equal_list.append(is_comments_equal) return all(is_equal for is_equal in is_comments_equal_list) else: return self_comments == other_comments else: Representation.attrs_values_types_error( self_attr=self_comments, other_attr=other_comments, expected_types=(list.__name__, type(None).__name__))