How to use test_clock method in pytest-benchmark

Best Python code snippet using pytest-benchmark

test_sampling.py

Source: test_sampling.py Github

copy

Full Screen

1# ==================================================================================================2# Copyright 2013 Twitter, Inc.3# --------------------------------------------------------------------------------------------------4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this work except in compliance with the License.6# You may obtain a copy of the License in the LICENSE file, or at:7#8# http:/​/​www.apache.org/​licenses/​LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15# ==================================================================================================16import os17import pytest18from twitter.common.contextutil import temporary_file19from twitter.common.metrics import Label20from twitter.common.metrics.metrics import Metrics21from twitter.common.metrics.sampler import (22 MetricSampler,23 SamplerBase,24 DiskMetricWriter,25 DiskMetricReader)26from twitter.common.quantity import Amount, Time27from twitter.common.testing.clock import ThreadedClock28def test_sampler_base():29 class TestSampler(SamplerBase):30 def __init__(self, period, clock):31 self.count = 032 SamplerBase.__init__(self, period, clock)33 def iterate(self):34 self.count += 135 test_clock = ThreadedClock()36 sampler = TestSampler(Amount(1, Time.SECONDS), clock=test_clock)37 sampler.start()38 assert test_clock.converge(threads=[sampler])39 test_clock.assert_waiting(sampler, 1)40 test_clock.tick(0.5)41 assert test_clock.converge(threads=[sampler])42 assert sampler.count == 043 test_clock.tick(0.5)44 assert test_clock.converge(threads=[sampler])45 assert sampler.count == 146 test_clock.tick(5)47 assert test_clock.converge(threads=[sampler])48 assert sampler.count == 649 assert not sampler.is_stopped()50 sampler.stop()51 # make sure that stopping the sampler short circuits any sampling52 test_clock.tick(5)53 assert test_clock.converge(threads=[sampler])54 assert sampler.count == 655def test_metric_read_write():56 metrics = Metrics()57 with temporary_file() as fp:58 os.unlink(fp.name)59 writer = DiskMetricWriter(metrics, fp.name)60 reader = DiskMetricReader(fp.name)61 assert reader.sample() == {}62 reader.iterate()63 assert reader.sample() == {}64 writer.iterate()65 assert reader.sample() == {}66 reader.iterate()67 assert reader.sample() == {}68 metrics.register(Label('herp', 'derp'))69 writer.iterate()70 assert reader.sample() == {}71 reader.iterate()72 assert reader.sample() == {'herp': 'derp'}73def test_metric_sample():74 metrics = Metrics()75 sampler = MetricSampler(metrics)76 assert sampler.sample() == {}77 sampler.iterate()78 assert sampler.sample() == {}79 metrics.register(Label('herp', 'derp'))80 assert sampler.sample() == {}81 sampler.iterate()...

Full Screen

Full Screen

test_clock_model.py

Source: test_clock_model.py Github

copy

Full Screen

1import pytest2from clockzy.lib.models.clock import Clock3from clockzy.lib.db.database_interface import item_exists4from clockzy.lib.test_framework.database import intratime_user_parameters, clock_parameters5from clockzy.lib.db.db_schema import CLOCK_TABLE6from clockzy.lib.handlers.codes import SUCCESS, ITEM_ALREADY_EXISTS7# Pytest tierdown fixture is executed from righ to left position8@pytest.mark.parametrize('user_parameters, clock_parameters', [(intratime_user_parameters, clock_parameters)])9def test_save_clock(add_pre_user, delete_post_user, delete_post_clock):10 test_clock = Clock(**clock_parameters)11 # Add the clock and check that 1 row has been affected (no exception when running)12 assert test_clock.save() == SUCCESS13 clock_parameters['id'] = test_clock.id14 # If we try to add the same CLOCK, check that it can not be inserted15 assert test_clock.save() == ITEM_ALREADY_EXISTS16 # Query and check that the clock exist17 assert item_exists({'id': test_clock.id}, CLOCK_TABLE)18@pytest.mark.parametrize('user_parameters, clock_parameters', [(intratime_user_parameters, clock_parameters)])19def test_update_clock(add_pre_user, add_pre_clock, delete_post_user, delete_post_clock):20 test_clock = Clock(**clock_parameters)21 test_clock.id = add_pre_clock22 clock_parameters['id'] = test_clock.id23 # Update the clock info and check that 1 row has been affected (no exception when running)24 test_clock.action = 'OUT'25 assert test_clock.update() == SUCCESS26 # Query and check that the clock exist27 assert item_exists({'id': test_clock.id, 'action': 'OUT'}, CLOCK_TABLE)28@pytest.mark.parametrize('user_parameters, clock_parameters', [(intratime_user_parameters, clock_parameters)])29def test_delete_clock(add_pre_user, add_pre_clock, delete_post_user):30 test_clock = Clock(**clock_parameters)31 test_clock.id = add_pre_clock32 clock_parameters['id'] = test_clock.id33 # Delete the clock info and check that 1 row has been affected (no exception when running)34 assert test_clock.delete() == SUCCESS35 # Query and check that the clock does not exist...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

What is coaching leadership

Coaching is a term that is now being mentioned a lot more in the leadership space. Having grown successful teams I thought that I was well acquainted with this subject.

Webinar: Move Forward With An Effective Test Automation Strategy [Voices of Community]

The key to successful test automation is to focus on tasks that maximize the return on investment (ROI), ensuring that you are automating the right tests and automating them in the right way. This is where test automation strategies come into play.

Are Agile Self-Managing Teams Realistic with Layered Management?

Agile software development stems from a philosophy that being agile means creating and responding to change swiftly. Agile means having the ability to adapt and respond to change without dissolving into chaos. Being Agile involves teamwork built on diverse capabilities, skills, and talents. Team members include both the business and software development sides working together to produce working software that meets or exceeds customer expectations continuously.

A Complete Guide To CSS Grid

Ever since the Internet was invented, web developers have searched for the most efficient ways to display content on web browsers.

Get A Seamless Digital Experience With #LambdaTestYourBusiness????

The holidays are just around the corner, and with Christmas and New Year celebrations coming up, everyone is busy preparing for the festivities! And during this busy time of year, LambdaTest also prepped something special for our beloved developers and testers – #LambdaTestYourBusiness

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 pytest-benchmark 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