How to use get_package_info method in avocado

Best Python code snippet using avocado_python

user_interface.py

Source:user_interface.py Github

copy

Full Screen

...43 while package_id > 40 or package_id < 1:44 package_id = int(input('Invalid package id please enter a new package id (1-40): '))45 # Take user input for time wanting to be checked46 # set times equal to the times for the associated package id given47 departure_time = get_package_map().get_package_info(str(package_id))[9]48 arrival_time = get_package_map().get_package_info(str(package_id))[10]49 time = input('Enter a time (HH:MM:SS): ')50 if departure_time == '8:00:00':51 truck_number = '1'52 elif departure_time == '9:05:00':53 truck_number = '2'54 else:55 truck_number = '3'56 # Converts times using timedelta into HH:MM:SS format57 # to use for comparison operations58 (hours, minutes, seconds) = time.split(':')59 converted_time = datetime.timedelta(hours=int(hours), minutes=int(minutes), seconds=int(seconds))60 (hours, minutes, seconds) = departure_time.split(':')61 converted_departure_time = datetime.timedelta(hours=int(hours), minutes=int(minutes), seconds=int(seconds))62 (hours, minutes, seconds) = arrival_time.split(':')63 converted_arrival_time = datetime.timedelta(hours=int(hours), minutes=int(minutes), seconds=int(seconds))64 # Checks if package is still at hub by comparing departure time65 # to the time given by user. If it is still at hub then it66 # sets delivery status to at hub and sets when it will leave67 # then prints package info for given ID68 if converted_departure_time >= converted_time:69 get_package_map().get_package_info(str(package_id))[10] = 'Package is at hub'70 get_package_map().get_package_info(str(package_id))[9] = 'Leaves hub at ' + departure_time71 print(72 f'\n\nPackage is on truck {truck_number}\n'73 f'Package ID: {get_package_map().get_package_info(str(package_id))[0]}\n'74 f'Address: {get_package_map().get_package_info(str(package_id))[2]}\n'75 f'City: {get_package_map().get_package_info(str(package_id))[3]}\n'76 f'State: {get_package_map().get_package_info(str(package_id))[4]}\n'77 f'Zip: {get_package_map().get_package_info(str(package_id))[5]}\n'78 f'Must be delivered by: {get_package_map().get_package_info(str(package_id))[6]}\n'79 f'Package weight: {get_package_map().get_package_info(str(package_id))[7]} lbs\n'80 f'Truck status: {get_package_map().get_package_info(str(package_id))[9]}\n'81 f'Delivery status: {get_package_map().get_package_info(str(package_id))[10]}\n'82 )83 # checks if package has left hub and check if package is not delivered84 # sets delivery status to out for delivery and sets when it left hub85 # then prints package info for given ID86 elif converted_departure_time <= converted_time:87 if converted_time < converted_arrival_time:88 get_package_map().get_package_info(str(package_id))[10] = 'Package is out for delivery'89 get_package_map().get_package_info(str(package_id))[9] = 'Left hub at ' + departure_time90 print(91 f'\n\nPackage is on truck {truck_number}\n'92 f'Package ID: {get_package_map().get_package_info(str(package_id))[0]}\n'93 f'Address: {get_package_map().get_package_info(str(package_id))[2]}\n'94 f'City: {get_package_map().get_package_info(str(package_id))[3]}\n'95 f'State: {get_package_map().get_package_info(str(package_id))[4]}\n'96 f'Zip: {get_package_map().get_package_info(str(package_id))[5]}\n'97 f'Must be delivered by: {get_package_map().get_package_info(str(package_id))[6]}\n'98 f'Package weight: {get_package_map().get_package_info(str(package_id))[7]} lbs\n'99 f'Truck status: {get_package_map().get_package_info(str(package_id))[9]}\n'100 f'Delivery status: {get_package_map().get_package_info(str(package_id))[10]}\n'101 )102 # Else case - Package has been delivered103 # sets delivery status to delivered with time of delivery104 # then prints package info for given ID105 else:106 get_package_map().get_package_info(str(package_id))[10] = 'Package was delivered at ' + arrival_time107 get_package_map().get_package_info(str(package_id))[9] = 'Left hub at ' + departure_time108 print(109 f'\n\nPackage is on truck {truck_number}\n'110 f'Package ID: {get_package_map().get_package_info(str(package_id))[0]}\n'111 f'Address: {get_package_map().get_package_info(str(package_id))[2]}\n'112 f'City: {get_package_map().get_package_info(str(package_id))[3]}\n'113 f'State: {get_package_map().get_package_info(str(package_id))[4]}\n'114 f'Zip: {get_package_map().get_package_info(str(package_id))[5]}\n'115 f'Must be delivered by: {get_package_map().get_package_info(str(package_id))[6]}\n'116 f'Package weight: {get_package_map().get_package_info(str(package_id))[7]} lbs\n'117 f'Truck status: {get_package_map().get_package_info(str(package_id))[9]}\n'118 f'Delivery status: {get_package_map().get_package_info(str(package_id))[10]}\n'119 )120 except ValueError:121 print('Invalid entry. Try again.')122 single_package()123 pass124 exit()125# Outputs all package info for a user-given time126# Space-Time Complexity: O(N)127def all_packages():128 departure_time = ''129 converted_departure_time = ''130 converted_arrival_time = ''131 arrival_time = ''132 try:133 print("If you would like to return to main menu please type: back")134 # takes user input for time135 time = input("Enter a time (HH:MM:SS):")136 # Allows user to go back if they did not mean to run this function137 if time.lower() == 'back':138 user_interface()139 exit()140 # splits time into hours, min and seconds141 # for comparisons using datetime.timedelta function142 (hours, minutes, seconds) = time.split(':')143 converted_time = datetime.timedelta(hours=int(hours), minutes=int(minutes), seconds=int(seconds))144 # Finds start and end times of packages with [9] and [10] being delivery times145 # Uses timedelta function in order to compare times to determine delivery status146 # based off the user given time147 # Time Complexity O(N^2)148 for ID in range(1, 41):149 try:150 # get departure and arrival time for package151 departure_time = get_package_map().get_package_info(str(ID))[9]152 arrival_time = get_package_map().get_package_info(str(ID))[10]153 # splits departure and arrival times into hours minutes and seconds154 # then converts them into datetime.timedelta objects to be compared155 (hours, minutes, seconds) = departure_time.split(':')156 converted_departure_time = datetime.timedelta(hours=int(hours), minutes=int(minutes),157 seconds=int(seconds))158 (hours, minutes, seconds) = arrival_time.split(':')159 converted_arrival_time = datetime.timedelta(hours=int(hours), minutes=int(minutes),160 seconds=int(seconds))161 except ValueError:162 pass163 # Checks if package is still at hub by comparing departure time to user time164 # Prints out Package ID and delivery status for packages165 # that still remain at the hub166 if converted_departure_time >= converted_time:167 get_package_map().get_package_info(str(ID))[10] = 'Package is at hub'168 get_package_map().get_package_info(str(ID))[9] = 'Package Leaves hub at ' + departure_time169 print(170 f'Package ID: {get_package_map().get_package_info(str(ID))[0]}, '171 f'Delivery status: {get_package_map().get_package_info(str(ID))[10]}'172 )173 # Checks if package is out for delivery by comparing departure time to user time174 # Prints out Package ID and delivery status for packages that175 # are out for delivery176 elif converted_departure_time <= converted_time:177 if converted_time < converted_arrival_time:178 get_package_map().get_package_info(str(ID))[10] = 'Package is out for delivery'179 get_package_map().get_package_info(str(ID))[9] = 'Left hub at ' + departure_time180 print(181 f'Package ID: {get_package_map().get_package_info(str(ID))[0]}, '182 f'Delivery status: {get_package_map().get_package_info(str(ID))[10]}'183 )184 # Else case, package was delivered185 # Prints out Package Id and delivery status for packages that have been delivered186 # at given time187 else:188 get_package_map().get_package_info(str(ID))[10] = 'Package was delivered at ' + arrival_time189 get_package_map().get_package_info(str(ID))[9] = 'Left hub at ' + departure_time190 print(191 f'Package ID: {get_package_map().get_package_info(str(ID))[0]}, '192 f'Delivery status: {get_package_map().get_package_info(str(ID))[10]}'193 )194 # Checks for value error by user and restarts all_packages() function to try again195 except ValueError:196 print('Invalid input. Try again')197 all_packages()...

Full Screen

Full Screen

import_utils.py

Source:import_utils.py Github

copy

Full Screen

...8 format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",9 datefmt="%m/%d/%Y %H:%M:%S",10 level=os.environ.get("LOGLEVEL", "INFO").upper(),11)12def get_package_info(package_name: str, verbose: bool = True):13 """14 Returns the package version as a string and the package name as a string.15 """16 _is_available = is_available(package_name)17 if _is_available:18 try:19 import importlib.metadata as _importlib_metadata20 _version = _importlib_metadata.version(package_name)21 except (ModuleNotFoundError, AttributeError):22 try:23 _version = importlib.import_module(package_name).__version__24 except AttributeError:25 _version = "unknown"26 if verbose:27 logger.info(f"{package_name} version {_version} is available.")28 else:29 _version = "N/A"30 return _is_available, _version31def print_enviroment_info():32 _torch_available, _torch_version = get_package_info("torch")33 _torchvision_available, _torchvision_version = get_package_info("torchvision")34 _tensorflow_available, _tensorflow_version = get_package_info("tensorflow")35 _tensorflow_hub_available, _tensorflow_hub_version = get_package_info("tensorflow-hub")36 _yolov5_available, _yolov5_version = get_package_info("yolov5")37 _mmdet_available, _mmdet_version = get_package_info("mmdet")38 _mmcv_available, _mmcv_version = get_package_info("mmcv")39 _detectron2_available, _detectron2_version = get_package_info("detectron2")40 _transformers_available, _transformers_version = get_package_info("transformers")41 _timm_available, _timm_version = get_package_info("timm")42 _layer_available, _layer_version = get_package_info("layer")43 _fiftyone_available, _fiftyone_version = get_package_info("fiftyone")44 _norfair_available, _norfair_version = get_package_info("norfair")45def is_available(module_name: str):46 return importlib.util.find_spec(module_name) is not None47@contextlib.contextmanager48def check_requirements(package_names):49 """50 Raise error if module is not installed.51 """52 missing_packages = []53 for package_name in package_names:54 if importlib.util.find_spec(package_name) is None:55 missing_packages.append(package_name)56 if missing_packages:57 raise ImportError(f"The following packages are required to use this module: {missing_packages}")58 yield

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