From 5d9fde949d1a37b63164ae1f5a60cffc9ac49ec1 Mon Sep 17 00:00:00 2001 From: evilchili Date: Wed, 21 Aug 2024 14:14:37 -0700 Subject: [PATCH] resolve warnings --- src/ttfrog/db/manager.py | 3 ++- src/ttfrog/db/schema/item.py | 20 ++++++++++++++++++-- test/test_bootstrap.py | 2 +- test/test_inventories.py | 2 -- test/test_items.py | 8 +++----- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/ttfrog/db/manager.py b/src/ttfrog/db/manager.py index 119d4e8..48ff9ee 100644 --- a/src/ttfrog/db/manager.py +++ b/src/ttfrog/db/manager.py @@ -75,8 +75,9 @@ class SQLDatabaseManager: return base64.urlsafe_b64encode(sha1bytes.digest()).decode("ascii")[:10] def init(self): - self.session.configure(bind=self.engine) self.metadata.bind = self.engine + self.session.remove() + self.session.configure(bind=self.engine) self.metadata.create_all(self.engine) def dump(self, names: list = []): diff --git a/src/ttfrog/db/schema/item.py b/src/ttfrog/db/schema/item.py index 557a502..5aa3ab8 100644 --- a/src/ttfrog/db/schema/item.py +++ b/src/ttfrog/db/schema/item.py @@ -53,18 +53,20 @@ class Spell(Item): __tablename__ = "spell" __mapper_args__ = {"polymorphic_identity": ItemType.SPELL} id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True, init=False) + item_type: Mapped[ItemType] = ItemType.SPELL + level: Mapped[int] = mapped_column(nullable=False, info={"min": 0, "max": 9}, default=0) concentration: Mapped[bool] = mapped_column(default=False) - item_type: Mapped[ItemType] = mapped_column(default=ItemType.SPELL, init=False) class Weapon(Item): __tablename__ = "weapon" __mapper_args__ = {"polymorphic_identity": ItemType.WEAPON} id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True, init=False) + item_type: Mapped[ItemType] = ItemType.WEAPON + damage_die: Mapped[str] = mapped_column(nullable=False, default="1d6") damage_type: Mapped[DamageType] = mapped_column(nullable=False, default=DamageType.slashing) - item_type: Mapped[ItemType] = mapped_column(default=ItemType.WEAPON) attack_range: Mapped[int] = mapped_column(nullable=False, info={"min": 0}, default=0) attack_range_long: Mapped[int] = mapped_column(nullable=True, info={"min": 0}, default=None) targets: Mapped[int] = mapped_column(nullable=False, info={"min": 1}, default=1) @@ -85,3 +87,17 @@ class Weapon(Item): @property def ranged(self): return self.attack_range > 0 + + +class Shield(Item): + __tablename__ = "shield" + __mapper_args__ = {"polymorphic_identity": ItemType.SHIELD} + id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True, init=False) + item_type: Mapped[ItemType] = ItemType.SHIELD + + +class Armor(Item): + __tablename__ = "armor" + __mapper_args__ = {"polymorphic_identity": ItemType.ARMOR} + id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True, init=False) + item_type: Mapped[ItemType] = ItemType.ARMOR diff --git a/test/test_bootstrap.py b/test/test_bootstrap.py index fbdafc1..120f9a0 100644 --- a/test/test_bootstrap.py +++ b/test/test_bootstrap.py @@ -9,7 +9,7 @@ def test_dump_load(db, bootstrap): # clear the database and reinitialize db.metadata.drop_all(bind=db.engine) - db.init() + db.metadata.create_all(db.engine) # load the dump db.load(data) diff --git a/test/test_inventories.py b/test/test_inventories.py index 6ad1041..08f343b 100644 --- a/test/test_inventories.py +++ b/test/test_inventories.py @@ -96,8 +96,6 @@ def test_spell_slots(db, carl, wizard): db.add_or_update(carl) # verify carl has the spell slots granted by wizard at 1st level - print(carl.levels) - print(carl.spell_slots) assert len(carl.spell_slots) == 2 assert carl.spell_slots[0].spell_level == 1 assert carl.spell_slots[1].spell_level == 1 diff --git a/test/test_items.py b/test/test_items.py index fe12130..4fd8cc0 100644 --- a/test/test_items.py +++ b/test/test_items.py @@ -1,5 +1,5 @@ from ttfrog.db.schema.constants import DamageType, Defenses -from ttfrog.db.schema.item import Item, ItemType, Rarity, Weapon +from ttfrog.db.schema.item import Armor, Rarity, Shield, Weapon from ttfrog.db.schema.modifiers import Modifier @@ -42,14 +42,13 @@ def test_weapons(db): def test_attunement(db, carl): with db.transaction(): - helm = Item( + helm = Armor( name="Iron Helm", - item_type=ItemType.ARMOR, rarity=Rarity.Common, ) helm.add_modifier(Modifier("+1 AC (helmet)", target="armor_class", relative_value=1, stacks=True)) - shield = Item( + shield = Shield( name="Shield of Missile Attraction", description=""" While holding this shield, you have resistance to damage from ranged weapon attacks. @@ -58,7 +57,6 @@ def test_attunement(db, carl): or similar magic. Removing the shield fails to end the curse on you. Whenever a ranged weapon attack is made against a target within 10 feet of you, the curse causes you to become the target instead. """, - item_type=ItemType.SHIELD, rarity=Rarity.Rare, requires_attunement=True, )