Best Python code snippet using tempest_python
einsum_op_test.py
Source: einsum_op_test.py
...30from tensorflow.python.ops import variables31from tensorflow.python.platform import benchmark32from tensorflow.python.platform import test33class EinsumOpTest(test.TestCase):34 def _check(self, s, *input_shapes, **kwargs):35 dtype = kwargs.pop('dtype', np.float32)36 r = np.random.RandomState(0)37 inputs = []38 for shape in input_shapes:39 arr = np.array(r.randn(*shape)).astype(dtype)40 if dtype == np.complex64 or dtype == np.complex128:41 arr += 1j * np.array(r.randn(*shape)).astype(dtype)42 inputs.append(arr)43 input_tensors = [constant_op.constant(x, shape=x.shape) for x in inputs]44 a = np.einsum(s, *inputs)45 b = self.evaluate(gen_linalg_ops.einsum(input_tensors, s))46 self.assertAllClose(a, b, atol=1e-4, rtol=1e-4)47 def testUnary(self):48 self._check('->', ())49 self._check('ab->', (3, 3))50 self._check('ab->ab', (3, 3))51 self._check('abc->b', (3, 4, 5))52 self._check('abc->ca', (3, 4, 5))53 self._check('abc->cab', (3, 4, 5))54 def testUnaryWithRepeatedLabels(self):55 self._check('aa->', (3, 3))56 self._check('aa->a', (3, 3))57 self._check('aaa->', (3, 3, 3))58 self._check('aaa->a', (3, 3, 3))59 self._check('aab->a', (3, 3, 4))60 self._check('aabcc->a', (3, 3, 5, 4, 4))61 self._check('aabcc->ac', (3, 3, 5, 4, 4))62 self._check('aabcd->ad', (3, 3, 5, 4, 4))63 def testUnaryEllipsis(self):64 # Unary cases with ellipsis.65 # Edge cases.66 self._check('...->...', ())67 self._check('...->', ())68 self._check('->...', ())69 # Tests from dask70 self._check('a...a->a...', (2, 2))71 self._check('a...a->', (2, 2))72 self._check('a...a->...', (2, 5, 1, 2))73 self._check('a...a->a...', (2, 1, 2))74 self._check('a...a->a...', (2, 3, 4, 5, 2))75 # Regular cases.76 self._check('...ijk->...ki', (3, 4, 5))77 self._check('...ijk->...ki', (1, 3, 4, 5))78 self._check('...ijk->...ki', (2, 2, 3, 4, 5))79 # Repeated indices.80 self._check('i...ii->...i', (3, 2, 3, 3))81 def testBinarySimple(self):82 # Binary cases in XLA mode must have either (a) each index appearing exactly83 # once in both the inputs (batch or contraction index), or (b) appearing84 # exactly once in an input and in the output (free index).85 self._check(',->', (), ())86 self._check('a,a->', (3,), (3,))87 self._check('a,a->a', (3,), (3,))88 self._check('ab,b->a', (3, 4), (4,))89 self._check('ab,ab->', (3, 4), (3, 4))90 self._check('ab,bc->ac', (3, 4), (4, 5))91 self._check('nij,jk->nik', (5, 2, 3), (3, 4))92 self._check('abc,bad->abcd', (1, 2, 3), (2, 1, 4))93 # Based on https://github.com/google/jax/issues/37#issuecomment-44857218794 self._check('sa,shb->shab', (2, 1), (2, 3, 4))95 def testReducedIndices(self):96 self._check('ba,b->', (3, 2), (3,))97 self._check('ab,ab->', (3, 4), (3, 4))98 self._check('abce,badf->abcd', (1, 2, 3, 4), (2, 1, 4, 3))99 def testRepeatedIndices(self):100 # Repeated indices.101 self._check('ijj,k->ik', (2, 3, 3), (4,))102 self._check('aba,a->b', (3, 4, 3), (3,))103 # From https://github.com/dask/dask/pull/3412#discussion_r182413444104 self._check('aab,bc->ac', (2, 2, 3), (3, 4))105 self._check('aab,bcc->ac', (2, 2, 3), (3, 4, 4))106 def testEllipsis(self):107 # Batch matmul with ellipsis but without broadcasting.108 self._check('...mk,...kn->...mn', (5, 1, 2, 3), (5, 1, 3, 4))109 # Empty batch dimensions.110 self._check('...mk,...kn->...mn', (2, 3), (3, 4))111 # Tensor contraction with transpose.112 self._check('...ija,aijb...->ba...ij', (1, 2, 2, 3, 1), (1, 2, 3, 4, 1, 2))113 # Output subscripts may omit ellipsis when batch shape is empty.114 self._check('...mk,...kn->mn', (2, 3), (3, 4))115 self._check('...mk,kn->mn', (2, 3), (3, 4))116 self._check('mk,...kn->mn', (2, 3), (3, 4))117 def testBroadcasting(self):118 # Batch matmul with broadcasting.119 self._check('...ij,...jk->...ik', (1, 2, 3), (3, 5))120 self._check('...ij,...jk->...ik', (2, 3), (1, 3, 5))121 self._check('...ij,...jk->...ik', (5, 2, 3), (3, 5))122 self._check('...ij,...jk->...ik', (2, 3), (5, 3, 5))123 self._check('...ij,...jk->...ik', (3, 1, 2, 3), (1, 1, 7, 3, 5))124 self._check('i...j,j...k->...ik', (2, 1, 3, 1, 3), (3, 1, 7, 5))125 # Following 2 from https://stackoverflow.com/a/19203475/1611416126 self._check('...abc,...abcd->...d', (1, 1, 2, 3, 4), (5, 2, 3, 4, 6))127 self._check('ab...,b->ab...', (2, 3, 1, 1, 5), (3,))128 self._check('i...j,j...k->i...k', (3, 1, 2, 2), (2, 2, 3, 1, 4))129 def testBroadcastingWithRepeatedIndices(self):130 # Broadcasting with repeated indices.131 self._check('ij,jk...k->i...', (3, 2), (2, 4, 1, 4))132 self._check('ij,jk...k->...i', (3, 2), (2, 4, 5, 4))133 self._check('ijj,jk...k->i...', (3, 2, 2), (2, 4, 1, 4))134 self._check('i...jj,jk...k->i...', (3, 3, 1, 2, 2), (2, 4, 1, 5, 4))135 def testDtypes(self):136 bfloat16 = dtypes.bfloat16.as_numpy_dtype137 def check(dtype):138 r = np.random.RandomState(0)139 equation = 'ij,jk->ik'140 input_shapes = [(2, 2), (2, 2)]141 inputs = []142 for shape in input_shapes:143 arr = np.array(r.randn(*shape)).astype(dtype)144 if dtype == np.complex64 or dtype == np.complex128:145 arr += 1j * np.array(r.randn(*shape)).astype(dtype)146 inputs.append(arr)147 input_tensors = [constant_op.constant(x) for x in inputs]148 if dtype == bfloat16:...
test_medical_uom.py
Source: test_medical_uom.py
1# Copyright 2021 Creu Blanca2# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).3from odoo.tests.common import TransactionCase4class TestMedicalUom(TransactionCase):5 def _check(self, origin, destiny, original_qty, expected_qty):6 base_uom = self.env.ref("medical_diagnostic_report.%s" % origin)7 compute_uom = self.env.ref("medical_diagnostic_report.%s" % destiny)8 self.assertAlmostEqual(9 base_uom._compute_quantity(original_qty, compute_uom),10 expected_qty,11 places=2,12 )13 def test_rate(self):14 self._check("uom_rate", "uom_percentage", 1, 100)15 self._check("uom_percentage", "uom_rate", 200, 2)16 def test_density(self):17 self._check("uom_gram_liter", "uom_gram_deciliter", 10, 1)18 self._check("uom_gram_deciliter", "uom_gram_liter", 2, 20)19 self._check("uom_gram_liter", "uom_milligram_deciliter", 1, 100)20 self._check("uom_milligram_deciliter", "uom_gram_liter", 100, 1)21 self._check("uom_gram_deciliter", "uom_milligram_deciliter", 1, 1000)22 self._check("uom_milligram_deciliter", "uom_gram_deciliter", 2000, 2)23 self._check("uom_gram_liter", "uom_milligram_liter", 1, 1000)24 self._check("uom_milligram_liter", "uom_gram_liter", 2000, 2)25 def test_concentration(self):26 self._check(27 "uom_million_micro_liter", "uom_ten_thousand_micro_liter", 1, 10028 )29 self._check(30 "uom_ten_thousand_micro_liter", "uom_million_micro_liter", 200, 231 )32 self._check(33 "uom_million_micro_liter", "uom_thousand_micro_liter", 1, 100034 )35 self._check(36 "uom_thousand_micro_liter", "uom_million_micro_liter", 2000, 237 )38 self._check(39 "uom_million_micro_liter", "uom_hundred_micro_liter", 1, 1000040 )41 self._check(42 "uom_hundred_micro_liter", "uom_million_micro_liter", 20000, 243 )44 self._check(45 "uom_ten_thousand_micro_liter", "uom_thousand_micro_liter", 1, 1046 )47 self._check(48 "uom_thousand_micro_liter", "uom_ten_thousand_micro_liter", 20, 249 )50 self._check(51 "uom_ten_thousand_micro_liter", "uom_hundred_micro_liter", 1, 10052 )53 self._check(54 "uom_hundred_micro_liter", "uom_ten_thousand_micro_liter", 200, 255 )56 self._check(57 "uom_thousand_micro_liter", "uom_hundred_micro_liter", 1, 1058 )59 self._check(60 "uom_hundred_micro_liter", "uom_thousand_micro_liter", 20, 261 )62 def test_concentration_water(self):63 self._check("uom_litre_litre", "uom_millilitre_litre", 1, 1000)64 self._check("uom_millilitre_litre", "uom_litre_litre", 2000, 2)65 def test_concentration_molar(self):66 self._check("uom_mol_litre", "uom_millimol_litre", 1, 1000)67 self._check("uom_millimol_litre", "uom_mol_litre", 2000, 2)68 def test_mol(self):69 self._check("uom_mol", "uom_femto_mol", 0.001, 1000000000000)70 self._check("uom_femto_mol", "uom_mol", 2000000000000000, 2)71 self._check("uom_mol", "uom_atto_mol", 0.000001, 1000000000000)72 self._check("uom_atto_mol", "uom_mol", 2000000000000000000, 2)73 self._check("uom_femto_mol", "uom_atto_mol", 1, 1000)74 self._check("uom_atto_mol", "uom_femto_mol", 2000, 2)75 def test_time_month_year(self):76 self._check("uom_hour", "uom_day", 24, 1)77 self._check("uom_day", "uom_hour", 2, 48)78 self._check("uom_hour", "uom_week", 168, 1)79 self._check("uom_week", "uom_hour", 2, 336)80 self._check("uom_day", "uom_week", 7, 1)81 self._check("uom_week", "uom_day", 2, 14)82 def test_time_hour_day_week(self):83 self._check("uom_month", "uom_year", 12, 1)84 self._check("uom_year", "uom_month", 1, 12)85 def test_femto_litre(self):86 base_uom = self.env.ref("uom.product_uom_litre")87 compute_uom = self.env.ref("medical_diagnostic_report.uom_femto_litre")88 self.assertAlmostEqual(89 base_uom._compute_quantity(0.001, compute_uom),90 1000000000000,91 places=2,92 )93 base_uom = self.env.ref("medical_diagnostic_report.uom_femto_litre")94 compute_uom = self.env.ref("uom.product_uom_litre")95 self.assertAlmostEqual(96 base_uom._compute_quantity(2000000000000000, compute_uom),97 2,98 places=2,...
decorator_utils_test.py
Source: decorator_utils_test.py
...31 def test_function(self):32 self.assertEqual("_test_function",33 decorator_utils.get_qualified_name(_test_function))34class AddNoticeToDocstringTest(test.TestCase):35 def _check(self, doc, expected):36 self.assertEqual(37 decorator_utils.add_notice_to_docstring(38 doc=doc,39 instructions="Instructions",40 no_doc_str="Nothing here",41 suffix_str="(suffix)",42 notice=["Go away"]),43 expected)44 def test_regular(self):45 expected = (46 "Brief (suffix)\n\nWarning: Go away\nInstructions\n\nDocstring\n\n"47 "Args:\n arg1: desc")48 # No indent for main docstring49 self._check("Brief\n\nDocstring\n\nArgs:\n arg1: desc", expected)50 # 2 space indent for main docstring, blank lines not indented51 self._check("Brief\n\n Docstring\n\n Args:\n arg1: desc", expected)52 # 2 space indent for main docstring, blank lines indented as well.53 self._check("Brief\n \n Docstring\n \n Args:\n arg1: desc", expected)54 # No indent for main docstring, first line blank.55 self._check("\n Brief\n \n Docstring\n \n Args:\n arg1: desc",56 expected)57 # 2 space indent, first line blank.58 self._check("\n Brief\n \n Docstring\n \n Args:\n arg1: desc",59 expected)60 def test_brief_only(self):61 expected = "Brief (suffix)\n\nWarning: Go away\nInstructions"62 self._check("Brief", expected)63 self._check("Brief\n", expected)64 self._check("Brief\n ", expected)65 self._check("\nBrief\n ", expected)66 self._check("\n Brief\n ", expected)67 def test_no_docstring(self):68 expected = "Nothing here\n\nWarning: Go away\nInstructions"69 self._check(None, expected)70 self._check("", expected)71 def test_no_empty_line(self):72 expected = "Brief (suffix)\n\nWarning: Go away\nInstructions\n\nDocstring"73 # No second line indent74 self._check("Brief\nDocstring", expected)75 # 2 space second line indent76 self._check("Brief\n Docstring", expected)77 # No second line indent, first line blank78 self._check("\nBrief\nDocstring", expected)79 # 2 space second line indent, first line blank80 self._check("\n Brief\n Docstring", expected)81class ValidateCallableTest(test.TestCase):82 def test_function(self):83 decorator_utils.validate_callable(_test_function, "test")84 def test_method(self):85 decorator_utils.validate_callable(self.test_method, "test")86 def test_callable(self):87 class TestClass(object):88 def __call__(self):89 pass90 decorator_utils.validate_callable(TestClass(), "test")91 def test_partial(self):92 partial = functools.partial(_test_function, unused_arg=7)93 decorator_utils.validate_callable(partial, "test")94 def test_fail_non_callable(self):...
Check out the latest blogs from LambdaTest on this topic:
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
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!!