How to use sometest method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

benchmark_results_unittest.py

Source:benchmark_results_unittest.py Github

copy

Full Screen

1# Copyright (C) 2015 Apple Inc. All rights reserved.2#3# Redistribution and use in source and binary forms, with or without4# modification, are permitted provided that the following conditions5# are met:6# 1. Redistributions of source code must retain the above copyright7# notice, this list of conditions and the following disclaimer.8# 2. Redistributions in binary form must reproduce the above copyright9# notice, this list of conditions and the following disclaimer in the10# documentation and/or other materials provided with the distribution.11#12# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY13# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED14# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE15# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY16# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES17# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;18# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON19# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT20# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS21# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.22import unittest23from benchmark_results import BenchmarkResults24class BenchmarkResultsTest(unittest.TestCase):25 def test_init(self):26 results = BenchmarkResults({'SomeTest': {'metrics': {'Time': {'current': [1, 2, 3]}}}})27 self.assertEqual(results._results, {'SomeTest': {'metrics': {'Time': {None: {'current': [1, 2, 3]}}}, 'tests': {}}})28 with self.assertRaisesRegexp(TypeError, r'"Time" metric of "SomeTest" contains non-numeric value: \[1, 2, "a"\]'):29 BenchmarkResults({'SomeTest': {'metrics': {'Time': {'current': [1, 2, 'a']}}}})30 def test_format(self):31 result = BenchmarkResults({'SomeTest': {'metrics': {'Time': {'current': [1, 2, 3]}}}})32 self.assertEqual(result.format(), 'SomeTest:Time: 2.0ms stdev=50.0%\n')33 result = BenchmarkResults({'SomeTest': {'metrics': {'Time': {'current': [1, 2, 3]}, 'Score': {'current': [2, 3, 4]}}}})34 self.assertEqual(result.format(), '''35SomeTest:Score: 3.0pt stdev=33.3%36 :Time: 2.0ms stdev=50.0%37'''[1:])38 result = BenchmarkResults({'SomeTest': {39 'metrics': {'Time': ['Total', 'Arithmetic']},40 'tests': {41 'SubTest1': {'metrics': {'Time': {'current': [1, 2, 3]}}},42 'SubTest2': {'metrics': {'Time': {'current': [4, 5, 6]}}}}}})43 self.assertEqual(result.format(), '''44SomeTest:Time:Arithmetic: 3.0ms stdev=33.3%45 :Time:Total: 7.0ms stdev=28.6%46 SubTest1:Time: 2.0ms stdev=50.0%47 SubTest2:Time: 5.0ms stdev=20.0%48'''[1:])49 def test_format_values_with_large_error(self):50 self.assertEqual(BenchmarkResults._format_values('Runs', [1, 2, 3]), '2.0/s stdev=50.0%')51 self.assertEqual(BenchmarkResults._format_values('Runs', [10, 20, 30]), '20/s stdev=50.0%')52 self.assertEqual(BenchmarkResults._format_values('Runs', [100, 200, 300]), '200/s stdev=50.0%')53 self.assertEqual(BenchmarkResults._format_values('Runs', [1000, 2000, 3000]), '2.0K/s stdev=50.0%')54 self.assertEqual(BenchmarkResults._format_values('Runs', [10000, 20000, 30000]), '20K/s stdev=50.0%')55 self.assertEqual(BenchmarkResults._format_values('Runs', [100000, 200000, 300000]), '200K/s stdev=50.0%')56 self.assertEqual(BenchmarkResults._format_values('Runs', [1000000, 2000000, 3000000]), '2.0M/s stdev=50.0%')57 self.assertEqual(BenchmarkResults._format_values('Runs', [0.1, 0.2, 0.3]), '200m/s stdev=50.0%')58 self.assertEqual(BenchmarkResults._format_values('Runs', [0.01, 0.02, 0.03]), '20m/s stdev=50.0%')59 self.assertEqual(BenchmarkResults._format_values('Runs', [0.001, 0.002, 0.003]), '2.0m/s stdev=50.0%')60 self.assertEqual(BenchmarkResults._format_values('Runs', [0.0001, 0.0002, 0.0003]), '200u/s stdev=50.0%')61 self.assertEqual(BenchmarkResults._format_values('Runs', [0.00001, 0.00002, 0.00003]), '20u/s stdev=50.0%')62 self.assertEqual(BenchmarkResults._format_values('Runs', [0.000001, 0.000002, 0.000003]), '2.0u/s stdev=50.0%')63 def test_format_values_with_small_error(self):64 self.assertEqual(BenchmarkResults._format_values('Runs', [1.1, 1.2, 1.3]), '1.20/s stdev=8.3%')65 self.assertEqual(BenchmarkResults._format_values('Runs', [11, 12, 13]), '12.0/s stdev=8.3%')66 self.assertEqual(BenchmarkResults._format_values('Runs', [110, 120, 130]), '120/s stdev=8.3%')67 self.assertEqual(BenchmarkResults._format_values('Runs', [1100, 1200, 1300]), '1.20K/s stdev=8.3%')68 self.assertEqual(BenchmarkResults._format_values('Runs', [11000, 12000, 13000]), '12.0K/s stdev=8.3%')69 self.assertEqual(BenchmarkResults._format_values('Runs', [110000, 120000, 130000]), '120K/s stdev=8.3%')70 self.assertEqual(BenchmarkResults._format_values('Runs', [1100000, 1200000, 1300000]), '1.20M/s stdev=8.3%')71 self.assertEqual(BenchmarkResults._format_values('Runs', [0.11, 0.12, 0.13]), '120m/s stdev=8.3%')72 self.assertEqual(BenchmarkResults._format_values('Runs', [0.011, 0.012, 0.013]), '12.0m/s stdev=8.3%')73 self.assertEqual(BenchmarkResults._format_values('Runs', [0.0011, 0.0012, 0.0013]), '1.20m/s stdev=8.3%')74 self.assertEqual(BenchmarkResults._format_values('Runs', [0.00011, 0.00012, 0.00013]), '120u/s stdev=8.3%')75 self.assertEqual(BenchmarkResults._format_values('Runs', [0.000011, 0.000012, 0.000013]), '12.0u/s stdev=8.3%')76 self.assertEqual(BenchmarkResults._format_values('Runs', [0.0000011, 0.0000012, 0.0000013]), '1.20u/s stdev=8.3%')77 def test_format_values_with_time(self):78 self.assertEqual(BenchmarkResults._format_values('Time', [1, 2, 3]), '2.0ms stdev=50.0%')79 self.assertEqual(BenchmarkResults._format_values('Time', [10, 20, 30]), '20ms stdev=50.0%')80 self.assertEqual(BenchmarkResults._format_values('Time', [100, 200, 300]), '200ms stdev=50.0%')81 self.assertEqual(BenchmarkResults._format_values('Time', [1000, 2000, 3000]), '2.0s stdev=50.0%')82 self.assertEqual(BenchmarkResults._format_values('Time', [10000, 20000, 30000]), '20s stdev=50.0%')83 self.assertEqual(BenchmarkResults._format_values('Time', [100000, 200000, 300000]), '200s stdev=50.0%')84 self.assertEqual(BenchmarkResults._format_values('Time', [0.11, 0.12, 0.13]), '120us stdev=8.3%')85 self.assertEqual(BenchmarkResults._format_values('Time', [0.011, 0.012, 0.013]), '12.0us stdev=8.3%')86 self.assertEqual(BenchmarkResults._format_values('Time', [0.0011, 0.0012, 0.0013]), '1.20us stdev=8.3%')87 self.assertEqual(BenchmarkResults._format_values('Time', [0.00011, 0.00012, 0.00013]), '120ns stdev=8.3%')88 def test_format_values_with_no_error(self):89 self.assertEqual(BenchmarkResults._format_values('Time', [1, 1, 1]), '1.00ms stdev=0.0%')90 def test_format_values_with_small_difference(self):91 self.assertEqual(BenchmarkResults._format_values('Time', [5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]),92 '4.05ms stdev=5.5%')93 def test_aggregate_results(self):94 self.maxDiff = None95 self.assertEqual(BenchmarkResults._aggregate_results(96 {'SomeTest': {'metrics': {'Time': {'current': [1, 2, 3]}}}}),97 {'SomeTest': {'metrics': {'Time': {None: {'current': [1, 2, 3]}}}, 'tests': {}}})98 self.assertEqual(BenchmarkResults._aggregate_results(99 {'SomeTest': {100 'metrics': {'Time': ['Total']},101 'tests': {102 'SubTest1': {'metrics': {'Time': {'current': [1, 2, 3]}}},103 'SubTest2': {'metrics': {'Time': {'current': [4, 5, 6]}}}}}}),104 {'SomeTest': {105 'metrics': {'Time': {'Total': {'current': [5, 7, 9]}}},106 'tests': {107 'SubTest1': {'metrics': {'Time': {None: {'current': [1, 2, 3]}}}, 'tests': {}},108 'SubTest2': {'metrics': {'Time': {None: {'current': [4, 5, 6]}}}, 'tests': {}}}}})109 self.assertEqual(BenchmarkResults._aggregate_results(110 {'SomeTest': {111 'metrics': {'Time': ['Total'], 'Runs': ['Total']},112 'tests': {113 'SubTest1': {'metrics': {'Time': {'current': [1, 2, 3]}}},114 'SubTest2': {'metrics': {'Time': {'current': [4, 5, 6]}}},115 'SubTest3': {'metrics': {'Runs': {'current': [7, 8, 9]}}}}}}),116 {'SomeTest': {117 'metrics': {118 'Time': {'Total': {'current': [5, 7, 9]}},119 'Runs': {'Total': {'current': [7, 8, 9]}}},120 'tests': {121 'SubTest1': {'metrics': {'Time': {None: {'current': [1, 2, 3]}}}, 'tests': {}},122 'SubTest2': {'metrics': {'Time': {None: {'current': [4, 5, 6]}}}, 'tests': {}},123 'SubTest3': {'metrics': {'Runs': {None: {'current': [7, 8, 9]}}}, 'tests': {}}}}})124 def test_aggregate_results_with_gropus(self):125 self.maxDiff = None126 self.assertEqual(BenchmarkResults._aggregate_results(127 {'SomeTest': {128 'metrics': {'Time': ['Total']},129 'tests': {130 'SubTest1': {'metrics': {'Time': {'current': [[1, 2], [3, 4]]}}},131 'SubTest2': {'metrics': {'Time': {'current': [[5, 6], [7, 8]]}}}}}}),132 {'SomeTest': {133 'metrics': {'Time': {'Total': {'current': [6, 8, 10, 12]}}},134 'tests': {135 'SubTest1': {'metrics': {'Time': {None: {'current': [1, 2, 3, 4]}}}, 'tests': {}},136 'SubTest2': {'metrics': {'Time': {None: {'current': [5, 6, 7, 8]}}}, 'tests': {}}}}})137 def test_aggregate_nested_results(self):138 self.maxDiff = None139 self.assertEqual(BenchmarkResults._aggregate_results(140 {'SomeTest': {141 'metrics': {'Time': ['Total']},142 'tests': {143 'SubTest1': {144 'metrics': {'Time': ['Total']},145 'tests': {146 'GrandChild1': {'metrics': {'Time': {'current': [1, 2]}}},147 'GrandChild2': {'metrics': {'Time': {'current': [3, 4]}}}}},148 'SubTest2': {'metrics': {'Time': {'current': [5, 6]}}}}}}),149 {'SomeTest': {150 'metrics': {'Time': {'Total': {'current': [9, 12]}}},151 'tests': {152 'SubTest1': {153 'metrics': {'Time': {'Total': {'current': [4, 6]}}},154 'tests': {155 'GrandChild1': {'metrics': {'Time': {None: {'current': [1, 2]}}}, 'tests': {}},156 'GrandChild2': {'metrics': {'Time': {None: {'current': [3, 4]}}}, 'tests': {}}}},157 'SubTest2': {'metrics': {'Time': {None: {'current': [5, 6]}}}, 'tests': {}}}}})158 self.assertEqual(BenchmarkResults._aggregate_results(159 {'SomeTest': {160 'metrics': {'Time': ['Total']},161 'tests': {162 'SubTest1': {163 'metrics': {'Time': ['Total', 'Arithmetic']},164 'tests': {165 'GrandChild1': {'metrics': {'Time': {'current': [1, 2]}}},166 'GrandChild2': {'metrics': {'Time': {'current': [3, 4]}}}}},167 'SubTest2': {'metrics': {'Time': {'current': [5, 6]}}}}}}),168 {'SomeTest': {169 'metrics': {'Time': {'Total': {'current': [9, 12]}}},170 'tests': {171 'SubTest1': {172 'metrics': {'Time': {'Total': {'current': [4, 6]}, 'Arithmetic': {'current': [2, 3]}}},173 'tests': {174 'GrandChild1': {'metrics': {'Time': {None: {'current': [1, 2]}}}, 'tests': {}},175 'GrandChild2': {'metrics': {'Time': {None: {'current': [3, 4]}}}, 'tests': {}}}},176 'SubTest2': {'metrics': {'Time': {None: {'current': [5, 6]}}}, 'tests': {}}}}})177 def test_lint_results(self):178 with self.assertRaisesRegexp(TypeError, r'"SomeTest" does not contain metrics or tests'):179 BenchmarkResults._lint_results({'SomeTest': {}})180 with self.assertRaisesRegexp(TypeError, r'The metrics in "SomeTest" is not a dictionary'):181 BenchmarkResults._lint_results({'SomeTest': {'metrics': []}})182 with self.assertRaisesRegexp(TypeError, r'The aggregator list is empty in "Time" metric of "SomeTest"'):183 BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': []}}})184 with self.assertRaisesRegexp(TypeError, r'"Time" metric of "SomeTest" is not wrapped by a configuration; e.g. "current"'):185 BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': [1, 2]}}})186 self.assertTrue(BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': {'current': [1, 2]}}}}))187 with self.assertRaisesRegexp(TypeError, r'"Time" metric of "SomeTest" was not an aggregator list or a dictionary of configurations: 1'):188 BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': 1}}})189 with self.assertRaisesRegexp(TypeError, r'"Time" metric of "SomeTest" contains non-numeric value: \["Total"\]'):190 BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': {'current': ['Total']}}}})191 with self.assertRaisesRegexp(TypeError, r'"Time" metric of "SomeTest" contains non-numeric value: \["Total", "Geometric"\]'):192 BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': {'current': [['Total', 'Geometric']]}}}})193 with self.assertRaisesRegexp(TypeError, r'"SomeTest" requires aggregation but "SomeTest" has no subtests'):194 BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': ['Total']}}})195 with self.assertRaisesRegexp(TypeError, r'"Time" metric of "SomeTest" had invalid aggregator list: \["Total", "Total"\]'):196 BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': ['Total', 'Total']}, 'tests': {197 'SubTest1': {'metrics': {'Time': {'current': []}}}}}})198 with self.assertRaisesRegexp(TypeError, r'"Time" metric of "SomeTest" uses unknown aggregator: KittenMean'):199 BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': ['KittenMean']}, 'tests': {200 'SubTest1': {'metrics': {'Time': {'current': []}}}}}})201 with self.assertRaisesRegexp(TypeError, r'"Time" metric of "SomeTest" had a mismatching subtest values'):202 BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': ['Total']}, 'tests': {203 'SubTest1': {'metrics': {'Time': {'current': [1, 2, 3]}}},204 'SubTest2': {'metrics': {'Time': {'current': [4, 5, 6, 7]}}}}}})205 with self.assertRaisesRegexp(TypeError, r'"Time" metric of "SomeTest" had a mismatching subtest values'):206 BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': ['Total']}, 'tests': {207 'SubTest1': {'metrics': {'Time': {'current': [[1, 2], [3]]}}},208 'SubTest2': {'metrics': {'Time': {'current': [[4, 5], [6, 7]]}}}}}})209 with self.assertRaisesRegexp(TypeError, r'"Time" metric of "SomeTest" had malformed values: \[1, \[2\], 3\]'):210 BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': {'current': [1, [2], 3]}}}})211 self.assertTrue(BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': ['Total']}, 'tests': {212 'SubTest1': {'metrics': {'Time': {'current': [1, 2, 3]}}},213 'SubTest2': {'metrics': {'Time': {'current': [4, 5, 6], 'baseline': [7]}}}}}}))214 self.assertTrue(BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': ['Total']}, 'tests': {215 'SubTest1': {'metrics': {'Time': {'current': [1, 2, 3]}}},216 'SubTest2': {'metrics': {'Runs': {'current': [4, 5, 6, 7]}}}}}}))217 self.assertTrue(BenchmarkResults._lint_results({'SomeTest': {'metrics': {'Time': ['Total']}, 'tests': {218 'SubTest1': {'metrics': {'Time': {'current': [[1, 2], [3, 4]]}}},...

Full Screen

Full Screen

intro.py

Source:intro.py Github

copy

Full Screen

1import unittest2"""3Let's PyUnit.4http://www.drdobbs.com/testing/unit-testing-with-python/2401651635"""6class SomeTest(unittest.TestCase):7 def setUp(self):8 print "SomeTest:setUp_:begin"9 print "do something for set up"10 print "SomeTest:setUp_:end"11 def tearDown(self):12 print "SomeTest:teardown_:begin"13 print "do something for tear down"14 print "SomeTest:teardown_:end"15 def testA(self):16 print "in SomeTest:testA"17 def testB(self):18 print "in SomeTest:testB"19if __name__ == '__main__':...

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