Best Python code snippet using tox_python
test_report_metric.py
Source: test_report_metric.py
...9def test_main():10 assert report_metric # use your library here11def test_setup_reporter_defaults(set_librato_credentials):12 # Librato is our default without config for the moment13 assert isinstance(metric.setup_reporter(), reporter.LibratoReport)14def test_setup_reporter_from_parameter(set_librato_credentials):15 rep = metric.setup_reporter('librato')16 assert isinstance(rep, reporter.LibratoReport)17 rep = metric.setup_reporter('direct')18 assert isinstance(rep, reporter.DirectReport)19 rep = metric.setup_reporter('dummy')20 assert isinstance(rep, reporter.DummyReport)21def test_setup_non_existent_reporter():22 with pytest.raises(reporter.StatsReportException):23 rep = metric.setup_reporter('no-such-reporter')24# TODO, source shouldn't be unique to librato25def test_set_source_from_parameter(set_librato_credentials):26 rep = metric.setup_reporter('librato', 'custom_source')27 assert rep.source == 'custom_source'28def test_set_source_from_env_setting():29 os.environ['METRICS_SOURCE'] = 'environ_source' # probably should cleanup, but...30 rep = metric.setup_reporter('librato')31 assert rep.source == 'environ_source'32def test_set_source_from_env_setting_when_passing_none():33 os.environ['METRICS_SOURCE'] = 'environ_source2' # probably should cleanup, but...34 rep = metric.setup_reporter('librato', None)35 assert rep.source == 'environ_source2'36# Smoke tests to make sure "frontend" side of module is handing off to backend37@patch("report_metric.metric.setup_reporter")38def test_gauge(mock_setup_reporter):39 mock_reporter = MagicMock(spec=reporter.ReportBase)40 mock_setup_reporter.return_value = mock_reporter41 # Try42 metric.gauge("mocked-gauge", 22)43 # Verify44 mock_reporter.gauge.assert_called_once_with("mocked-gauge", 22)45# Smoke tests to make sure "frontend" side of module is handing off to backend46@patch("report_metric.metric.setup_reporter")47def test_counter(mock_setup_reporter):48 mock_reporter = MagicMock(spec=reporter.ReportBase)49 mock_setup_reporter.return_value = mock_reporter50 # Try51 metric.counter("mocked-counter")52 # Verify53 mock_reporter.counter.assert_called_once_with("mocked-counter", 1) # we expect one unless other is passed54@patch("report_metric.metric.setup_reporter")55def test_specific_source(mock_setup_reporter):56 mock_reporter = MagicMock(spec=reporter.ReportBase)57 mock_setup_reporter.return_value = mock_reporter58 metric.gauge("mocked-gauge", 123, source="one-off-source")59 mock_reporter.gauge.assert_called_once_with("mocked-gauge", 123) # we expect one unless other is passed60 mock_setup_reporter.assert_called_once_with(None, "one-off-source") # as as setup_reporter is sent the parameter, other test make sure it's used61# TODO better tests, these are barely smoke tests62@pytest.mark.skip("Breaks on credentials at the moment")63def test_librato_gauge(set_librato_credentials):64 rep = metric.setup_reporter('librato')65 rep.gauge("Test.SubmissionLibratoCheck", 1)66def test_direct_gauge_submission():67 rep = metric.setup_reporter('direct')...
metric.py
Source: metric.py
2from celery.task import task3from report_metric import reporter4from report_metric import settings5logging.basicConfig(level=logging.DEBUG)6def setup_reporter(destination=None, source=None):7 destination = destination or settings.get('METRICS_DESTINATION', 'librato')8 source = source or settings.get('METRICS_SOURCE', None)9 if destination == 'librato' and reporter.LIBRATO and settings.get('METRICS_LIBRATO_USER'):10 return reporter.LibratoReport(username=settings.get('METRICS_LIBRATO_USER'),11 api_key=settings.get('METRICS_LIBRATO_TOKEN'),12 source=source)13 elif destination == 'direct':14 return reporter.DirectReport()15 elif destination == 'dummy':16 return reporter.DummyReport()17 raise reporter.StatsReportException('No available/configured destination') # maybe not right exception18def gauge(name, number, **kwargs):19 '''20 Helper method for single call sending of a gauge21 :param name: metric name22 :param number: metric number23 :param destination: optional, if not sending to default24 :return:25 '''26 if settings.get('METRICS_USE_CELERY', False):27 _report_gauge.delay(name, number, **kwargs)28 else:29 _report_gauge(name, number, **kwargs)30def counter(name, number=1, **kwargs):31 '''32 Helper method for single call sending of a counter33 :param name: metric name34 :param number: metric number35 :param destination: optional, if not sending to default36 :return:37 '''38 if settings.get('METRICS_USE_CELERY', False):39 _report_counter.delay(name, number, **kwargs)40 else:41 _report_counter(name, number, **kwargs)42# There's got to be a more elegant way to conditionally wrap a function in Task, but for the moment43@task(name='report_metric.gauge')44def _report_gauge(name, number, **kwargs):45 try:46 rep = setup_reporter(kwargs.get('destination', None), kwargs.get('source', None))47 rep.gauge(name, number)48 except reporter.StatsReportException as e:49 logging.exception(str(e))50@task(name='report_metric.counter')51def _report_counter(name, number=1, **kwargs):52 try:53 setup_reporter(kwargs.get('destination', None), kwargs.get('source', None)).counter(name, number)54 except reporter.StatsReportException as e:...
setup.py
Source: setup.py
...16 app.include_router(customer_api.customer_api, prefix="/customer", tags=["Customer"])17 app.include_router(manager_api.manager_api, prefix="/manager", tags=["Manager"])18 app.state.repository = setup_sql_lite_repository()19 app.state.terminal = setup_terminal(app.state.repository)20 app.state.manager_reporter = setup_reporter(setup_x_report(app.state.repository))21 app.state.point_of_sales = setup_pos(app.state.terminal, app.state.manager_reporter)22 return app23# Setup Service Beans24def setup_pos(25 terminal: TerminalInteractor, reporter: ReporterInteractor26) -> PointOfSales:27 return PointOfSales(terminal, reporter)28def setup_sql_lite_repository() -> SqlLiteRepository:29 return SqlLiteRepository(DB_LOCATION)30def setup_terminal(repository: ITerminalRepository) -> TerminalInteractor:31 return TerminalInteractor(repository)32def setup_x_report(repository: IReporterRepository) -> IReportCommand:33 return XReportCommand(repository)34def setup_reporter(x_report: IReportCommand) -> ReporterInteractor:...
Check out the latest blogs from LambdaTest on this topic:
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).
Mobile devices and mobile applications – both are booming in the world today. The idea of having the power of a computer in your pocket is revolutionary. As per Statista, mobile accounts for more than half of the web traffic worldwide. Mobile devices (excluding tablets) contributed to 54.4 percent of global website traffic in the fourth quarter of 2021, increasing consistently over the past couple of years.
Even though several frameworks are available in the market for automation testing, Selenium is one of the most renowned open-source frameworks used by experts due to its numerous features and benefits.
JUnit is one of the most popular unit testing frameworks in the Java ecosystem. The JUnit 5 version (also known as Jupiter) contains many exciting innovations, including support for new features in Java 8 and above. However, many developers still prefer to use the JUnit 4 framework since certain features like parallel execution with JUnit 5 are still in the experimental phase.
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!!