Run black on sources

This commit is contained in:
Griatch 2024-06-27 16:01:09 +02:00
parent 9ca41b5d0d
commit 9c3ba936e4
27 changed files with 153 additions and 90 deletions

View file

@ -15,16 +15,17 @@ class BaseComponent(type):
This is the metaclass for components,
responsible for registering components to the listing.
"""
def __new__(cls, name, parents, attrs):
"""
Every class that uses this metaclass will be registered
as a component in the Component Listing using its name.
All of them require a unique name.
"""
attrs_name = attrs.get('name')
attrs_name = attrs.get("name")
if attrs_name and not COMPONENT_LISTING.get(attrs_name):
new_fields = {}
attrs['_fields'] = new_fields
attrs["_fields"] = new_fields
for parent in parents:
_parent_fields = getattr(parent, "_fields")
if _parent_fields:

View file

@ -87,23 +87,23 @@ class TestComponents(EvenniaTest):
def test_character_components_set_fields_properly(self):
test_a_fields = self.char1.test_a._fields
self.assertIn('my_int', test_a_fields)
self.assertIn('my_list', test_a_fields)
self.assertIn("my_int", test_a_fields)
self.assertIn("my_list", test_a_fields)
self.assertEqual(len(test_a_fields), 2)
test_b_fields = self.char1.test_b._fields
self.assertIn('my_int', test_b_fields)
self.assertIn('my_list', test_b_fields)
self.assertIn('default_tag', test_b_fields)
self.assertIn('single_tag', test_b_fields)
self.assertIn('multiple_tags', test_b_fields)
self.assertIn('default_single_tag', test_b_fields)
self.assertIn("my_int", test_b_fields)
self.assertIn("my_list", test_b_fields)
self.assertIn("default_tag", test_b_fields)
self.assertIn("single_tag", test_b_fields)
self.assertIn("multiple_tags", test_b_fields)
self.assertIn("default_single_tag", test_b_fields)
self.assertEqual(len(test_b_fields), 6)
test_ic_a_fields = self.char1.ic_a._fields
self.assertIn('my_int', test_ic_a_fields)
self.assertIn('my_list', test_ic_a_fields)
self.assertIn('my_other_int', test_ic_a_fields)
self.assertIn("my_int", test_ic_a_fields)
self.assertIn("my_list", test_ic_a_fields)
self.assertIn("my_other_int", test_ic_a_fields)
self.assertEqual(len(test_ic_a_fields), 3)
def test_inherited_typeclass_does_not_include_child_class_components(self):

View file

@ -1,8 +1,8 @@
from .achievements import (
get_achievement,
search_achievement,
all_achievements,
track_achievements,
get_achievement_progress,
CmdAchieve,
all_achievements,
get_achievement,
get_achievement_progress,
search_achievement,
track_achievements,
)

View file

@ -50,11 +50,18 @@ Example:
"""
from collections import Counter
from django.conf import settings
from evennia.utils import logger
from evennia.utils.utils import all_from_module, is_iter, make_iter, string_partial_matching
from evennia.utils.evmore import EvMore
from evennia.commands.default.muxcommand import MuxCommand
from evennia.utils import logger
from evennia.utils.evmore import EvMore
from evennia.utils.utils import (
all_from_module,
is_iter,
make_iter,
string_partial_matching,
)
# this is either a string of the attribute name, or a tuple of strings of the attribute name and category
_ACHIEVEMENT_ATTR = make_iter(getattr(settings, "ACHIEVEMENT_CONTRIB_ATTRIBUTE", "achievements"))
@ -322,12 +329,12 @@ class CmdAchieve(MuxCommand):
elif not achievement_data.get("progress"):
status = "|yNot Started|n"
else:
count = achievement_data.get("count",1)
count = achievement_data.get("count", 1)
# is this achievement tracking items separately?
if is_iter(achievement_data["progress"]):
# we'll display progress as how many items have been completed
completed = Counter(val >= count for val in achievement_data["progress"])[True]
pct = (completed * 100) // len(achievement_data['progress'])
pct = (completed * 100) // len(achievement_data["progress"])
else:
# we display progress as the percent of the total count
pct = (achievement_data["progress"] * 100) // count
@ -379,8 +386,7 @@ class CmdAchieve(MuxCommand):
elif "all" in self.switches:
# we merge our progress data into the full dict of achievements
achievement_data = {
key: data | progress_data.get(key, {})
for key, data in achievements.items()
key: data | progress_data.get(key, {}) for key, data in achievements.items()
}
# we show all of the currently available achievements regardless of progress status

View file

@ -1,5 +1,7 @@
from evennia.utils.test_resources import BaseEvenniaTest, BaseEvenniaCommandTest
from mock import patch
from evennia.utils.test_resources import BaseEvenniaCommandTest, BaseEvenniaTest
from . import achievements
_dummy_achievements = {

View file

@ -47,8 +47,17 @@ from collections import deque
from django.conf import settings
from django.db.models import Q
from evennia import (CmdSet, DefaultRoom, EvEditor, FuncParser,
InterruptCommand, default_cmds, gametime, utils)
from evennia import (
CmdSet,
DefaultRoom,
EvEditor,
FuncParser,
InterruptCommand,
default_cmds,
gametime,
utils,
)
from evennia.typeclasses.attributes import AttributeProperty
from evennia.utils.utils import list_to_string, repeat

View file

@ -22,9 +22,9 @@ from random import choices
from django.conf import settings
from evennia import DefaultAccount
from evennia.commands.default.muxcommand import MuxAccountCommand
from evennia.commands.default.account import CmdIC
from evennia.commands.cmdset import CmdSet
from evennia.commands.default.account import CmdIC
from evennia.commands.default.muxcommand import MuxAccountCommand
from evennia.objects.models import ObjectDB
from evennia.utils.evmenu import EvMenu
from evennia.utils.utils import is_iter, string_partial_matching