Best Python code snippet using autotest_python
SiteWiseTelemetry.py
Source: SiteWiseTelemetry.py
1# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 20212# SPDX-License-Identifier: Apache-2.03import boto34import logging5import time6import uuid7import json8import csv9import argparse10import os11import sys12LOGGER = logging.getLogger()13LOGGER.setLevel(logging.INFO)14sys.path.append(os.path.join(os.path.dirname(__file__), '../../../modules'))15from sitewise.lib.util.SiteWiseTelemetryUtils import SiteWiseTelemetryImporter16def parse_arguments():17 parser = argparse.ArgumentParser(18 description='Load telemetry data into IotSiteWise')19 subparser = parser.add_subparsers(dest='command')20 import_parser = subparser.add_parser('import')21 cleanup_parser = subparser.add_parser('cleanup')22 import_parser.add_argument('--csv-file',23 help='The csv file name',24 required=True)25 import_parser.add_argument('--aws-region',26 help='The aws region to store data in iotsitewise',27 required=False)28 import_parser.add_argument('--asset-model-name-prefix',29 help='Prefix of asset model name',30 required=True)31 import_parser.add_argument('--entity-include-pattern',32 help='Only import entities whose name/id include this string',33 required=False,34 default=None)35 cleanup_parser.add_argument('--aws-region',36 help='The aws region to store data in iotsitewise',37 required=False)38 cleanup_parser.add_argument('--asset-model-name-prefix',39 help='Prefix of asset mode name',40 required=True)41 cleanup_parser.add_argument('--entity-include-pattern',42 help='Only cleanup entities whose name/id include this string',43 required=False,44 default=None)45 return parser46def print_usage():47 print("""Usage: 48 Install lib to local first by:49 goto folder of $GETTING_STARTED_DIR/src/modules/sitewise/lib50 pip install .51 then in folder $GETTING_STARTED_DIR/src/libs/deploy_utils 52 To import csv file to iot sitewise,53 `python3 SiteWiseTelemetry.py import --csv-file ../../../workspaces/cookiefactory/sample_data/telemetry/telemetry.csv --asset-model-name-prefix CookieFactory` 54 To cleanup above dataset from sitewise,55 `python3 SiteWiseTelemetry.py cleanup --asset-model-name-prefix CookieFactory` 56 """)57def main():58 parser = parse_arguments()59 args = parser.parse_args()60 assetModelPrefix = args.asset_model_name_prefix61 print(args)62 entityIncludePattern = args.entity_include_pattern63 sitewiseImporter = SiteWiseTelemetryImporter(args.aws_region, asset_model_prefix=assetModelPrefix, entity_include_pattern=entityIncludePattern)64 if args.command == 'import':65 csvFile = args.csv_file66 sitewiseImporter.import_csv_to_sitewise(csvFile)67 elif args.command == 'cleanup':68 sitewiseImporter.cleanup_sitewise(assetModelPrefix)69 else: 70 print_usage()71if __name__ == '__main__':...
usn.py
Source: usn.py
1# --- BEGIN COPYRIGHT BLOCK ---2# Copyright (C) 2016-2017 Red Hat, Inc.3# All rights reserved.4#5# License: GPL (version 3 or any later version).6# See LICENSE for details.7# --- END COPYRIGHT BLOCK ---8from lib389.plugins import USNPlugin9from lib389.cli_conf.plugin import add_generic_plugin_parsers10def display_usn_mode(inst, basedn, log, args):11 plugin = USNPlugin(inst)12 if plugin.is_global_mode_set():13 log.info("USN global mode is enabled")14 else:15 log.info("USN global mode is disabled")16def enable_global_mode(inst, basedn, log, args):17 plugin = USNPlugin(inst)18 plugin.enable_global_mode()19 log.info("USN global mode enabled")20def disable_global_mode(inst, basedn, log, args):21 plugin = USNPlugin(inst)22 plugin.disable_global_mode()23 log.info("USN global mode disabled")24def tombstone_cleanup(inst, basedn, log, args):25 plugin = USNPlugin(inst)26 log.info('Attempting to add task entry... This will fail if replication is enabled or if USN plug-in is disabled.')27 task = plugin.cleanup(args.suffix, args.backend, args.maxusn)28 log.info('Successfully added task entry ' + task.dn)29def create_parser(subparsers):30 usn_parser = subparsers.add_parser('usn', help='Manage and configure USN plugin')31 subcommands = usn_parser.add_subparsers(help='action')32 add_generic_plugin_parsers(subcommands, USNPlugin)33 global_mode_parser = subcommands.add_parser('global', help='get or manage global usn mode')34 global_mode_parser.set_defaults(func=display_usn_mode)35 global_mode_subcommands = global_mode_parser.add_subparsers(help='action')36 on_global_mode_parser = global_mode_subcommands.add_parser('on', help='enable usn global mode')37 on_global_mode_parser.set_defaults(func=enable_global_mode)38 off_global_mode_parser = global_mode_subcommands.add_parser('off', help='disable usn global mode')39 off_global_mode_parser.set_defaults(func=disable_global_mode)40 cleanup_parser = subcommands.add_parser('cleanup', help='run the USN tombstone cleanup task')41 cleanup_parser.set_defaults(func=tombstone_cleanup)42 cleanup_group = cleanup_parser.add_mutually_exclusive_group(required=True)43 cleanup_group.add_argument('-s', '--suffix', help="suffix where USN tombstone entries are cleaned up")44 cleanup_group.add_argument('-n', '--backend', help="backend instance in which USN tombstone entries are cleaned up (alternative to suffix)")...
entrypoint.py
Source: entrypoint.py
1import sys2from src.cleanup.cleanup_cmd_helper import CleanupCommandHelper as Cleanup3def _cleanup(args):4 Cleanup.clean(args)5def register(parser):6 cleanup_parser = parser.add_parser('cleanup')7 cleanup_parser.add_argument('-i', '--intellij', help="intellij", action='store_true')8 cleanup_parser.add_argument('-n', '--npm', help="npm", action='store_true')9 cleanup_parser.add_argument('-a', '--artifacts', help="artifacts", action='store_true')10 cleanup_parser.add_argument('-d', '--docker', help="docker", action='store_true')11 cleanup_parser.set_defaults(func=_cleanup)12 if len(sys.argv) == 2 and 'cleanup' == sys.argv[1]:13 cleanup_parser.print_help()...
Check out the latest blogs from LambdaTest on this topic:
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.
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.
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.
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.
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.
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!!