Best Python code snippet using autotest_python
test_stake_part.py
Source:test_stake_part.py
...77 key = StakePart.make_key(create_address(1))78 self.assertEqual(ICON_CONTRACT_ADDRESS_BYTES_SIZE + len(StakePart.PREFIX), len(key))79 def test_stake_part_stake(self):80 part = StakePart()81 part.set_complete(True)82 self.assertEqual(0, part.stake)83 def test_stake_part_stake_overflow(self):84 part = StakePart()85 with self.assertRaises(Exception) as e:86 self.assertEqual(0, part.stake)87 self.assertEqual(AssertionError, type(e.exception))88 def test_stake_part_voting_weight(self):89 stake = 1090 part = StakePart(stake=stake)91 part.set_complete(True)92 self.assertEqual(stake, part.voting_weight)93 def test_stake_part_voting_weight_overflow(self):94 part = StakePart()95 with self.assertRaises(Exception) as e:96 self.assertEqual(0, part.voting_weight)97 self.assertEqual(AssertionError, type(e.exception))98 def test_stake_part_unstake(self):99 unstake = 10100 part = StakePart(unstake=unstake)101 part.set_complete(True)102 self.assertEqual(unstake, part.unstake)103 def test_stake_part_unstake_overflow(self):104 part = StakePart()105 with self.assertRaises(Exception) as e:106 self.assertEqual(0, part.unstake)107 self.assertEqual(AssertionError, type(e.exception))108 def test_stake_part_unstake_block_height(self):109 unstake_block_height = 10110 part = StakePart(unstake_block_height=unstake_block_height)111 part.set_complete(True)112 self.assertEqual(unstake_block_height, part.unstake_block_height)113 def test_stake_part_unstake_block_height_overflow(self):114 part = StakePart()115 with self.assertRaises(Exception) as e:116 self.assertEqual(0, part.unstake_block_height)117 self.assertEqual(AssertionError, type(e.exception))118 def test_stake_part_total_stake(self):119 stake = 10120 unstake = 20121 part = StakePart(stake=stake, unstake=unstake)122 part.set_complete(True)123 self.assertEqual(stake+unstake, part.total_stake)124 def test_stake_part_total_stake_overflow(self):125 part = StakePart()126 with self.assertRaises(Exception) as e:127 self.assertEqual(0, part.total_stake)128 self.assertEqual(AssertionError, type(e.exception))129 def test_stake_part_add_stake(self):130 part = StakePart()131 part.set_complete(True)132 stake = 100133 part.add_stake(100)134 self.assertEqual(stake, part.stake)135 self.assertTrue(part.is_set(BasePartState.DIRTY | BasePartState.COMPLETE))136 def test_stake_part_set_unstake_update(self):137 part = StakePart()138 part.set_complete(True)139 stake = 100140 block_height = 10141 part.add_stake(100)142 unstake = stake143 part.set_unstake(block_height, unstake)144 self.assertEqual(0, part.stake)145 self.assertEqual(stake, part.unstake)146 self.assertEqual(block_height, part.unstake_block_height)147 self.assertTrue(part.is_set(BasePartState.DIRTY | BasePartState.COMPLETE))148 block_height += block_height149 unstake = 10150 part.set_unstake(block_height, unstake)151 self.assertEqual(stake - unstake, part.stake)152 self.assertEqual(unstake, part.unstake)...
defs.py
Source:defs.py
1import glob2import numpy as np3import tensorflow as tf4import keras5from numpy.random import default_rng6from keras import backend as K7def get_data(train_path, test_path, train_mean, test_mean):8 beginning = 19 actionTrainFolder = sorted(glob.glob(train_path + "train/*/"))10 for ins_e, ins in enumerate(actionTrainFolder):11 instanceFolder = sorted(glob.glob(ins + "*/"))12 for cla_e, cla in enumerate(instanceFolder):13 classFolder = sorted(glob.glob(cla + "/*.png"))14 for img_e, img in enumerate(classFolder):15 tensor = tf.io.read_file(img)16 print(img)17 tensor = tf.io.decode_image(tensor, dtype=tf.dtypes.uint8)18 tensor = tf.image.convert_image_dtype(tensor, tf.float32)19 if beginning == 1:20 img_w,img_h,img_d = tensor.shape21 train_cla_n = len(instanceFolder)22 train_img_n = len(classFolder)23 train_set = np.zeros((len(actionTrainFolder) ,len(instanceFolder) ,len(classFolder), img_w, img_h, 1), dtype = 'float32') 24 beginning = 025 train_set[ins_e,cla_e,img_e,:,:,:] = tensor26 beginning = 127 actionTestFolder = sorted(glob.glob(test_path + "test/*/"))28 for ins_e, ins in enumerate(actionTestFolder):29 instanceFolder = sorted(glob.glob(ins + "*/"))30 for cla_e, cla in enumerate(instanceFolder):31 classFolder = sorted(glob.glob(cla + "/*.png"))32 for img_e, img in enumerate(classFolder):33 tensor = tf.io.read_file(img)34 print(img)35 tensor = tf.io.decode_image(tensor, dtype=tf.dtypes.uint8)36 tensor = tf.image.convert_image_dtype(tensor, tf.float32)37 if beginning == 1:38 test_cla_n = len(instanceFolder)39 test_set = np.zeros((len(actionTestFolder) ,len(instanceFolder) ,len(classFolder), img_w, img_h, 1), dtype = 'float32') 40 beginning = 041 test_set[ins_e,cla_e,img_e,:,:,:] = tensor42 if train_mean == True:43 train_set = np.mean(train_set, axis=(2), keepdims=True)44 if test_mean == True:45 test_set = np.mean(test_set, axis=(2), keepdims=True)46 return img_w, img_h, train_cla_n, test_cla_n, train_img_n, train_set, test_set47def get_r_val(train_path, test_path, train_cla_n, test_cla_n):48 r_train = np.array([])49 r_test = np.array([])50 51 beginning = 152 actionFolder = sorted(glob.glob(train_path + "train/*/"))53 54 for ins_e, ins in enumerate(actionFolder):55 print(ins)56 instanceFolder = sorted(glob.glob(ins + "*.npy"))57 for r_e, r in enumerate(instanceFolder):58 print(r)59 r_act = np.load(r)60 if beginning == 1:61 r_shape = r_act.shape62 r_train = np.zeros((train_cla_n, r_shape[0], r_shape[1], 1))63 r_train[r_e,:,:,:] = r_act64 beginning = 065 else :66 r_train[r_e,:,:,:] = r_act67 68 beginning = 169 actionFolder = sorted(glob.glob(test_path + "test/*/"))70 71 for ins_e, ins in enumerate(actionFolder):72 print(ins)73 instanceFolder = sorted(glob.glob(ins + "*.npy"))74 for r_e, r in enumerate(instanceFolder):75 print(r)76 r_act = np.load(r)77 if beginning == 1:78 r_shape = r_act.shape79 r_test = np.zeros((test_cla_n, r_shape[0], r_shape[1], 1))80 r_test[r_e,:,:,:] = r_act81 beginning = 082 else :83 r_test[r_e,:,:,:] = r_act84 return r_train, r_test85def make_epoch(set_complete):86 ins_e,cla_e,img_e,img_h,img_w,img_d=set_complete.shape87 cla_rand = np.zeros(cla_e)88 img_rand = np.zeros(img_e)89 rng = default_rng()90 91 cla_rand[:] = rng.choice(cla_e, size=cla_e, replace=False)92 img_rand[:] = rng.choice(img_e, size=img_e, replace=False)93 cla_rang = np.tile(cla_rand,img_e)94 img_rang = np.repeat(img_rand, cla_e)95 cla_iter = iter(cla_rang)96 img_iter = iter(img_rang)97 return cla_iter, img_iter , cla_rang, img_rang98def make_batch(set_complete, cla_iter, img_iter, batch_size, r_train, r_max):99 ins_e,cla_e,img_e,img_h,img_w,img_d=set_complete.shape100 r_batch = np.zeros((batch_size,img_h,img_w,img_d),dtype='float32')101 input_batch = np.zeros((batch_size,img_h,img_w,img_d),dtype='float32')102 ground_batch = np.zeros((batch_size,img_h,img_w,img_d),dtype='float32')103 for i in range(batch_size):104 cla_pick = next(cla_iter, None)105 img_pick = next(img_iter, None)106 if cla_pick == None or img_pick == None:107 break108 r_batch[i,:,:,:] = r_train[int(cla_pick), :,:,:]109 input_batch[i,:,:,:] = set_complete[0,int(cla_pick),int(img_pick),:,:,:] 110 ground_batch[i,:,:,:] = set_complete[1,int(cla_pick),int(img_pick),:,:,:]111 input_batch = input_batch * r_batch/r_max112 ground_batch = ground_batch * r_batch/r_max113 return input_batch, ground_batch, r_batch114def custom_loss(r, img_w, img_h, r_max):115 img_w = K.constant(img_w)116 img_h = K.constant(img_h)117 r_max = K.constant(r_max)118 def loss(y_true, y_pred):119 loss_value = K.sum((K.abs(y_pred - y_true)))/(img_w * img_h)120 return loss_value121 return loss122def dist(a, b, IM_SIZE, r_max):123 z_diff = 50 #mm...
admin.py
Source:admin.py
...80 'set_shipped',81 'set_delivered',82 )83 def set_complete_delivered(self, request, queryset):84 self.set_complete(request, queryset)85 self.set_delivered(request, queryset)86 set_complete_delivered.short_description = 'Mark selected orders as complete and delivered today'87 def set_complete(self, request, queryset):88 queryset.update(complete=True)89 self.set_delivered(request, queryset)90 set_complete.short_description = 'Mark selected orders as complete'91 def set_incomplete(self, request, queryset):92 queryset.update(complete=False)93 set_incomplete.short_description = 'Mark selected orders as incomplete'94 def set_shipped(self, request, queryset):95 queryset.filter(shipping_date=None).update(shipping_date=date.today())96 set_shipped.short_description = 'Mark selected orders as shipped today'97 def set_delivered(self, request, queryset):98 queryset.filter(delivery_date=None).update(delivery_date=date.today())99 set_delivered.short_description = 'Mark selected orders as delivered today'100 def make_state_action(self, state):101 name = 'set_state_{0}'.format(state.state)...
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!!