How to use forced method in hypothesis

Best Python code snippet using hypothesis

player.py

Source:player.py Github

copy

Full Screen

1#!/usr/bin/env python32# -*- coding:utf-8 -*-3from game.define.store_define import TN_P_PLAYER4from store.store import StoreObj5from game import Game6import config7class ModelPlayer(StoreObj):8 """玩家数据"""9 TABLE_NAME = TN_P_PLAYER10 def init(self):11 self.id = None # rid12 self.account = '' #账号13 self.password = '' #密码14 self.gm = 0 if int(config.serverNo) >= 60000 else 1 #是否gm 先默认都是GM15 self.newTime = 0 # 创建时间16 self.loginTime = 0 # 最后一次登录时间17 self.logoutTime = 0 # 最后一次退出时间18 self.itemTranceNo = 0 #用于生成物品唯一id的自增值19 self.mailTranceNo = 0 #用于生成邮件唯一id的自增值20 self.petTranceNo = 0 # 用于生成宠物唯一id的自增值21 self.loginNum = 0 #角色历史登陆次数22 self.shutuped = False # 禁言23 self.blocked = False # 封号24 self.onlineTimeTotal = 0 # 累计在线时长25 self.channel = 0 # 玩家渠道26 self.platform = "" # android ios27 self.baseDict = {} #角色基础数据28 self.attrDict = {} # 角色属性29 self.historyDict = {} # 历史统计30 self.bagDict = {} # 角色背包31 self.walletDict = {} # 角色钱包32 self.rankDict = {} # 角色排行33 self.battleArrayDict = {} # 角色出战阵型34 self.mapDict = {} # 角色地图35 self.niudanDict = {} # 扭蛋36 self.chargeDict = {} # 充值37 self.chargeDailyDict = {} # 充值日常38 self.zhuanpanDict = {} # 转盘39 self.shopDict = {} # 商店40 self.rescueDict = {} # 救援队41 self.vipDict = {} # vip42 self.totemDict = {} # 图腾43 self.petDict = {} # 角色宠物44 self.marryDict = {} # 婚姻45 self.houseDict = {} # 房子46 self.examDict = {} # 答题47 self.bossDict = {} # boss 四合一48 self.chenghaoDict = {} # 称号49 self.myheadDict = {} # 头像50 self.relationshipDict = {} # 连协 羁绊 队伍加成51 self.daoguanDict = {} #道馆52 self.taskDict = {} # 任务53 self.fubenDict = {} #副本54 self.zhudaoxunliDict = {} #诸岛巡礼55 self.daylypvpDict = {} # 日常pvp抢夺56 self.hetiDict = {} #合体57 self.chatDict = {} #玩家聊天58 self.gongchengDict = {} #攻城59 self.guildDict = {} #公会60 self.yabiaoDict = {} #押镖61 self.diaoyuDict = {} #钓鱼62 def set_owner(self, owner):63 self.owner = owner64 def to_save_dict(self, copy=False, forced=False):65 save = {}66 save['id'] = self.id67 save['account'] = self.account68 save['password'] = self.password69 save['gm'] = self.gm70 save['newTime'] = self.newTime71 save['loginTime'] = self.loginTime72 save['logoutTime'] = self.logoutTime73 save['itemTranceNo'] = self.itemTranceNo74 save['mailTranceNo'] = self.mailTranceNo75 save['petTranceNo'] = self.petTranceNo76 save['loginNum'] = self.loginNum77 save['shutuped'] = self.shutuped78 save['blocked'] = self.blocked79 save['onlineTimeTotal'] = self.onlineTimeTotal80 save['channel'] = self.channel81 save['platform'] = self.platform82 save['baseDict'] = self.owner.base.to_save_dict(forced=forced) #角色基础信息83 save['attrDict'] = self.owner.attr.to_save_dict(forced=forced) # 角色属性84 save['historyDict'] = self.owner.history.to_save_dict(forced=forced) # 历史统计85 save['bagDict'] = self.owner.bag.to_save_dict(forced=forced) # 角色背包86 save['walletDict'] = self.owner.wallet.to_save_dict(forced=forced) # 角色钱包87 save['rankDict'] = self.owner.rank.to_save_dict(forced=forced) # 角色排行88 save['battleArrayDict'] = self.owner.battle_array.to_save_dict(forced=forced) # 角色出战阵型89 save['mapDict'] = self.owner.map.to_save_dict(forced=forced) # 地图90 save['niudanDict'] = self.owner.niudan.to_save_dict(forced=forced) # 扭蛋91 save['chargeDict'] = self.owner.charge.to_save_dict(forced=forced) # 充值92 save['chargeDailyDict'] = self.owner.chargeDaily.to_save_dict(forced=forced) # 充值日常93 save['zhuanpanDict'] = self.owner.zhuanpan.to_save_dict(forced=forced) # 转盘94 save['shopDict'] = self.owner.shop.to_save_dict(forced=forced) # 商店95 save['rescueDict'] = self.owner.rescue.to_save_dict(forced=forced) # 救援队96 save['vipDict'] = self.owner.vip.to_save_dict(forced=forced) # vip97 save['totemDict'] = self.owner.totem.to_save_dict(forced=forced) # 图腾98 save['petDict'] = self.owner.pet.to_save_dict(forced=forced) # 角色宠物99 save["marryDict"] = self.owner.marry.to_save_dict(forced=forced) # 婚姻100 save["houseDict"] = self.owner.house.to_save_dict(forced=forced) # 房子101 save["examDict"] = self.owner.exam.to_save_dict(forced=forced) # 答题102 save['bossDict'] = self.owner.boss.to_save_dict(forced=forced) # boss 四合一103 save['chenghaoDict'] = self.owner.chenghao.to_save_dict(forced=forced) # 称号104 save['myheadDict'] = self.owner.myhead.to_save_dict(forced=forced) # 头像105 save['relationshipDict'] = self.owner.relationship.to_save_dict(forced=forced) # 连协 羁绊 队伍加成106 save["daoguanDict"] = self.owner.daoguan.to_save_dict(forced=forced) # 道馆107 save['fubenDict'] = self.owner.fuben.to_save_dict(forced=forced) # 副本108 save['zhudaoxunliDict'] = self.owner.zhudaoxunli.to_save_dict(forced=forced) # 诸岛巡礼109 save["daylypvpDict"] = self.owner.daylypvp.to_save_dict(forced=forced) # 日常pvp抢夺110 save['hetiDict'] = self.owner.heti.to_save_dict(forced=forced) # 合体111 save["chatDict"] = self.owner.chat.to_save_dict(forced=forced) # 玩家聊天112 save['gongchengDict'] = self.owner.gongcheng.to_save_dict(forced=forced) # 攻城113 save['guildDict'] = self.owner.guild.to_save_dict(forced=forced) # 任务114 save['yabiaoDict'] = self.owner.yabiao.to_save_dict(forced=forced) # 押镖115 save['diaoyuDict'] = self.owner.diaoyu.to_save_dict(forced=forced) # 钓鱼116 # save['taskDict'] = self.owner.task.to_save_dict(forced=forced) # 任务117 return save118 #overwrite119 def save(self, store, forced=False, no_let=False):120 StoreObj.save(self,store, forced=forced, no_let=no_let)121 self.owner.base.cleanDirty() # 角色基础信息122 self.owner.attr.cleanDirty() # 角色属性123 self.owner.history.cleanDirty() # 历史统计124 self.owner.bag.cleanDirty() # 角色背包125 self.owner.wallet.cleanDirty() # 角色钱包126 self.owner.rank.cleanDirty() # 角色排行127 self.owner.battle_array.cleanDirty() # 角色出战阵型128 self.owner.map.cleanDirty() # 地图129 self.owner.niudan.cleanDirty() # 扭蛋130 self.owner.charge.cleanDirty() # 充值131 self.owner.chargeDaily.cleanDirty() # 充值日常132 self.owner.zhuanpan.cleanDirty() # 转盘133 self.owner.shop.cleanDirty() # 商店134 self.owner.rescue.cleanDirty() # 救援队135 self.owner.vip.cleanDirty() # vip136 self.owner.totem.cleanDirty() # 图腾137 self.owner.pet.cleanDirty() # 角色宠物138 self.owner.marry.cleanDirty() #婚姻139 self.owner.house.cleanDirty() #房子140 self.owner.exam.cleanDirty() # 答题141 self.owner.boss.cleanDirty() # boss 四合一142 self.owner.chenghao.cleanDirty() # 称号143 self.owner.myhead.cleanDirty() # 头像144 self.owner.relationship.cleanDirty() # 连协 羁绊 队伍加成145 self.owner.daoguan.cleanDirty() # 道馆146 self.owner.fuben.cleanDirty() # 副本147 self.owner.zhudaoxunli.cleanDirty() # 诸岛巡礼148 self.owner.daylypvp.cleanDirty() # 日常pvp抢夺149 self.owner.heti.cleanDirty() # 合体150 self.owner.chat.cleanDirty() # 玩家聊天151 self.owner.gongcheng.cleanDirty() # 攻城152 self.owner.guild.cleanDirty() # 公会153 self.owner.yabiao.cleanDirty() # 押镖154 self.owner.diaoyu.cleanDirty() # 钓鱼155 # self.owner.task.cleanDirty() # 任务156 def GetLoginTime(self):157 return self.loginTime158 def GetLogoutTime(self):159 return self.logoutTime160 def SetLoginTime(self, iTime):161 self.loginTime = iTime162 self.modify()163 def SetLogoutTime(self, iTime):164 self.logoutTime = iTime165 self.onlineTimeTotal += self.logoutTime - self.loginTime166 if self.onlineTimeTotal < 0:167 self.onlineTimeTotal = 0168 self.modify()169 def AddLoginNum(self):170 self.loginNum += 1171 self.modify()172 def IsGm(self):173 return self.gm174 def GenerateItemTranceNo(self):175 self.itemTranceNo += 1176 self.modify()177 return self.itemTranceNo178 def GeneratePetTranceNo(self):179 self.petTranceNo += 1180 self.modify()181 return self.petTranceNo182 @classmethod183 def name_to_id(cls, name):184 rs = Game.store.values(cls.TABLE_NAME, None, dict(name=name))185 if rs:186 return rs[0]['id']187 @classmethod188 def id_to_name(cls, pid):189 rs = Game.store.values(cls.TABLE_NAME, ['name'], dict(id=pid))190 if rs:...

Full Screen

Full Screen

DebugDataConsumer.py

Source:DebugDataConsumer.py Github

copy

Full Screen

1#!/usr/bin/env python2# -*- coding: utf-8 -*-3# This file is part of Beremiz, a Integrated Development Environment for4# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.5#6# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD7#8# See COPYING file for copyrights details.9#10# This program is free software; you can redistribute it and/or11# modify it under the terms of the GNU General Public License12# as published by the Free Software Foundation; either version 213# of the License, or (at your option) any later version.14#15# This program is distributed in the hope that it will be useful,16# but WITHOUT ANY WARRANTY; without even the implied warranty of17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the18# GNU General Public License for more details.19#20# You should have received a copy of the GNU General Public License21# along with this program; if not, write to the Free Software22# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.23from __future__ import absolute_import24import datetime25# -------------------------------------------------------------------------------26# Date and Time conversion function27# -------------------------------------------------------------------------------28SECOND = 1000000 # Number of microseconds in one second29MINUTE = 60 * SECOND # Number of microseconds in one minute30HOUR = 60 * MINUTE # Number of microseconds in one hour31DAY = 24 * HOUR # Number of microseconds in one day32# Date corresponding to Epoch (1970 January the first)33DATE_ORIGIN = datetime.datetime(1970, 1, 1)34def get_microseconds(value):35 """36 Function converting time duration expressed in day, second and microseconds37 into one expressed in microseconds38 @param value: Time duration to convert39 @return: Time duration expressed in microsecond40 """41 return float(value.days * DAY +42 value.seconds * SECOND +43 value.microseconds)44def generate_time(value):45 """46 Function converting time duration expressed in day, second and microseconds47 into a IEC 61131 TIME literal48 @param value: Time duration to convert49 @return: IEC 61131 TIME literal50 """51 microseconds = get_microseconds(value)52 # Get absolute microseconds value and save if it was negative53 negative = microseconds < 054 microseconds = abs(microseconds)55 # TIME literal prefix56 data = "T#"57 if negative:58 data += "-"59 # In TIME literal format, it isn't mandatory to indicate null values60 # if no greater non-null values are available. This variable is used to61 # inhibit formatting until a non-null value is found62 not_null = False63 for val, format in [64 (int(microseconds) / DAY, "%dd"), # Days65 ((int(microseconds) % DAY) / HOUR, "%dh"), # Hours66 ((int(microseconds) % HOUR) / MINUTE, "%dm"), # Minutes67 ((int(microseconds) % MINUTE) / SECOND, "%ds")]: # Seconds68 # Add value to TIME literal if value is non-null or another non-null69 # value have already be found70 if val > 0 or not_null:71 data += format % val72 # Update non-null variable73 not_null = True74 # In any case microseconds have to be added to TIME literal75 data += "%gms" % (microseconds % SECOND / 1000.)76 return data77def generate_date(value):78 """79 Function converting time duration expressed in day, second and microseconds80 into a IEC 61131 DATE literal81 @param value: Time duration to convert82 @return: IEC 61131 DATE literal83 """84 return (DATE_ORIGIN + value).strftime("DATE#%Y-%m-%d")85def generate_datetime(value):86 """87 Function converting time duration expressed in day, second and microseconds88 into a IEC 61131 DATE_AND_TIME literal89 @param value: Time duration to convert90 @return: IEC 61131 DATE_AND_TIME literal91 """92 return (DATE_ORIGIN + value).strftime("DT#%Y-%m-%d-%H:%M:%S.%f")93def generate_timeofday(value):94 """95 Function converting time duration expressed in day, second and microseconds96 into a IEC 61131 TIME_OF_DAY literal97 @param value: Time duration to convert98 @return: IEC 61131 TIME_OF_DAY literal99 """100 microseconds = get_microseconds(value)101 # TIME_OF_DAY literal prefix102 data = "TOD#"103 for val, format in [104 (int(microseconds) / HOUR, "%2.2d:"), # Hours105 ((int(microseconds) % HOUR) / MINUTE, "%2.2d:"), # Minutes106 ((int(microseconds) % MINUTE) / SECOND, "%2.2d."), # Seconds107 (microseconds % SECOND, "%6.6d")]: # Microseconds108 # Add value to TIME_OF_DAY literal109 data += format % val110 return data111# Dictionary of translation functions from value send by debugger to IEC112# literal stored by type113TYPE_TRANSLATOR = {114 "TIME": generate_time,115 "DATE": generate_date,116 "DT": generate_datetime,117 "TOD": generate_timeofday,118 "STRING": lambda v: "'%s'" % v,119 "WSTRING": lambda v: '"%s"' % v,120 "REAL": lambda v: "%.6g" % v,121 "LREAL": lambda v: "%.6g" % v}122# -------------------------------------------------------------------------------123# Debug Data Consumer Class124# -------------------------------------------------------------------------------125class DebugDataConsumer(object):126 """127 Class that implements an element that consumes debug values128 Value update can be inhibited during the time the associated Debug Viewer is129 refreshing130 """131 def __init__(self):132 """133 Constructor134 """135 # Debug value and forced flag136 self.Value = None137 self.Forced = False138 # Store debug value and forced flag when value update is inhibited139 self.LastValue = None140 self.LastForced = False141 # Value IEC data type142 self.DataType = None143 # Flag that value update is inhibited144 self.Inhibited = False145 def Inhibit(self, inhibit):146 """147 Set flag to inhibit or activate value update148 @param inhibit: Inhibit flag149 """150 # Save inhibit flag151 self.Inhibited = inhibit152 # When reactivated update value and forced flag with stored values153 if not inhibit and self.LastValue is not None:154 self.SetForced(self.LastForced)155 self.SetValue(self.LastValue)156 # Reset stored values157 self.LastValue = None158 self.LastForced = False159 def SetDataType(self, data_type):160 """161 Set value IEC data type162 @param data_type: Value IEC data type163 """164 self.DataType = data_type165 def NewValues(self, tick, values, raw="BOOL"):166 """167 Function called by debug thread when a new debug value is available168 @param tick: PLC tick when value was captured169 @param value: Value captured170 @param forced: Forced flag, True if value is forced (default: False)171 @param raw: Data type of values not translated (default: 'BOOL')172 """173 value, forced = values174 # Translate value to IEC literal175 if self.DataType != raw:176 value = TYPE_TRANSLATOR.get(self.DataType, str)(value)177 # Store value and forced flag when value update is inhibited178 if self.Inhibited:179 self.LastValue = value180 self.LastForced = forced181 # Update value and forced flag in any other case182 else:183 self.SetForced(forced)184 self.SetValue(value)185 def SetValue(self, value):186 """187 Update value.188 May be overridden by inherited classes189 @param value: New value190 """191 self.Value = value192 def GetValue(self):193 """194 Return current value195 @return: Current value196 """197 return self.Value198 def SetForced(self, forced):199 """200 Update Forced flag.201 May be overridden by inherited classes202 @param forced: New forced flag203 """204 self.Forced = forced205 def IsForced(self):206 """207 Indicate if current value is forced208 @return: Current forced flag209 """...

Full Screen

Full Screen

forcedvel.py

Source:forcedvel.py Github

copy

Full Screen

1'''2Created on 17 Sep 20143@author: sm61104The module contains methods to define the velocity at the beam support.5The methods are equivalent to those implemented in the subroutine:6 module: input7 input_forcedvel (NumNodes,Time,ForcedVel,ForcedVelDot)8 9of the original Fortran beam solver. The output variables are:10 ForcedVel (NumSteps+1,6) ! Forced velocities at the support.11 ForcedVelDot(NumSteps+1,6) ! Derivatives of the forced velocities at the support.12these describe velocities and accelerations of the support at NumSteps, evenly 13spaced, times-steps.14'''15import numpy as np16#-------------------------------------------------- Methods from input_forcedved17def set_zero(Time):18 # VelAmp=0.d019 20 NumSteps = len(Time)-121 22 ForcedVel = np.zeros( (NumSteps+1,6), dtype='float', order='F' )23 ForcedVelDot = np.zeros( (NumSteps+1,6), dtype='float', order='F' )24 25 return ForcedVel, ForcedVelDot 26def set_sin(Time, Omega, TrAmpl, RotAmpl ):27 ''' 28 Sinusoidal oscillation of frequency Omega and amplitudes TrAmpl29 (translational dof) and MomAmpl (rotational dof), such that the final support30 motion will be:31 32 Tr/Rot = {TrAmpl/RotAmpl}*sin(Omega Time)33 34 '''35 36 NumSteps = len(Time)-1 37 38 ForcedVel = np.zeros( (NumSteps+1,6), dtype='float', order='F' )39 ForcedVelDot = np.zeros( (NumSteps+1,6), dtype='float', order='F' )40 Time = Omega*Time41 ForcedVel[:,:3] = np.sin(Time).reshape((NumSteps+1,1)) * TrAmpl42 ForcedVel[:,3:] = np.sin(Time).reshape((NumSteps+1,1)) * RotAmpl 43 44 ForcedVelDot[:,:3]= Omega * np.cos(Time).reshape((NumSteps+1,1)) * TrAmpl45 ForcedVelDot[:,3:]= Omega * np.cos(Time).reshape((NumSteps+1,1)) * RotAmpl46 47 return ForcedVel, ForcedVelDot 48def set_ramp( Time, Tfull, TrAmp, RotAmp ):49 '''50 Tfull: time-step at which the full load amplitude is reached.51 '''52 53 if Tfull > Time[-1]:54 raise NameError('Tfull has to be less-equal then Time[-1]') 55 56 NumSteps = len(Time)-157 ForcedVel = np.empty( (NumSteps+1,6), dtype='float', order='F' )58 ForcedVelDot = np.empty( (NumSteps+1,6), dtype='float', order='F' )59 vel_shape = np.ones( (NumSteps+1,1), dtype=float, order='F' )60 acc_shape = np.zeros( (NumSteps+1,1), dtype=float, order='F' )61 62 NSfull = np.sum(Time < Tfull) # 1st time-step with full load63 for ii in range(NSfull): # NSfull is excluded64 vel_shape[ii]= Time[ii]/Tfull65 acc_shape[ii]= 1.0/Tfull66 67 ForcedVel[:,:3] = vel_shape * TrAmp68 ForcedVel[:,3:] = vel_shape * RotAmp69 70 ForcedVelDot[:,:3] = acc_shape * TrAmp71 ForcedVelDot[:,3:] = acc_shape * RotAmp 72 73 return ForcedVel, ForcedVelDot74def set_rampsin( Time, Tfull, Omega, TrAmpl, RotAmpl ):75 '''76 Tfull: time-step at which the full load amplitude is reached.77 omega: sine frequency78 '''79 80 v1 = np.ones(3)81 82 vel_sin, acc_sin = set_sin(Time,Omega, TrAmpl, RotAmpl )83 vel_ramp1, acc_ramp1 = set_ramp( Time, Tfull, v1, v1 )84 85 ForcedVel = vel_sin * vel_ramp186 ForcedVelDot = acc_sin*vel_ramp1 + vel_sin*acc_ramp187 88 return ForcedVel, ForcedVelDot 89if __name__=='__main__':90 91 import matplotlib.pyplot as plt92 93 Time = np.linspace(0,5,500) # sec94 Omega = 2.0*np.pi*2.0 # 2Hz 95 TrAmpl =np.array([1.,10.,100.])96 RotAmpl=np.array([2.,20.,200.]) 97 Tfull = 3.098 99 #ForcedVel, ForcedVelDot = set_sin(Time, Omega, TrAmpl, RotAmpl )100 #ForcedVel, ForcedVelDot = set_ramp(Time, Tfull, TrAmpl, RotAmpl )101 ForcedVel, ForcedVelDot = set_rampsin(Time, Tfull, Omega, TrAmpl, RotAmpl )102 103 104 for ii in range(3):105 plt.plot(Time,ForcedVel[:,ii],'r')106 plt.plot(Time,ForcedVel[:,ii+3],'k')107 plt.title('Velocities of Tr and Rot no. %d' %(ii))108 plt.show()109 110 plt.plot(Time,ForcedVelDot[:,ii],'r')111 plt.plot(Time,ForcedVelDot[:,ii+3],'k')112 plt.title('Accelerations of Tr and Rot no. %d' %(ii))113 plt.show() 114 115 116 117 ...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful