Best Python code snippet using tempest_python
items.py
Source:items.py
1# Standard library imports 2from dataclasses import dataclass3from typing import Optional4from abc import ABC5# Local application imports6import entities.slots as slots7@dataclass(frozen=True)8class BaseItem(ABC):9 name: str = ''10 worth: int = 011 weight: int = 012 slot_type: slots.Slot = slots.Miscellaneous13 description: Optional[str] = None14 def __init__(self, *args, **kwargs):15 if type(self) == BaseItem:16 raise NotImplementedError('Do not instantiate BaseItem directly')17# Weapons18@dataclass(frozen=True)19class Weapon(BaseItem):20 damage: int = 021 def __init__(self, *args, **kwargs):22 if type(self) == Weapon:23 raise NotImplementedError('Do not instantiate Weapon directly')24# One Handed Weapons25@dataclass(frozen=True)26class OneHandedWeapon(Weapon):27 slot_type: slots.Slot = slots.OneHanded28 def __init__(self, *args, **kwargs):29 if type(self) == OneHandedWeapon:30 raise NotImplementedError('Do not instantiate OneHandedWeapon directly')31@dataclass(frozen=True)32class Rock(OneHandedWeapon):33 name: str = 'Rock'34 worth: int = 135 weight: int = 136 damage: int = 537@dataclass(frozen=True)38class Dagger(OneHandedWeapon):39 name: str = 'Dagger'40 worth: int = 20041 weight: int = 142 damage: int = 543@dataclass(frozen=True)44class Sword(OneHandedWeapon):45 name: str = 'Sword'46 worth: int = 50047 weight: int = 148 damage: int = 549# Two Handed Weapons50@dataclass(frozen=True)51class TwoHandedWeapon(Weapon):52 slot_type: slots.Slot = slots.TwoHanded53 def __init__(self, *args, **kwargs):54 if type(self) == TwoHandedWeapon:55 raise NotImplementedError('Do not instantiate TwoHandedWeapon directly')56@dataclass(frozen=True)57class Crossbow(TwoHandedWeapon):58 name: str = 'Crossbow'59 worth: int = 75060 weight: int = 261 damage: int = 1562@dataclass(frozen=True)63class Axe(TwoHandedWeapon):64 name: str = 'Axe'65 worth: int = 60066 weight: int = 267 damage: int = 2568# Consumables/Healing69@dataclass(frozen=True)70class Consumable(BaseItem):71 healing_value: int = 072 def __init__(self, *args, **kwargs):73 if type(self) == Consumable:74 raise NotImplementedError('Do not instantiate Consumable directly')75@dataclass(frozen=True)76class Bread(Consumable):77 name: str = 'Bread'78 worth: int = 1279 weight: int = 180 description: str = 'Cursty'81 healing_value: int = 1082@dataclass(frozen=True)83class HealingPotion(Consumable):84 name: str = 'Healing Potion'85 worth: int = 60086 weight: int = 187 healing_value: int = 5088# Containers89# class Container(BaseItem):90# def __init__(self, update_limit=tuple(), **kwargs):91# self.update_limit = update_limit92# super().__init__(**kwargs)93# if type(self) == Container:94# raise NotImplementedError('Do not instantiate Container directly')95 96# def updateSlotLimit(self, slots, amount=1, negative=False):97# for slot_type in slots.__dict__.values():98# # checks if self.update_limit is an emputy list99# if not self.update_limit: return False100# if not isinstance(slot_type, self.update_limit[0]): continue101# if negative:102# slot_type.item_limit = slot_type.item_limit - self.update_limit[1] * amount103# return True104# else:105# slot_type.item_limit = slot_type.item_limit + self.update_limit[1] * amount106# return True107 108# class Backpack(Container, BaseItem):109# def __init__(self, name='Backpack', worth=10, weight=1, 110# slot_type=slots.Body().name, update_limit=(slots.SmallItem, 8), **kwargs):111# super().__init__(name=name, worth=worth, weight=weight, 112# slot_type=slot_type, update_limit=update_limit, **kwargs)113 114# class CoinPouch(Container, BaseItem):115# def __init__(self, name='Coin Pouch', worth=1, weight=.1, 116# slot_type=slots.SmallItem().name, update_limit=(slots.Coins, 50), **kwargs):117# super().__init__(name=name, worth=worth, weight=weight, ...
gups_generator_par.py
Source:gups_generator_par.py
1# Copyright (c) 2021 The Regents of the University of California2# All rights reserved.3#4# Redistribution and use in source and binary forms, with or without5# modification, are permitted provided that the following conditions are6# met: redistributions of source code must retain the above copyright7# notice, this list of conditions and the following disclaimer;8# redistributions in binary form must reproduce the above copyright9# notice, this list of conditions and the following disclaimer in the10# documentation and/or other materials provided with the distribution;11# neither the name of the copyright holders nor the names of its12# contributors may be used to endorse or promote products derived from13# this software without specific prior written permission.14#15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26from typing import Optional27from m5.objects import Addr28from ...utils.override import overrides29from ..boards.mem_mode import MemMode30from .abstract_processor import AbstractProcessor31from ..boards.abstract_board import AbstractBoard32from .gups_generator_core import GUPSGeneratorCore33class GUPSGeneratorPAR(AbstractProcessor):34 def __init__(35 self,36 num_cores: int,37 start_addr: Addr,38 mem_size: str,39 update_limit: int = 0,40 clk_freq: Optional[str] = None,41 ):42 """The GUPSGeneratorPAR class43 This class defines the interface for multi core GUPSGenerator, this44 generator could be used in place of a processor. In terms of45 benchmarking this generator implements the parallel (3rd)46 variant of the GUPS benchmark as specified by HPCC website.47 :param start_addr: The start address for allocating the update table.48 :param mem_size: The size of memory to allocate for the update table.49 Should be a power of 2.50 :param update_limit: The number of updates to do before terminating51 simulation. Pass zero to run the benchmark to completion (The amount of52 time it takes to simulate depends on )53 """54 super().__init__(55 cores=self._create_cores(56 num_cores=num_cores,57 start_addr=start_addr,58 mem_size=mem_size,59 update_limit=update_limit,60 clk_freq=clk_freq,61 )62 )63 def _create_cores(64 self,65 num_cores: int,66 start_addr: Addr,67 mem_size: str,68 update_limit: int,69 clk_freq: Optional[str],70 ):71 """72 Helper function to create cores.73 """74 return [75 GUPSGeneratorCore(76 start_addr=start_addr,77 mem_size=mem_size,78 update_limit=update_limit / num_cores,79 clk_freq=clk_freq,80 )81 for _ in range(num_cores)82 ]83 @overrides(AbstractProcessor)84 def incorporate_processor(self, board: AbstractBoard) -> None:85 board.set_mem_mode(MemMode.TIMING)86 def start_traffic(self):87 # This function should be implemented so that GUPSGeneratorPAR could be88 # used in the same scripts that use LinearGenerator, RandomGenerator,89 # and ComplexGenrator...
dump-field-limits.py
Source:dump-field-limits.py
...36 ,"protein_sequence":{"min":10000000000, "max":-1}37 }38 39 for doc in db["c_glycan"].find({}):40 update_limit(limit_obj["glytoucan_ac"], len(doc["glytoucan_ac"]))41 for o in doc["motifs"]:42 update_limit(limit_obj["motif_name"], len(o["name"]))43 for doc in db["c_protein"].find({}):44 update_limit(limit_obj["uniprot_canonical_ac"], len(doc["uniprot_canonical_ac"]))45 update_limit(limit_obj["uniprot_id"], len(doc["uniprot_id"]))46 if "ac" in doc["refseq"]:47 update_limit(limit_obj["refseq_ac"], len(doc["refseq"]["ac"]))48 if "full" in doc["recommendedname"]:49 update_limit(limit_obj["protein_name"], len(doc["recommendedname"]["full"]))50 for o in doc["pathway"]:51 update_limit(limit_obj["pathway_name"], len(o["name"]))52 update_limit(limit_obj["pathway_id"], len(o["id"]))53 for o in doc["disease"]:54 update_limit(limit_obj["disease_name"], len(o["name"]))55 for o in doc["gene"]:56 update_limit(limit_obj["gene_name"], len(o["name"]))57 for o in doc["isoforms"]: 58 update_limit(limit_obj["protein_sequence"], len(o["sequence"]["sequence"]))59 limit_obj["enzyme_uniprot_canonical_ac"] = limit_obj["uniprot_canonical_ac"]60 print json.dumps(limit_obj, indent=4)61if __name__ == '__main__':...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!