Best Python code snippet using autotest_python
api.py
Source: api.py
1import copy2import itertools3import logging4import string5from performanceplatform.client import DataSet6import requests7from .data import SmartAnswer8import settings9logger = logging.getLogger(__name__)10class PerformancePlatform(object):11 """12 Handles GETting and POSTing data to and from the Performance Platform.13 This class uses the PerformancePlatform Client, which will retry14 handling GET and POST requests up to five times, if their status15 codes are 502 or 503. If they still don't succeed, the client16 raises an exception that is not handled by us.17 """18 date_format = "%Y-%m-%dT00:00:00Z"19 def __init__(self, pp_token, start_date, end_date):20 self.pp_token = pp_token21 # Format dates here so that they won't be accidentally used as22 # non-midnight datetimes elsewhere in the class:23 self.start_date = start_date.strftime(self.date_format)24 self.end_date = end_date.strftime(self.date_format)25 def get_problem_report_counts(self):26 logger.info('Getting problem report counts')27 results_by_letter = [self._get_problem_report_counts_for_paths_starting_with('/' + letter)28 for letter in string.lowercase]29 all_results = list(itertools.chain(*results_by_letter))30 return {result["pagePath"].encode('utf-8'): result["total:sum"]31 for result in all_results}32 def get_search_counts(self):33 logger.info('Getting search counts')34 results_by_letter = [self._get_search_counts_for_paths_starting_with('/' + letter)35 for letter in string.lowercase]36 all_results = list(itertools.chain(*results_by_letter))37 return {result["pagePath"].encode('utf-8'): result["searchUniques:sum"]38 for result in all_results}39 def get_unique_pageviews(self, paths):40 logger.info('Getting pageview counts')41 return {path: self.get_unique_pageviews_for_path(path) for path in paths}42 def get_unique_pageviews_for_path(self, path):43 data = self._get_pp_data('page-statistics', 'uniquePageviews:sum',44 filter_by=path)45 if data and data[0]['uniquePageviews:sum']:46 return int(data[0]['uniquePageviews:sum'])47 def save_aggregated_results(self, results):48 data_set = DataSet.from_group_and_type(settings.DATA_DOMAIN,49 settings.DATA_GROUP,50 settings.RESULTS_DATASET,51 token=self.pp_token)52 enriched_results = [self._enrich_mandatory_pp_fields(result)53 for result in results]54 logger.info('Posting data to Performance Platform')55 data_set.post(enriched_results)56 def _get_problem_report_counts_for_paths_starting_with(self, path_prefix):57 return self._get_pp_data('page-contacts', 'total:sum',58 filter_by_prefix=path_prefix)59 def _get_search_counts_for_paths_starting_with(self, path_prefix):60 return self._get_pp_data('search-terms', 'searchUniques:sum',61 filter_by_prefix=path_prefix)62 def _enrich_mandatory_pp_fields(self, result):63 enriched_result = copy.copy(result.as_dict())64 enriched_result['_timestamp'] = self.end_date65 enriched_result['_start_at'] = self.start_date66 enriched_result['_end_at'] = self.end_date67 return enriched_result68 def _get_pp_data(self, dataset_name, value,69 filter_by=None, filter_by_prefix=None):70 dataset = DataSet.from_group_and_type(settings.DATA_DOMAIN,71 settings.DATA_GROUP,72 dataset_name)73 query_parameters = {74 'group_by': 'pagePath',75 'period': 'day',76 'start_at': self.start_date,77 'end_at': self.end_date,78 'collect': value,79 }80 if filter_by:81 query_parameters['filter_by'] = 'pagePath:' + filter_by82 elif filter_by_prefix:83 query_parameters['filter_by_prefix'] = 'pagePath:' + filter_by_prefix84 logger.debug('Getting {0} data with params {1}'.format(dataset_name, query_parameters))85 json_data = dataset.get(query_parameters)86 if 'data' in json_data:87 return json_data['data']88 else:89 return []90class GOVUK(object):91 def get_smart_answers(self):92 """Get all smart answers, from the Search API."""93 logger.info('Getting smart answers')94 smart_answers = []95 url = 'https://www.gov.uk/api/search.json'96 url += '?filter_format=smart-answer'97 url += '&filter_format=simple_smart_answer'98 url += '&start=0&count=1000&fields=link'99 try:100 r = requests.get(url)101 if r.status_code == 200:102 results = r.json()['results']103 return [SmartAnswer(result['link'].encode('utf-8')) for result in results]104 else:105 logger.error('Received %d status code when getting smartanswers from %s',106 r.status_code, url)107 except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError) as e:...
practice 03.py
Source: practice 03.py
...7 'cherry',8 'charlie',9]1011def filter_by_prefix(words, prefix):12 '''13 prefixë¡ ììíë word를 린í´í©ëë¤. 1415 >>> filter_by_prefix(words, 'a')16 'apple'17 '''18 19 # ìë ì½ë를 ìì±íì¸ì.20 21 22 return [i for i in words if i.startswith(prefix)]232425# ìë 주ìì í´ì íê³ ê²°ê³¼ë¥¼ íì¸í´ë³´ì¸ì. 26a_words = filter_by_prefix(words, 'a')27print(a_words)28293031'''32í ì¤ ëª
ë ¹ì´ë¡ ë°ì´í° ë¤ë£¨ê¸°33íì´ì¬ì ê°ì¥ í° ì¥ì ì¤ íëë ê°ê²°í ì½ëì
ëë¤. for문ì 리ì¤í¸ ìì ì
ë ¥íë©´ ìë¡ì´ 리ì¤í¸ë¥¼ ì½ë í ì¤ë¡ ê°ê²°íê² ìì±í ì ììµëë¤. ìëì ë ì½ëë ëì¼íê² ìëí©ëë¤.34'''3536'''37ë°ì´í° ë¶ìì ìì©í기38Noneì ìì íê³ ë¨ì´ 모ì wordsìì prefixë¡ ììíë ë¨ì´ë§ 리í´íë filter_by_prefix í¨ì를 ìì±íì¸ì.
...
canonical_solution_29.py
Source: canonical_solution_29.py
1from typing import List234def filter_by_prefix(strings: List[str], prefix: str) -> List[str]:5 """ Filter an input list of strings only for ones that start with a given prefix.6 >>> filter_by_prefix([], 'a')7 []8 >>> filter_by_prefix(['abc', 'bcd', 'cde', 'array'], 'a')9 ['abc', 'array']10 """
...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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!!