From 80b3a5b1d49141d1cbb7953cb5e2feab5c4a4bf6 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Thu, 6 Jan 2022 06:09:15 +0100 Subject: [PATCH] WebHost: fix is_zipfile check for flask FileStorage objects - and assorted cleanup --- BaseClasses.py | 5 ++--- WebHostLib/upload.py | 2 +- test/TestBase.py | 1 + test/base/__init__.py | 0 test/{base => general}/TestFill.py | 10 +++++----- test/minor_glitches/TestMinor.py | 10 ++++++---- worlds/hk/__init__.py | 4 ---- 7 files changed, 15 insertions(+), 17 deletions(-) delete mode 100644 test/base/__init__.py rename test/{base => general}/TestFill.py (98%) diff --git a/BaseClasses.py b/BaseClasses.py index bbf110d2..13e74d13 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -782,10 +782,9 @@ class RegionType(int, Enum): class Region(object): - - def __init__(self, name: str, type: str, hint, player: int, world: Optional[MultiWorld] = None): + def __init__(self, name: str, type_: RegionType, hint, player: int, world: Optional[MultiWorld] = None): self.name = name - self.type = type + self.type = type_ self.entrances = [] self.exits = [] self.locations = [] diff --git a/WebHostLib/upload.py b/WebHostLib/upload.py index cdd7e315..607b0aff 100644 --- a/WebHostLib/upload.py +++ b/WebHostLib/upload.py @@ -100,7 +100,7 @@ def uploads(): if file.filename == '': flash('No selected file') elif file and allowed_file(file.filename): - if zipfile.is_zipfile(file.filename): + if zipfile.is_zipfile(file): with zipfile.ZipFile(file, 'r') as zfile: res = upload_zip_to_db(zfile) if type(res) == str: diff --git a/test/TestBase.py b/test/TestBase.py index 431aaa00..cf73cec2 100644 --- a/test/TestBase.py +++ b/test/TestBase.py @@ -9,6 +9,7 @@ Utils.local_path.cached_path = file_path from BaseClasses import MultiWorld, CollectionState from worlds.alttp.Items import ItemFactory + class TestBase(unittest.TestCase): world: MultiWorld _state_cache = {} diff --git a/test/base/__init__.py b/test/base/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/test/base/TestFill.py b/test/general/TestFill.py similarity index 98% rename from test/base/TestFill.py rename to test/general/TestFill.py index 38447b62..573a224f 100644 --- a/test/base/TestFill.py +++ b/test/general/TestFill.py @@ -1,4 +1,4 @@ -from typing import NamedTuple +from typing import NamedTuple, List import unittest from worlds.AutoWorld import World from Fill import FillError, fill_restrictive @@ -28,8 +28,8 @@ def generate_multi_world(players: int = 1) -> MultiWorld: class PlayerDefinition(NamedTuple): id: int menu: Region - locations: list[Location] - prog_items: list[Item] + locations: List[Location] + prog_items: List[Item] def generate_player_data(multi_world: MultiWorld, player_id: int, location_count: int, prog_item_count: int) -> PlayerDefinition: @@ -40,7 +40,7 @@ def generate_player_data(multi_world: MultiWorld, player_id: int, location_count return PlayerDefinition(player_id, menu, locations, prog_items) -def generate_locations(count: int, player_id: int, address: int = None, region: Region = None) -> list[Location]: +def generate_locations(count: int, player_id: int, address: int = None, region: Region = None) -> List[Location]: locations = [] for i in range(count): name = "player" + str(player_id) + "_location" + str(i) @@ -50,7 +50,7 @@ def generate_locations(count: int, player_id: int, address: int = None, region: return locations -def generate_items(count: int, player_id: int, advancement: bool = False, code: int = None) -> list[Location]: +def generate_items(count: int, player_id: int, advancement: bool = False, code: int = None) -> List[Item]: items = [] for i in range(count): name = "player" + str(player_id) + "_item" + str(i) diff --git a/test/minor_glitches/TestMinor.py b/test/minor_glitches/TestMinor.py index ac277205..db77ee91 100644 --- a/test/minor_glitches/TestMinor.py +++ b/test/minor_glitches/TestMinor.py @@ -4,15 +4,15 @@ from BaseClasses import MultiWorld from worlds.alttp.Dungeons import create_dungeons, get_dungeon_item_pool from worlds.alttp.EntranceShuffle import link_entrances from worlds.alttp.InvertedRegions import mark_dark_world_regions -from worlds.alttp.ItemPool import difficulties, generate_itempool +from worlds.alttp.ItemPool import difficulties from worlds.alttp.Items import ItemFactory from worlds.alttp.Regions import create_regions from worlds.alttp.Shops import create_shops -from worlds.alttp.Rules import set_rules from test.TestBase import TestBase from worlds import AutoWorld + class TestMinor(TestBase): def setUp(self): self.world = MultiWorld(1) @@ -30,8 +30,10 @@ class TestMinor(TestBase): self.world.worlds[1].create_items() self.world.required_medallions[1] = ['Ether', 'Quake'] self.world.itempool.extend(get_dungeon_item_pool(self.world)) - self.world.itempool.extend(ItemFactory(['Green Pendant', 'Red Pendant', 'Blue Pendant', 'Beat Agahnim 1', 'Beat Agahnim 2', 'Crystal 1', 'Crystal 2', 'Crystal 3', 'Crystal 4', 'Crystal 5', 'Crystal 6', 'Crystal 7'], 1)) + self.world.itempool.extend(ItemFactory( + ['Green Pendant', 'Red Pendant', 'Blue Pendant', 'Beat Agahnim 1', 'Beat Agahnim 2', 'Crystal 1', + 'Crystal 2', 'Crystal 3', 'Crystal 4', 'Crystal 5', 'Crystal 6', 'Crystal 7'], 1)) self.world.get_location('Agahnim 1', 1).item = None self.world.get_location('Agahnim 2', 1).item = None mark_dark_world_regions(self.world, 1) - self.world.worlds[1].set_rules() \ No newline at end of file + self.world.worlds[1].set_rules() diff --git a/worlds/hk/__init__.py b/worlds/hk/__init__.py index 046ee6ea..1826ba93 100644 --- a/worlds/hk/__init__.py +++ b/worlds/hk/__init__.py @@ -68,16 +68,12 @@ class HKWorld(World): self.world.itempool += pool - def set_rules(self): set_rules(self.world, self.player) def create_regions(self): create_regions(self.world, self.player) - def generate_output(self): - pass # Hollow Knight needs no output files - def fill_slot_data(self): slot_data = {} for option_name in self.options: