How to use process_packages method in autotest

Best Python code snippet using autotest_python

process_edit.py

Source: process_edit.py Github

copy

Full Screen

1import os2import random3from werkzeug.utils import secure_filename4import shutil5from db_manager.models import db, Process6from configuration import config7import datetime8class ProcessEdit:9 def __init__(self, form_request, form_files):10 self.form_request = form_request11 self.form_files = form_files12 def update_process(self):13 current_process = Process.query.filter_by(id=self.form_request['process_id']).first()14 # handling duplicate name15 same_processes = Process.query.filter(Process.name == self.form_request['name']).all()16 for process_item in same_processes:17 if process_item.id != current_process.id:18 return "duplicate_name"19 # handling duplicate package_name20 same_processes = Process.query.filter(Process.package_name == self.form_request['package_name']).all()21 for process_item in same_processes:22 if process_item.id != current_process.id:23 return "duplicate_package_name"24 # فقط نام پکیج تغییر کرده و فایل جدیدی انتخاب نشده است25 if self.form_request['package_name'] != Process.query.filter_by(package_name=self.form_request['package_name']).first() and \26 'kpp_file' not in self.form_files:27 shutil.move("{0}process_packages\\{1}.kpp".format(config.static_dir_local, current_process.package_name),28 "{0}process_packages\\{1}.kpp".format(config.static_dir_local, self.form_request['package_name']))29 package_address = "/​static/​process_packages/​{0}.kpp".format(self.form_request['package_name'])30 current_process.package_address = package_address31 # handling package file32 if 'kpp_file' in self.form_files:33 try:34 # حذف فایل فرآیند قبلی35 if os.path.exists(36 "{0}process_packages\\{1}.kpp".format(config.static_dir_local, current_process.package_name)):37 os.remove(38 "{0}process_packages\\{1}.kpp".format(config.static_dir_local, current_process.package_name))39 # ذخیره و کپی کردن فایل فرآیند جدید با نام جدید40 f = self.form_files['kpp_file']41 filename = secure_filename(f.filename)42 f.save(filename)43 shutil.move(filename, "{0}.kpp".format(self.form_request['package_name']))44 filename = "{0}.kpp".format(self.form_request['package_name'])45 # اطمینان از نبودن فایل با نام مشابه46 files_list = os.listdir('{0}process_packages'.format(config.static_dir_local))47 filename_correction = False48 new_filename = filename49 while not filename_correction:50 if new_filename in files_list:51 new_filename = str(random.randint(0, 9)) + new_filename52 else:53 filename_correction = True54 shutil.move(filename, "{0}process_packages\\{1}".format(config.static_dir_local, new_filename))55 package_address = "/​static/​process_packages/​{0}".format(new_filename)56 current_process.package_address = package_address57 except:58 return "kpp_file_error"59 # image file handling60 # image_address = ''61 if 'img_file' in self.form_files:62 try:63 # حذف عکس قبلی64 if os.path.exists("{0}process_images\\{1}.kpp".format(config.static_dir_local,65 current_process.image_address.replace(66 "/​static/​process_images/​", ''))):67 os.remove("{0}process_images\\{1}.kpp".format(config.static_dir_local,68 current_process.image_address.replace(69 "/​static/​process_images/​", '')))70 # ذخیره سازی عکس جدید71 f = self.form_files['img_file']72 filename = secure_filename(f.filename)73 f.save(filename)74 files_list = os.listdir('{0}process_images'.format(config.static_dir_local))75 filename_correction = False76 new_filename = filename77 while not filename_correction:78 if new_filename in files_list:79 new_filename = str(random.randint(1, 99)) + new_filename80 else:81 filename_correction = True82 shutil.move(filename, "{0}process_images\\{1}".format(config.static_dir_local, new_filename))83 current_process.image_address = "/​static/​process_images/​{0}".format(new_filename)84 except:85 return "img_file_error"86 current_process.name = self.form_request['name']87 current_process.package_name = self.form_request['package_name']88 current_process.description = self.form_request['description']89 current_process.is_approved = False90 current_process.last_modified_date = str(datetime.datetime.utcnow())91 db.session.commit()...

Full Screen

Full Screen

3. Симуляция обработки сетевых пакетов.py

Source: 3. Симуляция обработки сетевых пакетов.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# https:/​/​stepik.org/​lesson/​Задачи-41234/​step/​3?course=Алгоритмы-теория-и-практика-Структуры-данных&unit=198183def process_packages(size, packages):4 queue = [None] * size5 time = 06 tail = 07 process_end = 08 for arrival, duration in packages:9 if time < arrival:10 time = arrival11 if process_end < time:12 # print(queue)13 del queue[0]14 queue.append(None)15 tail -= 116 if queue[0] is not None:17 process_end = time + queue[0]18 if queue[-1] is not None:19 # очередь заполнена20 yield -121 else:22 yield time23 queue[tail] = duration24 tail += 125if __name__ == '__main__':26 assert tuple(process_packages(1, [[0, 0]])) == (0,)27 print(tuple(process_packages(1, [[0, 1], [0, 1]])))28 assert tuple(process_packages(1, [[0, 1], [0, 1]])) == (0, -1)29 print(tuple(process_packages(1, [[0, 1], [1, 1]])))30 assert tuple(process_packages(1, [[0, 1], [1, 1]])) == (0, 1)31 assert tuple(process_packages(1, [[0, 1]])) == (0,)32 print(tuple(process_packages(1, ((16, 0), (29, 3), (44, 6), (58, 0), (72, 2), (88, 8), (95, 7), (108, 6), (123, 9), (139, 6), (152, 6), (157, 3), (169, 3), (183, 1), (192, 0), (202, 8), (213, 8), (229, 3), (232, 3), (236, 3), (239, 4), (247, 8), (251, 2), (267, 7), (275, 7)))))33 assert \34 tuple(process_packages(1, ((16, 0), (29, 3), (44, 6), (58, 0), (72, 2), (88, 8), (95, 7), (108, 6), (123, 9), (139, 6), (152, 6), (157, 3), (169, 3), (183, 1), (192, 0), (202, 8), (213, 8), (229, 3), (232, 3), (236, 3), (239, 4), (247, 8), (251, 2), (267, 7), (275, 7)))) == \35 (16, 29, 44, 58, 72, 88, -1, 108, 123, 139, 152, -1, 169, 183, 192, 202, 213, 229, 232, 236, 239, 247, -1, 267, 275)36 print(tuple(process_packages(11, ((6, 23), (15, 44), (24, 28), (25, 15), (33, 7), (47, 41), (58, 25), (65, 5), (70, 14), (79, 8), (93, 43), (103, 11), (110, 25), (123, 27), (138, 40), (144, 19), (159, 2), (167, 23), (179, 43), (182, 31), (186, 7), (198, 16), (208, 41), (222, 23), (235, 26)))))37 assert tuple(process_packages(11, ((6, 23), (15, 44), (24, 28), (25, 15), (33, 7), (47, 41), (58, 25), (65, 5), (70, 14), (79, 8), (93, 43), (103, 11), (110, 25), (123, 27), (138, 40), (144, 19), (159, 2), (167, 23), (179, 43), (182, 31), (186, 7), (198, 16), (208, 41), (222, 23), (235, 26)))) == (6, 29, 73, 101, 116, 123, 164, 189, 194, 208, 216, 259, 270, 295, 322, 362, -1, 381, -1, -1, -1, 404, 420, 461, 484)38 # size, n = (int(_) for _ in input().split())39 # for _ in process_packages(size, [[int(_) for _ in input().split(' ')] for _ in range(n)]):...

Full Screen

Full Screen

network_packages.py

Source: network_packages.py Github

copy

Full Screen

1import typing as tp2from collections import deque3def process_packages(size: int, package_list: tp.List[tp.Tuple[int, int]]) -> tp.List[int]:4 result = []5 processing_queue: tp.Deque[int] = deque()6 for package in package_list:7 start, duration = package8 if processing_queue and start >= processing_queue[-1]:9 processing_queue.pop()10 if len(processing_queue) != size:11 start = processing_queue[0] if processing_queue else start12 result.append(start)13 processing_queue.appendleft(duration + start)14 continue15 result.append(-1)16 return result17assert process_packages(18 size=2,19 package_list=[20 (1, 100),21 (1, 100),22 (1, 0),23 ]24) == [1, 101, -1]25assert process_packages(26 size=2,27 package_list=[28 (0, 0),29 (0, 0),30 (0, 0),31 (1, 0),32 (1, 0),33 (1, 1),34 (1, 2),35 (1, 3),36 ]37) == [0, 0, 0, 1, 1, 1, 2, -1]38assert process_packages(39 size=3,40 package_list=[41 (0, 7),42 (0, 0),43 (2, 0),44 (3, 3),45 (4, 0),46 (5, 0),47 ]48) == [0, 7, 7, -1, -1, -1]49assert process_packages(50 size=2,51 package_list=[52 (2, 9),53 (4, 8),54 (10, 9),55 (15, 2),56 (19, 1),57 ]58) == [2, 11, -1, 19, 21]59assert process_packages(60 size=1,61 package_list=[62 (999999, 1),63 (1000000, 0),64 (1000000, 1),65 (1000000, 0),66 (1000000, 0),67 ]68) == [999999, 1000000, 1000000, -1, -1]69assert process_packages(70 size=3,71 package_list=[72 (1, 1),73 (2, 2),74 (3, 3),75 (4, 4),76 (5, 5),77 (6, 6),78 (7, 7),79 (8, 8),80 ]...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Why Agile Teams Have to Understand How to Analyze and Make adjustments

How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.

Top 17 Resources To Learn Test Automation

Lack of training is something that creates a major roadblock for a tester. Often, testers working in an organization are all of a sudden forced to learn a new framework or an automation tool whenever a new project demands it. You may be overwhelmed on how to learn test automation, where to start from and how to master test automation for web applications, and mobile applications on a new technology so soon.

Joomla Testing Guide: How To Test Joomla Websites

Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.

30 Top Automation Testing Tools In 2022

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.

Nov’22 Updates: Live With Automation Testing On OTT Streaming Devices, Test On Samsung Galaxy Z Fold4, Galaxy Z Flip4, &#038; More

Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.

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 autotest 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