Best Python code snippet using hypothesis
check_date_count.py
Source: check_date_count.py
...9nodeaddress = "wss://api.cocosbcx.net"10AFTER_DAYS = 3011last_block_date = "1970-01-01" # random default date12result_block_data = {}13def check_block(start_date):14 global last_block_date, AFTER_DAYS, result_block_data15 start_date = start_date16 gph = Graphene(node=nodeaddress)17 info = gph.info()18 logger.info("info: {}".format(info))19 last_block_num = info['head_block_number']20 logger.info("time: {}".format(info["time"]))21 current_time = info["time"]22 current_date = info["time"].split("T")[0]23 start_block_num = 124 end_block_num = last_block_num25 seconds = compare_time(current_date, start_date)26 logger.info("current_date: {}, start_date: {}, seconds: {}".format(current_date, start_date, seconds))27 if seconds < 3600 * 24 * AFTER_DAYS:28 logger.info("before {} days".format(AFTER_DAYS))29 logger.info("last_block_num: {}, delta: {}".format(last_block_num, 1800 * 24 * AFTER_DAYS))30 end_block_num = last_block_num31 start_block_num = last_block_num - 1800 * 24 * AFTER_DAYS32 else:33 logger.info("after {} days".format(AFTER_DAYS))34 start_block_num = int(last_block_num - seconds/2)35 end_block_num = int(start_block_num + (1800 * 24 * AFTER_DAYS))36 if last_block_num < end_block_num:37 end_block_num = last_block_num38 logger.info('[block num]start: {}, end: {}, last: {}, seconds: {}'.format(start_block_num, end_block_num, last_block_num, seconds))39 for block_num in range(start_block_num, end_block_num+1):40 try:41 block = gph.rpc.get_block(block_num)42 # logger.info("block: {}".format(block))43 timestamp = block["timestamp"]44 block_date = timestamp.split("T")[0]45 46 if block_date != last_block_date:47 # logger.info("last_date: {}, block_num: {}, block: {}".format(last_block_date, block_num, block))48 logger.info("last_date: {}, block_num: {}, block_id: {}, block timestamp: {}".format(last_block_date, 49 block_num, block["block_id"], block["timestamp"]))50 if last_block_date in result_block_data.keys():51 logger.info(">>>>>>>>>>>> {}: {}".format(last_block_date, result_block_data[last_block_date]))52 last_block_date = block_date53 result_block_data[block_date] = {54 "block_total": 0,55 "trx_total": 0,56 "ops_total": 057 }58 block_data = result_block_data[block_date]59 block_data["block_total"] += 160 transactions = block["transactions"]61 if transactions:62 block_data["trx_total"] += len(transactions)63 for trx in transactions:64 block_data["ops_total"] += len(trx[1]["operations"])65 result_block_data[block_date] = block_data66 except Exception as e:67 logger.error('get_object exception. block {}, error {}'.format(block_num, repr(e)))68 logger.info("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>> total result: \n{}".format(result_block_data))69def compare_time(time1, time2):70 s_time = time.mktime(time.strptime(time1,'%Y-%m-%d'))71 e_time = time.mktime(time.strptime(time2,'%Y-%m-%d'))72 return int(s_time) - int(e_time)73def compare_time_test():74 result = compare_time('2020-04-17', '2020-04-19')75 logger.info("result: {}".format(result))76if __name__ == '__main__':77 logger.info('args: {}'.format(sys.argv))78 if len(sys.argv) < 2:79 logger.error('Usage: python3 check.py start_date[2020-07-01]')80 sys.exit(1)81 start_date = sys.argv[1]82 check_block(start_date)83'''841. åè½85ç»è®¡æ¯å¤©çé¾ä¸åºåã交æåoperationçæ»æ°ã86è¾å
¥ä¸ä¸ªå¼å§æ¥æï¼ç»è®¡è¯¥æ¥æä¹åNå¤©çæ°æ®ï¼Nç±AFTER_DAYSå
¨å±åéæ§å¶ï¼é»è®¤æ¯7ï¼å¯ä»¥æ ¹æ®ç»è®¡éæ±ä»»æä¿®æ¹ã87妿å¼å§æ¥æåææ°åºåçé´éå°äºN天ï¼ç»è®¡ææ°åºåä¹åçNå¤©æ°æ®ã882. 使ç¨89ä¾èµï¼ python-sdk90python3 check_count.py YYYY-MM-DD 91说æï¼ 92æ¥ææ ¼å¼ï¼ YYYY-MM-DD933. æµè¯94AFTER_DAYS = 7 test record:95---------------------------------------------------96dev@ck-chain-slave-prod-001:~/cocos/data_analysis# nohup python3 check_count.py 2020-06-24 >> console.log 2>&1 &...
minesweeper.py
Source: minesweeper.py
...25 for _ in range(0, BOARD_Y):26 GAMEBOARD[i].append(0)27def is_bomb(x, y):28 return GAMEBOARD[x][y] == 'B'29def check_block(x, y):30 if x < 0:31 return 'X'32 if x > BOARD_X-1:33 return 'X'34 if y < 0:35 return 'X'36 if y > BOARD_Y-1:37 return 'X'38 return GAMEBOARD[x][y]39def count_bombs(x, y):40 bomb_count = 041 if check_block(x-1, y) == 'B':42 bomb_count += 143 if check_block(x-1, y+1) == 'B':44 bomb_count += 145 if check_block(x, y+1) == 'B':46 bomb_count += 147 if check_block(x+1, y+1) == 'B':48 bomb_count += 149 if check_block(x+1, y) == 'B':50 bomb_count += 151 if check_block(x+1, y-1) == 'B':52 bomb_count += 153 if check_block(x, y-1) == 'B':54 bomb_count += 155 if check_block(x-1, y-1) == 'B':56 bomb_count += 157 return bomb_count58def get_number_format(num):59 if num < 10 and num >= 0:60 return CHARACTER_LOOKUP[str(num)]61 return CHARACTER_LOOKUP['X']62def random_vector(x_max, y_max):63 return random.randint(0, x_max), random.randint(0, y_max)64def generate_bombs():65 global GAMEBOARD66 mine_count = 067 while mine_count < MINECOUNT:68 x, y = random_vector(BOARD_X - 1, BOARD_Y - 1)69 if is_bomb(x, y):70 continue71 GAMEBOARD[x][y] = 'B'72 mine_count += 173def generate_numbers():74 global GAMEBOARD75 for x in range(0, BOARD_X):76 for y in range(0, BOARD_Y):77 if is_bomb(x, y):78 continue79 GAMEBOARD[x][y] = str(count_bombs(x, y))80def place_within_tag(element):81 return SPOILERS_CHAR + element + SPOILERS_CHAR82def generate_emoji_board():83 board = ''84 for x in range(0, BOARD_X):85 tmp = ''86 for y in range(0, BOARD_Y):87 if check_block(x, y) == '0':88 tmp += ':' + CHARACTER_LOOKUP[GAMEBOARD[x][y]] + ':'89 continue90 else:91 if len(tmp) > 0:92 board += place_within_tag(tmp)93 tmp = ''94 board += place_within_tag(':' + CHARACTER_LOOKUP[GAMEBOARD[x][y]] + ':')95 if len(tmp) > 0:96 board += place_within_tag(tmp)97 tmp = ''98 board += '\n'99 print(board)100def main(argc, argv):101 global BOARD_X...
Check out the latest blogs from LambdaTest on this topic:
The best agile teams are built from people who work together as one unit, where each team member has both the technical and the personal skills to allow the team to become self-organized, cross-functional, and self-motivated. These are all big words that I hear in almost every agile project. Still, the criteria to make a fantastic agile team are practically impossible to achieve without one major factor: motivation towards a common goal.
Hey LambdaTesters! We’ve got something special for you this week. ????
Xamarin is an open-source framework that offers cross-platform application development using the C# programming language. It helps to simplify your overall development and management of cross-platform software applications.
As everyone knows, the mobile industry has taken over the world and is the fastest emerging industry in terms of technology and business. It is possible to do all the tasks using a mobile phone, for which earlier we had to use a computer. According to Statista, in 2021, smartphone vendors sold around 1.43 billion smartphones worldwide. The smartphone penetration rate has been continuously rising, reaching 78.05 percent in 2020. By 2025, it is expected that almost 87 percent of all mobile users in the United States will own a smartphone.
The sky’s the limit (and even beyond that) when you want to run test automation. Technology has developed so much that you can reduce time and stay more productive than you used to 10 years ago. You needn’t put up with the limitations brought to you by Selenium if that’s your go-to automation testing tool. Instead, you can pick from various test automation frameworks and tools to write effective test cases and run them successfully.
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!!