diff --git a/docs/source/conf.py b/docs/source/conf.py index 953d3df4cd..60d9385049 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -35,8 +35,8 @@ extensions = [ "sphinx.ext.githubpages", ] -source_suffix = ['.md', '.rst'] -master_doc = 'index' +source_suffix = [".md", ".rst"] +master_doc = "index" # make sure sectionlabel references can be used as path/to/file:heading autosectionlabel_prefix_document = True @@ -74,9 +74,9 @@ smv_tag_whitelist = r"^$" # html_theme = 'scrolls' # html_theme = 'agogo' # html_theme = "traditional" -html_theme = 'nature' +html_theme = "nature" ## html_theme = 'pyramid' -#html_theme = 'bizstyle' +# html_theme = 'bizstyle' # html_theme = 'epub' # Custom extras for sidebar @@ -100,23 +100,23 @@ pygments_style = "sphinx" # -- Options for LaTeX output ------------------------------------------------ # experimental, not working well atm -latex_engine = 'xelatex' -latex_show_urls = 'footnote' +latex_engine = "xelatex" +latex_show_urls = "footnote" latex_elements = { - 'papersize': 'a4paper', - 'fncychap': r'\usepackage[Bjarne]{fncychap}', - 'fontpkg': r'\usepackage{times,amsmath,amsfonts,amssymb,amsthm}', - 'preamble': r''' + "papersize": "a4paper", + "fncychap": r"\usepackage[Bjarne]{fncychap}", + "fontpkg": r"\usepackage{times,amsmath,amsfonts,amssymb,amsthm}", + "preamble": r""" \usepackage[utf8]{fontenc} \usepackage{amsmath,amsfonts,amssymb,amsthm} \usepackage[math-style=literal]{unicode-math} \usepackage{newunicodechar} \usepackage{graphicx} - ''' + """, } latex_documents = [ - (master_doc, 'main.tex', 'Sphinx format', 'Evennia', 'report'), - ("toc", 'toc.tex', 'TOC', 'Evennia', 'report') + (master_doc, "main.tex", "Sphinx format", "Evennia", "report"), + ("toc", "toc.tex", "TOC", "Evennia", "report"), ] @@ -139,7 +139,7 @@ def url_resolver(url): return _github_issue_choose elif url.startswith(githubstart): - urlpath = url[len(githubstart):] + urlpath = url[len(githubstart) :] if not (urlpath.startswith("develop/") or urlpath.startswith("master")): urlpath = "master/" + urlpath return _github_code_root + urlpath @@ -240,13 +240,15 @@ napoleon_use_rtype = True # -- Main config setup ------------------------------------------ # last setup steps for some plugins + def setup(app): app.connect("autodoc-skip-member", autodoc_skip_member) app.add_transform(AutoStructify) # build toctree file - sys.path.insert(1, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'docs')) + sys.path.insert(1, os.path.join(os.path.dirname(os.path.dirname(__file__)), "docs")) from docs.pylib import create_toctree + create_toctree.create_toctree() print("Updated source/toc.md file") diff --git a/evennia/commands/default/help.py b/evennia/commands/default/help.py index 1e4786e1ee..a2bcf158ad 100644 --- a/evennia/commands/default/help.py +++ b/evennia/commands/default/help.py @@ -92,9 +92,7 @@ def help_search_with_index(query, candidate_entries, suggestion_maxnum=5): # matches (objs), suggestions (strs) return ( [mapping[match["ref"]] for match in matches], - [ - str(match["ref"]) for match in matches - ], # + f" (score {match['score']})") # good debug + [str(match["ref"]) for match in matches], # + f" (score {match['score']})") # good debug ) @@ -140,10 +138,7 @@ class CmdHelp(Command): if type(self).help_more: usemore = True - if self.session and self.session.protocol_key in ( - "websocket", - "ajax/comet", - ): + if self.session and self.session.protocol_key in ("websocket", "ajax/comet",): try: options = self.account.db._saved_webclient_options if options and options["helppopup"]: @@ -177,9 +172,7 @@ class CmdHelp(Command): if title: string += "|CHelp for |w%s|n" % title if aliases: - string += " |C(aliases: %s|C)|n" % ( - "|C,|n ".join("|w%s|n" % ali for ali in aliases) - ) + string += " |C(aliases: %s|C)|n" % ("|C,|n ".join("|w%s|n" % ali for ali in aliases)) if help_text: string += "\n%s" % dedent(help_text.rstrip()) if suggested: @@ -206,22 +199,15 @@ class CmdHelp(Command): category_str = f"-- {category.title()} " grid.append( ANSIString( - category_clr - + category_str - + "-" * (width - len(category_str)) - + topic_clr + category_clr + category_str + "-" * (width - len(category_str)) + topic_clr ) ) verbatim_elements.append(len(grid) - 1) - entries = sorted( - set(hdict_cmds.get(category, []) + hdict_db.get(category, [])) - ) + entries = sorted(set(hdict_cmds.get(category, []) + hdict_db.get(category, []))) grid.extend(entries) - gridrows = format_grid( - grid, width, sep=" ", verbatim_elements=verbatim_elements - ) + gridrows = format_grid(grid, width, sep=" ", verbatim_elements=verbatim_elements) gridrows = ANSIString("\n").join(gridrows) return gridrows @@ -293,9 +279,7 @@ class CmdHelp(Command): # retrieve all available commands and database topics all_cmds = [cmd for cmd in cmdset if self.check_show_help(cmd, caller)] all_topics = [ - topic - for topic in HelpEntry.objects.all() - if topic.access(caller, "view", default=True) + topic for topic in HelpEntry.objects.all() if topic.access(caller, "view", default=True) ] all_categories = list( set( @@ -320,11 +304,7 @@ class CmdHelp(Command): return # Try to access a particular help entry or category - entries = ( - [cmd for cmd in all_cmds if cmd] - + list(HelpEntry.objects.all()) - + all_categories - ) + entries = [cmd for cmd in all_cmds if cmd] + list(HelpEntry.objects.all()) + all_categories for match_query in [f"{query}~1", f"{query}*"]: # We first do an exact word-match followed by a start-by query @@ -459,9 +439,7 @@ class CmdSetHelp(COMMAND_DEFAULT_CLASS): # check if we have an old entry with the same name try: for querystr in topicstrlist: - old_entry = HelpEntry.objects.find_topicmatch( - querystr - ) # also search by alias + old_entry = HelpEntry.objects.find_topicmatch(querystr) # also search by alias if old_entry: old_entry = list(old_entry)[0] break @@ -483,11 +461,7 @@ class CmdSetHelp(COMMAND_DEFAULT_CLASS): helpentry = old_entry else: helpentry = create.create_help_entry( - topicstr, - self.rhs, - category=category, - locks=lockstring, - aliases=aliases, + topicstr, self.rhs, category=category, locks=lockstring, aliases=aliases, ) self.caller.db._editing_help = helpentry @@ -504,9 +478,7 @@ class CmdSetHelp(COMMAND_DEFAULT_CLASS): if "append" in switches or "merge" in switches or "extend" in switches: # merge/append operations if not old_entry: - self.msg( - "Could not find topic '%s'. You must give an exact name." % topicstr - ) + self.msg("Could not find topic '%s'. You must give an exact name." % topicstr) return if not self.rhs: self.msg("You must supply text to append/merge.") @@ -553,9 +525,7 @@ class CmdSetHelp(COMMAND_DEFAULT_CLASS): topicstr, self.rhs, category=category, locks=lockstring, aliases=aliases ) if new_entry: - self.msg( - "Topic '%s'%s was successfully created." % (topicstr, aliastxt) - ) + self.msg("Topic '%s'%s was successfully created." % (topicstr, aliastxt)) if "edit" in switches: # open the line editor to edit the helptext self.caller.db._editing_help = new_entry @@ -570,6 +540,5 @@ class CmdSetHelp(COMMAND_DEFAULT_CLASS): return else: self.msg( - "Error when creating topic '%s'%s! Contact an admin." - % (topicstr, aliastxt) + "Error when creating topic '%s'%s! Contact an admin." % (topicstr, aliastxt) ) diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index c6eff24809..9ed9a4129b 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -265,16 +265,17 @@ class TestGeneral(CommandTest): class TestHelp(CommandTest): - def setUp(self): super().setUp() # we need to set up a logger here since lunr takes over the logger otherwise import logging + logging.basicConfig(level=logging.ERROR) def tearDown(self): super().tearDown() import logging + logging.disable(level=logging.ERROR) def test_help(self): diff --git a/evennia/contrib/puzzles.py b/evennia/contrib/puzzles.py index 924addfc32..6052b7d43f 100644 --- a/evennia/contrib/puzzles.py +++ b/evennia/contrib/puzzles.py @@ -611,7 +611,6 @@ class CmdUsePuzzleParts(MuxCommand): passed in. """ - key = "use" aliases = "combine" locks = "cmd:pperm(use) or pperm(Player)" diff --git a/evennia/server/portal/tests.py b/evennia/server/portal/tests.py index 8ba98732a3..6bd76db827 100644 --- a/evennia/server/portal/tests.py +++ b/evennia/server/portal/tests.py @@ -1,4 +1,3 @@ - try: from django.utils.unittest import TestCase except ImportError: @@ -290,7 +289,7 @@ class TestWebSocket(EvenniaTest): self.proto.sessionhandler = PORTAL_SESSIONS self.proto.sessionhandler.portal = Mock() self.proto.transport = proto_helpers.StringTransport() - #self.proto.transport = proto_helpers.FakeDatagramTransport() + # self.proto.transport = proto_helpers.FakeDatagramTransport() self.proto.transport.client = ["localhost"] self.proto.transport.setTcpKeepAlive = Mock() self.proto.state = MagicMock() @@ -318,4 +317,4 @@ class TestWebSocket(EvenniaTest): self.proto.sendLine = MagicMock() msg = json.dumps(["logged_in", (), {}]) self.proto.sessionhandler.data_out(self.proto, text=[["Excepting Alice"], {}]) - self.proto.sendLine.assert_called_with(json.dumps(['text', ['Excepting Alice'], {}])) + self.proto.sendLine.assert_called_with(json.dumps(["text", ["Excepting Alice"], {}])) diff --git a/evennia/server/server.py b/evennia/server/server.py index 0dc7e1cc57..a1b70820ea 100644 --- a/evennia/server/server.py +++ b/evennia/server/server.py @@ -132,7 +132,7 @@ def _server_maintenance(): else: # adjust the runtime not with 60s but with the actual elapsed time # in case this may varies slightly from 60s. - _GAMETIME_MODULE.SERVER_RUNTIME += (now - _LAST_SERVER_TIME_SNAPSHOT) + _GAMETIME_MODULE.SERVER_RUNTIME += now - _LAST_SERVER_TIME_SNAPSHOT _LAST_SERVER_TIME_SNAPSHOT = now # update game time and save it across reloads diff --git a/evennia/typeclasses/attributes.py b/evennia/typeclasses/attributes.py index 001cee929d..d224c5173c 100644 --- a/evennia/typeclasses/attributes.py +++ b/evennia/typeclasses/attributes.py @@ -162,6 +162,7 @@ class Attribute(IAttribute, SharedMemoryModel): """ This attribute is stored via Django. Most Attributes will be using this class. """ + # # Attribute Database Model setup # @@ -269,10 +270,12 @@ class Attribute(IAttribute, SharedMemoryModel): value = property(__value_get, __value_set, __value_del) + # # Handlers making use of the Attribute model # + class IAttributeBackend: """ Abstract interface for the backends used by the Attribute Handler. @@ -336,8 +339,10 @@ class IAttributeBackend: if not _TYPECLASS_AGGRESSIVE_CACHE: return attrs = self.query_all() - self._cache = {f"{to_str(attr.key).lower()}-{attr.category.lower() if attr.category else None}": attr - for attr in attrs} + self._cache = { + f"{to_str(attr.key).lower()}-{attr.category.lower() if attr.category else None}": attr + for attr in attrs + } self._cache_complete = True def _get_cache_key(self, key, category): @@ -623,7 +628,9 @@ class IAttributeBackend: # update an existing attribute object self.do_batch_update_attribute(attr_obj, category, lockstring, new_value, strattr) else: - new_attr = self.do_create_attribute(keystr, category, lockstring, new_value, strvalue=strattr) + new_attr = self.do_create_attribute( + keystr, category, lockstring, new_value, strvalue=strattr + ) new_attrobjs.append(new_attr) if new_attrobjs: self.do_batch_finish(new_attrobjs) @@ -696,8 +703,13 @@ class IAttributeBackend: attrs = self._cache.values() if accessing_obj: - self.do_batch_delete([attr for attr in attrs if attr.access(accessing_obj, self._attredit, - default=default_access)]) + self.do_batch_delete( + [ + attr + for attr in attrs + if attr.access(accessing_obj, self._attredit, default=default_access) + ] + ) else: # have to cast the results to a list or we'll get a RuntimeError for removing from the dict we're iterating self.do_batch_delete(list(attrs)) @@ -765,7 +777,9 @@ class InMemoryAttributeBackend(IAttributeBackend): strvalue has no meaning for InMemory attributes. """ - new_attr = self._attrclass(pk=self._next_id(), key=key, category=category, lock_storage=lockstring, value=value) + new_attr = self._attrclass( + pk=self._next_id(), key=key, category=category, lock_storage=lockstring, value=value + ) self._storage[(key, category)] = new_attr self._category_storage[category].append(new_attr) return new_attr @@ -805,6 +819,7 @@ class ModelAttributeBackend(IAttributeBackend): """ Uses Django models for storing Attributes. """ + _attrclass = Attribute _m2m_fieldname = "db_attributes" @@ -844,9 +859,7 @@ class ModelAttributeBackend(IAttributeBackend): } return [ conn.attribute - for conn in getattr(self.obj, self._m2m_fieldname).through.objects.filter( - **query - ) + for conn in getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query) ] def do_create_attribute(self, key, category, lockstring, value, strvalue): @@ -855,7 +868,7 @@ class ModelAttributeBackend(IAttributeBackend): "db_category": category, "db_model": self._model, "db_lock_storage": lockstring if lockstring else "", - "db_attrtype": self._attrtype + "db_attrtype": self._attrtype, } if strvalue: kwargs["db_value"] = None @@ -901,6 +914,7 @@ class AttributeHandler: """ Handler for adding Attributes to the object. """ + _attrcreate = "attrcreate" _attredit = "attredit" _attrread = "attrread" diff --git a/evennia/typeclasses/managers.py b/evennia/typeclasses/managers.py index 092a8eba6c..9e14a4870e 100644 --- a/evennia/typeclasses/managers.py +++ b/evennia/typeclasses/managers.py @@ -31,14 +31,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): # Attribute manager methods def get_attribute( - self, - key=None, - category=None, - value=None, - strvalue=None, - obj=None, - attrtype=None, - **kwargs + self, key=None, category=None, value=None, strvalue=None, obj=None, attrtype=None, **kwargs ): """ Return Attribute objects by key, by category, by value, by @@ -82,9 +75,9 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): # no reason to make strvalue/value mutually exclusive at this level query.append(("attribute__db_value", value)) return Attribute.objects.filter( - pk__in=self.model.db_attributes.through.objects.filter( - **dict(query) - ).values_list("attribute_id", flat=True) + pk__in=self.model.db_attributes.through.objects.filter(**dict(query)).values_list( + "attribute_id", flat=True + ) ) def get_nick(self, key=None, category=None, value=None, strvalue=None, obj=None): @@ -111,13 +104,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): ) def get_by_attribute( - self, - key=None, - category=None, - value=None, - strvalue=None, - attrtype=None, - **kwargs + self, key=None, category=None, value=None, strvalue=None, attrtype=None, **kwargs ): """ Return objects having attributes with the given key, category, @@ -174,15 +161,11 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): obj (list): Objects having the matching Nicks. """ - return self.get_by_attribute( - key=key, category=category, strvalue=nick, attrtype="nick" - ) + return self.get_by_attribute(key=key, category=category, strvalue=nick, attrtype="nick") # Tag manager methods - def get_tag( - self, key=None, category=None, obj=None, tagtype=None, global_search=False - ): + def get_tag(self, key=None, category=None, obj=None, tagtype=None, global_search=False): """ Return Tag objects by key, by category, by object (it is stored on) or with a combination of those criteria. @@ -226,9 +209,9 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): if category: query.append(("tag__db_category", category)) return Tag.objects.filter( - pk__in=self.model.db_tags.through.objects.filter( - **dict(query) - ).values_list("tag_id", flat=True) + pk__in=self.model.db_tags.through.objects.filter(**dict(query)).values_list( + "tag_id", flat=True + ) ) def get_permission(self, key=None, category=None, obj=None): @@ -310,9 +293,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): dbmodel = self.model.__dbclass__.__name__.lower() query = ( - self.filter( - db_tags__db_tagtype__iexact=tagtype, db_tags__db_model__iexact=dbmodel - ) + self.filter(db_tags__db_tagtype__iexact=tagtype, db_tags__db_model__iexact=dbmodel) .distinct() .order_by("id") ) @@ -332,9 +313,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): clauses = Q() for ikey, key in enumerate(keys): # ANY mode; must match any one of the given tags/categories - clauses |= Q( - db_key__iexact=key, db_category__iexact=categories[ikey] - ) + clauses |= Q(db_key__iexact=key, db_category__iexact=categories[ikey]) else: # only one or more categories given clauses = Q() @@ -344,8 +323,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): tags = _Tag.objects.filter(clauses) query = query.filter(db_tags__in=tags).annotate( - matches=Count("db_tags__pk", filter=Q(db_tags__in=tags), - distinct=True) + matches=Count("db_tags__pk", filter=Q(db_tags__in=tags), distinct=True) ) if anymatch: @@ -412,9 +390,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): # try to get old tag dbmodel = self.model.__dbclass__.__name__.lower() - tag = self.get_tag( - key=key, category=category, tagtype=tagtype, global_search=True - ) + tag = self.get_tag(key=key, category=category, tagtype=tagtype, global_search=True) if tag and data is not None: # get tag from list returned by get_tag tag = tag[0] @@ -428,9 +404,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): from evennia.typeclasses.models import Tag as _Tag tag = _Tag.objects.create( db_key=key.strip().lower() if key is not None else None, - db_category=category.strip().lower() - if category and key is not None - else None, + db_category=category.strip().lower() if category and key is not None else None, db_data=data, db_model=dbmodel, db_tagtype=tagtype.strip().lower() if tagtype is not None else None, @@ -539,8 +513,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): typeclass=F("db_typeclass_path"), # Calculate this class' percentage of total composition percent=ExpressionWrapper( - ((F("count") / float(self.count())) * 100.0), - output_field=FloatField(), + ((F("count") / float(self.count())) * 100.0), output_field=FloatField(), ), ) .values("typeclass", "count", "percent") @@ -560,9 +533,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): stats = self.get_typeclass_totals().order_by("typeclass") return {x.get("typeclass"): x.get("count") for x in stats} - def typeclass_search( - self, typeclass, include_children=False, include_parents=False - ): + def typeclass_search(self, typeclass, include_children=False, include_parents=False): """ Searches through all objects returning those which has a certain typeclass. If location is set, limit search to objects @@ -837,8 +808,7 @@ class TypeclassManager(TypedObjectManager): """ paths = [self.model.path] + [ - "%s.%s" % (cls.__module__, cls.__name__) - for cls in self._get_subclasses(self.model) + "%s.%s" % (cls.__module__, cls.__name__) for cls in self._get_subclasses(self.model) ] kwargs.update({"db_typeclass_path__in": paths}) return super().get(**kwargs) @@ -860,8 +830,7 @@ class TypeclassManager(TypedObjectManager): """ # query, including all subclasses paths = [self.model.path] + [ - "%s.%s" % (cls.__module__, cls.__name__) - for cls in self._get_subclasses(self.model) + "%s.%s" % (cls.__module__, cls.__name__) for cls in self._get_subclasses(self.model) ] kwargs.update({"db_typeclass_path__in": paths}) return super().filter(*args, **kwargs) @@ -876,7 +845,6 @@ class TypeclassManager(TypedObjectManager): """ paths = [self.model.path] + [ - "%s.%s" % (cls.__module__, cls.__name__) - for cls in self._get_subclasses(self.model) + "%s.%s" % (cls.__module__, cls.__name__) for cls in self._get_subclasses(self.model) ] return super().all().filter(db_typeclass_path__in=paths) diff --git a/evennia/typeclasses/models.py b/evennia/typeclasses/models.py index 84ec1dd408..dbc2c970a8 100644 --- a/evennia/typeclasses/models.py +++ b/evennia/typeclasses/models.py @@ -36,7 +36,12 @@ from django.urls import reverse from django.utils.encoding import smart_str from django.utils.text import slugify -from evennia.typeclasses.attributes import Attribute, AttributeHandler, ModelAttributeBackend, InMemoryAttributeBackend +from evennia.typeclasses.attributes import ( + Attribute, + AttributeHandler, + ModelAttributeBackend, + InMemoryAttributeBackend, +) from evennia.typeclasses.attributes import DbHolder from evennia.typeclasses.tags import Tag, TagHandler, AliasHandler, PermissionHandler @@ -122,6 +127,7 @@ class TypeclassBase(SharedMemoryModelBase): signals.pre_delete.connect(remove_attributes_on_delete, sender=new_class) return new_class + # # Main TypedObject abstraction # diff --git a/evennia/typeclasses/tests.py b/evennia/typeclasses/tests.py index 93b100f87b..3818d3028b 100644 --- a/evennia/typeclasses/tests.py +++ b/evennia/typeclasses/tests.py @@ -58,16 +58,12 @@ class TestTypedObjectManager(EvenniaTest): self.obj2.tags.add("tag4") self.obj2.tags.add("tag2c") self.assertEqual(self._manager("get_by_tag", "tag1"), [self.obj1]) - self.assertEqual( - set(self._manager("get_by_tag", "tag2")), set([self.obj1, self.obj2]) - ) + self.assertEqual(set(self._manager("get_by_tag", "tag2")), set([self.obj1, self.obj2])) self.assertEqual(self._manager("get_by_tag", "tag2a"), [self.obj2]) self.assertEqual(self._manager("get_by_tag", "tag3 with spaces"), [self.obj2]) self.assertEqual(self._manager("get_by_tag", ["tag2a", "tag2b"]), [self.obj2]) self.assertEqual(self._manager("get_by_tag", ["tag2a", "tag1"]), []) - self.assertEqual( - self._manager("get_by_tag", ["tag2a", "tag4", "tag2c"]), [self.obj2] - ) + self.assertEqual(self._manager("get_by_tag", ["tag2a", "tag4", "tag2c"]), [self.obj2]) def test_get_by_tag_and_category(self): self.obj1.tags.add("tag5", "category1") @@ -83,24 +79,17 @@ class TestTypedObjectManager(EvenniaTest): self.obj1.tags.add("tag8", "category6") self.obj2.tags.add("tag9", "category6") - self.assertEqual( - self._manager("get_by_tag", "tag5", "category1"), [self.obj1, self.obj2] - ) + self.assertEqual(self._manager("get_by_tag", "tag5", "category1"), [self.obj1, self.obj2]) self.assertEqual(self._manager("get_by_tag", "tag6", "category1"), []) - self.assertEqual( - self._manager("get_by_tag", "tag6", "category3"), [self.obj1, self.obj2] - ) + self.assertEqual(self._manager("get_by_tag", "tag6", "category3"), [self.obj1, self.obj2]) self.assertEqual( self._manager("get_by_tag", ["tag5", "tag6"], ["category1", "category3"]), [self.obj1, self.obj2], ) self.assertEqual( - self._manager("get_by_tag", ["tag5", "tag7"], "category1"), - [self.obj1, self.obj2], - ) - self.assertEqual( - self._manager("get_by_tag", category="category1"), [self.obj1, self.obj2] + self._manager("get_by_tag", ["tag5", "tag7"], "category1"), [self.obj1, self.obj2], ) + self.assertEqual(self._manager("get_by_tag", category="category1"), [self.obj1, self.obj2]) self.assertEqual(self._manager("get_by_tag", category="category2"), [self.obj2]) self.assertEqual( self._manager("get_by_tag", category=["category1", "category3"]), @@ -110,39 +99,27 @@ class TestTypedObjectManager(EvenniaTest): self._manager("get_by_tag", category=["category1", "category2"]), [self.obj1, self.obj2], ) - self.assertEqual( - self._manager("get_by_tag", category=["category5", "category4"]), [] - ) - self.assertEqual( - self._manager("get_by_tag", category="category1"), [self.obj1, self.obj2] - ) - self.assertEqual( - self._manager("get_by_tag", category="category6"), [self.obj1, self.obj2] - ) + self.assertEqual(self._manager("get_by_tag", category=["category5", "category4"]), []) + self.assertEqual(self._manager("get_by_tag", category="category1"), [self.obj1, self.obj2]) + self.assertEqual(self._manager("get_by_tag", category="category6"), [self.obj1, self.obj2]) def test_get_tag_with_all(self): self.obj1.tags.add("tagA", "categoryA") self.assertEqual( - self._manager( - "get_by_tag", ["tagA", "tagB"], ["categoryA", "categoryB"], match="all" - ), + self._manager("get_by_tag", ["tagA", "tagB"], ["categoryA", "categoryB"], match="all"), [], ) def test_get_tag_with_any(self): self.obj1.tags.add("tagA", "categoryA") self.assertEqual( - self._manager( - "get_by_tag", ["tagA", "tagB"], ["categoryA", "categoryB"], match="any" - ), + self._manager("get_by_tag", ["tagA", "tagB"], ["categoryA", "categoryB"], match="any"), [self.obj1], ) def test_get_tag_withnomatch(self): self.obj1.tags.add("tagC", "categoryC") self.assertEqual( - self._manager( - "get_by_tag", ["tagA", "tagB"], ["categoryA", "categoryB"], match="any" - ), + self._manager("get_by_tag", ["tagA", "tagB"], ["categoryA", "categoryB"], match="any"), [], ) diff --git a/evennia/utils/test_resources.py b/evennia/utils/test_resources.py index 606927e524..d128302a71 100644 --- a/evennia/utils/test_resources.py +++ b/evennia/utils/test_resources.py @@ -158,11 +158,13 @@ class EvenniaTest(TestCase): self.account2.delete() super().tearDown() + class LocalEvenniaTest(EvenniaTest): """ This test class is intended for inheriting in mygame tests. It helps ensure your tests are run with your own objects. """ + account_typeclass = settings.BASE_ACCOUNT_TYPECLASS object_typeclass = settings.BASE_OBJECT_TYPECLASS character_typeclass = settings.BASE_CHARACTER_TYPECLASS