How to use test_path_parts method in tox

Best Python code snippet using tox_python

timeseries.py

Source:timeseries.py Github

copy

Full Screen

1# Copyright 2018 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import collections5from cli_tools.soundwave import pandas_sqlite6from core.external_modules import pandas7TABLE_NAME = 'timeseries'8COLUMN_TYPES = (9 # Index columns.10 ('test_suite', str), # benchmark name ('loading.mobile')11 ('measurement', str), # metric name ('timeToFirstContentfulPaint')12 ('bot', str), # master/builder name ('ChromiumPerf.android-nexus5')13 ('test_case', str), # story name ('Wikipedia')14 ('point_id', 'int64'), # monotonically increasing id for time series axis15 # Other columns.16 ('value', 'float64'), # value recorded for test_path at given point_id17 ('timestamp', 'datetime64[ns]'), # when the value got stored on dashboard18 ('commit_pos', 'int64'), # chromium commit position19 ('chromium_rev', str), # git hash of chromium revision20 ('clank_rev', str), # git hash of clank revision21 ('trace_url', str), # URL to a sample trace.22 ('units', str), # unit of measurement (e.g. 'ms', 'bytes')23 ('improvement_direction', str), # good direction ('up', 'down', 'unknown')24)25COLUMNS = tuple(c for c, _ in COLUMN_TYPES)26INDEX = COLUMNS[:5]27# Copied from https://goo.gl/DzGYpW.28_CODE_TO_IMPROVEMENT_DIRECTION = {29 0: 'up',30 1: 'down',31}32TEST_PATH_PARTS = (33 'master', 'builder', 'test_suite', 'measurement', 'test_case')34# Query template to find all data points of a given test_path (i.e. fixed35# test_suite, measurement, bot, and test_case values).36_QUERY_TIME_SERIES = (37 'SELECT * FROM %s WHERE %s'38 % (TABLE_NAME, ' AND '.join('%s=?' % c for c in INDEX[:-1])))39# Required columns to request from /timeseries2 API.40_TIMESERIES2_COLS = [41 'revision',42 'revisions',43 'avg',44 'timestamp',45 'annotations']46class Key(collections.namedtuple('Key', INDEX[:-1])):47 """Uniquely identifies a single timeseries."""48 @classmethod49 def FromDict(cls, *args, **kwargs):50 kwargs = dict(*args, **kwargs)51 kwargs.setdefault('test_case', '') # test_case is optional.52 return cls(**kwargs)53 def AsDict(self):54 return dict(zip(self._fields, self))55 def AsApiParams(self):56 """Return a dict with params for a /timeseries2 API request."""57 params = self.AsDict()58 if not params['test_case']:59 del params['test_case'] # test_case is optional.60 params['columns'] = ','.join(_TIMESERIES2_COLS)61 return params62def DataFrame(rows=None):63 return pandas_sqlite.DataFrame(COLUMN_TYPES, index=INDEX, rows=rows)64def _ParseIntValue(value, on_error=-1):65 # Try to parse as int and, in case of error, return a pre-defined value.66 try:67 return int(value)68 except Exception:69 return on_error70def _ParseConfigFromTestPath(test_path):71 if isinstance(test_path, Key):72 return test_path.AsDict()73 values = test_path.split('/', len(TEST_PATH_PARTS) - 1)74 if len(values) < len(TEST_PATH_PARTS):75 values.append('') # Possibly missing test_case.76 if len(values) != len(TEST_PATH_PARTS):77 raise ValueError(test_path)78 config = dict(zip(TEST_PATH_PARTS, values))79 config['bot'] = '%s/%s' % (config.pop('master'), config.pop('builder'))80 return config81def DataFrameFromJson(test_path, data):82 if isinstance(test_path, Key):83 return _DataFrameFromJsonV2(test_path, data)84 else:85 # TODO(crbug.com/907121): Remove when we can switch entirely to v2.86 return _DataFrameFromJsonV1(test_path, data)87def _DataFrameFromJsonV2(ts_key, data):88 rows = []89 for point in data['data']:90 point = dict(zip(_TIMESERIES2_COLS, point))91 rows.append(ts_key + (92 point['revision'], # point_id93 point['avg'], # value94 point['timestamp'], # timestamp95 _ParseIntValue(point['revisions']['r_commit_pos']), # commit_pos96 point['revisions'].get('r_chromium'), # chromium_rev97 point['revisions'].get('r_clank'), # clank_rev98 point['annotations'].get('a_tracing_uri'), # trace_url99 data['units'], # units100 data['improvement_direction'], # improvement_direction101 ))102 return DataFrame(rows)103def _DataFrameFromJsonV1(test_path, data):104 # The dashboard API returns an empty list if there is no recent data for the105 # timeseries.106 if not data:107 return DataFrame()108 assert test_path == data['test_path']109 config = _ParseConfigFromTestPath(data['test_path'])110 config['improvement_direction'] = _CODE_TO_IMPROVEMENT_DIRECTION.get(111 data['improvement_direction'], 'unknown')112 timeseries = data['timeseries']113 # The first element in timeseries list contains header with column names.114 header = timeseries[0]115 rows = []116 # Remaining elements contain the values for each row.117 for values in timeseries[1:]:118 row = config.copy()119 row.update(zip(header, values))120 row['point_id'] = row['revision']121 row['commit_pos'] = _ParseIntValue(row['r_commit_pos'])122 row['chromium_rev'] = row.get('r_chromium')123 row['clank_rev'] = row.get('r_clank', None)124 rows.append(tuple(row.get(k) for k in COLUMNS))125 return DataFrame(rows)126def GetTimeSeries(con, test_path, extra_cond=None):127 """Get the records for all data points on the given test_path.128 Returns:129 A pandas.DataFrame with all records found.130 """131 config = _ParseConfigFromTestPath(test_path)132 params = tuple(config[c] for c in INDEX[:-1])133 query = _QUERY_TIME_SERIES134 if extra_cond is not None:135 query = ' '.join([query, extra_cond])136 return pandas.read_sql(query, con, params=params, parse_dates=['timestamp'])137def GetMostRecentPoint(con, test_path):138 """Find the record for the most recent data point on the given test_path.139 Returns:140 A pandas.Series with the record if found, or None otherwise.141 """142 df = GetTimeSeries(con, test_path, 'ORDER BY timestamp DESC LIMIT 1')...

Full Screen

Full Screen

local_extensions.py

Source:local_extensions.py Github

copy

Full Screen

1import urllib2from cookiecutter.utils import simple_filter3@simple_filter4def test_database_url(url):5 parsed_url = urllib.parse.urlparse(url)6 test_path_parts = parsed_url.path.split("/", 1)7 test_path_parts[1] = "test_" + test_path_parts[1]8 test_path = "/".join(test_path_parts)...

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