How to use add_testcase method in autotest

Best Python code snippet using autotest_python

test_tapdoc.py

Source:test_tapdoc.py Github

copy

Full Screen

...16 self.assertEquals(doc.version, 13)17 doc = TapDocument(skip=True)18 self.assertTrue(doc.skip)19 doc.add_plan(1, 1)20 doc.add_testcase(TapTestcase())21 self.assertIn(u'skip', unicode(doc).lower())22 def testSet(self):23 doc = TapDocument()24 doc.set_version(12)25 self.assertEquals(doc.version, 12)26 doc.set_skip('this test expired')27 self.assertTrue(doc.skip)28 doc.set_skip(False)29 self.assertFalse(doc.skip)30 def testAdd(self):31 doc = TapDocument()32 doc.add_plan(1, 5, u'SKIP wip')33 self.assertIn(u'wip', unicode(doc))34 self.assertIn(u'1..5', unicode(doc))35 tc = TapTestcase()36 tc.field = True37 tc.number = 138 tc.description = 'TC #1'39 tc.data = [">>> int('88t')",40 "Traceback (most recent call last):",41 ' File "<stdin>", line 1, in <module>',42 "ValueError: invalid literal for int() with base 10: '88t'",43 {'locals': ['int']}]44 doc.add_testcase(tc)45 self.assertIn(u'wip', unicode(doc))46 self.assertIn(u'1..5', unicode(doc))47 self.assertNotIn(u'...', unicode(doc))48 self.assertIn(u'88t', unicode(doc))49 self.assertIn(u'locals', unicode(doc))50 doc.add_bailout(TapBailout('Filesystem crashed'))51 self.assertIn(u'Bail out! Filesystem crashed', unicode(doc))52 def testAddHeaderLine(self):53 doc = TapDocument()54 doc.add_plan(1, 0)55 doc.add_version_line(12)56 self.assertEquals(doc.version, 12)57 doc.add_header_line('Hello World')58 doc.add_header_line('Embrace!')59 self.assertIn(u'Hello World', unicode(doc))60 self.assertIn(u'Embrace!', unicode(doc))61 def testLength(self):62 doc = TapDocument()63 doc.add_plan(3, 7)64 doc.add_testcase(TapTestcase())65 doc.add_testcase(TapTestcase())66 doc.add_bailout(TapBailout('FS problem'))67 self.assertEquals(len(doc), 5)68 self.assertEquals(doc.actual_length(), 2)69 def testRangeAndPlan(self):70 doc = TapDocument()71 self.assertEquals(doc.range(), (1, 0))72 self.assertEquals(doc.actual_range(), (1, 0))73 self.assertEquals(doc.plan(), '1..0')74 self.assertEquals(doc.actual_plan(), '1..0')75 doc.add_plan(3, 7)76 self.assertEquals(doc.range(), (3, 7))77 self.assertEquals(doc.actual_range(), (1, 0))78 self.assertEquals(doc.plan(), '3..7')79 self.assertEquals(doc.actual_plan(), '1..0')80 doc.add_testcase(TapTestcase())81 doc.add_testcase(TapTestcase())82 doc.add_bailout(TapBailout('FS problem'))83 self.assertEquals(doc.range(), (3, 7))84 self.assertEquals(doc.actual_range(), (3, 4))85 self.assertEquals(doc.plan(), '3..7')86 self.assertEquals(doc.actual_plan(), '3..4')87 def testIn(self):88 doc = TapDocument()89 doc.add_plan(1, 3)90 self.assertFalse(1 in doc)91 self.assertFalse(2 in doc)92 self.assertFalse(42 in doc)93 doc.add_testcase(TapTestcase())94 doc.add_testcase(TapTestcase())95 self.assertTrue(1 in doc)96 self.assertTrue(2 in doc)97 self.assertFalse(3 in doc)98 tc = TapTestcase()99 tc.number = 3100 doc.add_testcase(tc)101 self.assertTrue(1 in doc)102 self.assertTrue(2 in doc)103 self.assertTrue(3 in doc)104 self.assertFalse(4 in doc)105 self.assertFalse(5 in doc)106 self.assertFalse(6 in doc)107 def testIndexing(self):108 doc = TapDocument()109 doc.add_plan(1, 10)110 tc1 = TapTestcase()111 tc1.number = 1112 tc1.field = True113 tc1.description = "First testcase"114 tc2 = TapTestcase()115 tc2.field = True116 tc2.description = "Second testcase"117 tc3 = TapTestcase()118 tc3.number = 4119 tc3.field = False120 tc3.description = "Fourth testcase"121 tc4 = TapTestcase()122 tc4.field = True123 tc4.description = "Third testcase"124 tc5 = TapTestcase()125 tc5.field = True126 tc5.description = "Fifth testcase"127 doc.add_testcase(tc1)128 doc.add_testcase(tc2)129 doc.add_testcase(tc3)130 doc.add_testcase(tc4)131 doc.add_bailout(TapBailout('raising bailout'))132 doc.add_testcase(tc5)133 self.assertEquals(doc[1], tc1)134 self.assertEquals(doc[2], tc2)135 self.assertEquals(doc[3], tc4)136 self.assertEquals(doc[4], tc3)137 self.assertEquals(doc[5], tc5)138 self.assertEquals(doc[6], None)139 self.assertEquals(doc[10], None)140 self.assertRaises(IndexError, lambda: doc[0])141 self.assertRaises(IndexError, lambda: doc[11])142 self.assertRaises(IndexError, lambda: doc[256])143 def testCount(self):144 doc = TapDocument()145 tc1 = TapTestcase()146 tc1.field = True147 tc1.todo = True148 doc.add_testcase(tc1)149 tc2 = TapTestcase()150 tc2.field = False151 tc2.todo = True152 doc.add_testcase(tc2)153 tc3 = TapTestcase()154 tc3.field = False155 tc3.todo = True156 tc3.skip = True157 doc.add_testcase(tc3)158 tc4 = TapTestcase()159 tc4.field = True160 doc.add_testcase(tc4)161 self.assertEquals(doc.count_not_ok(), 2)162 self.assertEquals(doc.count_todo(), 3)163 self.assertEquals(doc.count_skip(), 1)164 def testBailout(self):165 doc = TapDocument()166 self.assertFalse(doc.bailed())167 doc.add_testcase(TapTestcase())168 self.assertFalse(doc.bailed())169 doc.add_bailout(TapBailout('FS crash'))170 self.assertTrue(doc.bailed())171 doc.add_bailout(TapBailout('Another crash'))172 self.assertTrue(doc.bailed())173 self.assertEquals(doc.bailout_message(), 'FS crash')174 def testValid(self):175 # valid iff176 # no bailout was thrown AND177 # document itself is skipped OR178 # all TCs exist AND179 # are 'ok' OR180 # skipped181 # default182 doc = TapDocument()183 doc.add_plan(1, 0)184 self.assertTrue(doc.valid())185 # bailout186 # must work without a plan187 doc.set_skip('Hello World')188 doc.add_bailout(TapBailout('filesystem problem'))189 self.assertFalse(doc.valid())190 # skipped191 doc = TapDocument()192 tc = TapTestcase()193 tc.field = False194 doc.add_testcase(tc)195 doc.add_plan(1, 1)196 doc.set_skip(True)197 self.assertTrue(doc.valid())198 # all tcs are ok199 doc = TapDocument()200 doc.add_testcase(TapTestcase(field=True))201 doc.add_testcase(TapTestcase(field=True))202 doc.add_testcase(TapTestcase(field=True))203 doc.add_testcase(TapTestcase(field=True))204 doc.add_plan(1, 4)205 self.assertTrue(doc.valid())206 # all tcs are ok207 doc = TapDocument()208 true_tc = TapTestcase()209 true_tc.field = True210 false_tc = TapTestcase()211 false_tc.field = False212 doc.add_testcase(true_tc)213 doc.add_testcase(true_tc)214 doc.add_testcase(true_tc)215 doc.add_testcase(false_tc)216 doc.add_plan(1, 4)217 self.assertFalse(doc.valid())218 # all tcs are skipped219 tc = TapTestcase()220 tc.field = False221 tc.skip = u'Only testable in enterprise environment'222 doc = TapDocument()223 doc.set_skip(False)224 doc.add_testcase(tc)225 doc.add_testcase(tc)226 doc.add_testcase(tc)227 doc.add_testcase(tc)228 doc.add_testcase(tc)229 doc.add_plan(1, 5)230 self.assertTrue(doc.valid())231 doc.add_bailout(TapBailout('System crashed'))232 self.assertFalse(doc.valid())233class TestTapDocumentIterator(unittest.TestCase):234 def testIterWithoutBailout(self):235 description = ['a', 'b', 'c', 'd']236 doc = TapDocument()237 tc = TapTestcase()238 doc.add_plan(1, 20)239 for d in range(4):240 tc.description = description[d] # use immutability property241 doc.add_testcase(tc)242 iterations = 0243 for d, tc in enumerate(iter(doc)):244 if d < 4:245 self.assertEquals(tc.description, description[d])246 else:247 self.assertIsNone(tc)248 iterations += 1249 for d, tc in enumerate(TapDocumentIterator(doc)):250 if d < 4:251 self.assertEquals(tc.description, description[d])252 else:253 self.assertIsNone(tc)254 iterations += 1255 self.assertEquals(iterations, 40)256 def testIter(self):257 description = ['a', 'b', 'c', 'd']258 doc = TapDocument()259 tc = TapTestcase()260 doc.add_plan(1, 20)261 for d in range(4):262 tc.description = description[d] # use immutability property263 doc.add_testcase(tc)264 if d == 2:265 doc.add_bailout(TapBailout("failure"))266 iterations = 0267 try:268 for d, tc in enumerate(iter(doc)):269 self.assertEquals(tc.description, description[d])270 iterations += 1271 except TapBailout:272 pass273 try:274 for d, tc in enumerate(TapDocumentIterator(doc)):275 self.assertEquals(tc.description, description[d])276 iterations += 1277 except TapBailout:278 pass279 self.assertEquals(iterations, 6)280class TestTapDocumentActualIterator(unittest.TestCase):281 def testIter(self):282 description = ['a', 'b', 'c', 'd']283 doc = TapDocument()284 tc = TapTestcase()285 doc.add_plan(1, 20)286 for d in range(4):287 tc.description = description[d]288 doc.add_testcase(tc)289 if d == 2:290 doc.add_bailout(TapBailout('failure'))291 def iterate(doc):292 iterations = 0293 try:294 for d, tc in enumerate(TapDocumentActualIterator(doc)):295 self.assertEquals(tc.description, description[d])296 iterations += 1297 except TapBailout:298 return iterations299 return iterations300 self.assertEquals(iterate(doc), 3)301 def testIterWithoutBailout(self):302 description = ['a', 'b', 'c', 'd']303 doc = TapDocument()304 tc = TapTestcase()305 doc.add_plan(1, 20)306 for d in range(4):307 tc.description = description[d]308 doc.add_testcase(tc)309 iterations = 0310 for d, tc in enumerate(TapDocumentActualIterator(doc)):311 self.assertEquals(tc.description, description[d])312 iterations += 1313 self.assertEquals(iterations, 4)314class TestTapDocumentFailedIterator(unittest.TestCase):315 def testIter(self):316 doc = TapDocument()317 doc.add_plan(1, 25)318 for i in range(20):319 tc = TapTestcase()320 tc.field = (i % 2 == 1)321 doc.add_testcase(tc)322 if i == 15:323 doc.add_bailout(TapBailout('fail'))324 iterations = 0325 for d, tc in enumerate(TapDocumentFailedIterator(doc)):326 self.assertFalse(tc.field)327 iterations += 1328 self.assertEquals(iterations, 10)329class TestTapParsing(unittest.TestCase):330 pass331class TestTapContextManager(unittest.TestCase):332 def testWrapper(self):333 with TapDocument() as tap:334 tap.plan(1, 4)335 tap.ok("a fine testcase").not_ok("a failed testcase")...

Full Screen

Full Screen

generate_matrix_testvector.py

Source:generate_matrix_testvector.py Github

copy

Full Screen

...5 return "0" * 646 w, sign = (float.hex(x), 0) if x > 0 else (float.hex(x)[1:], 1)7 mantissa, exp = int(w[4:17], 16), int(w[18:])8 return "{}{:011b}{:052b}".format(sign, exp + 1023, mantissa)9def add_testcase(input_matrix, input_vector):10 testvector_row = ""11 for row in range(4):12 for col in range(4):13 testvector_row += float_to_bin(input_matrix[row, col]) + "_"14 for col in range(4):15 testvector_row += float_to_bin(input_vector[col]) + "_"16 target_vector = input_matrix.dot(input_vector)17 for col in range(3):18 testvector_row += float_to_bin(target_vector[col]) + "_"19 testvector_row += float_to_bin(target_vector[3])20 f.write(testvector_row + "\n")21# Specific edge cases to test 22# The identity matrix multiplying a vector should output the same vector.23identity_matrix = np.eye(4, dtype=float)24add_testcase(identity_matrix, np.arange(4, dtype=float))25# The zero matrix multiplying a vector should result in a zero vector.26zero_matrix = np.zeros((4,4), dtype=float)27add_testcase(zero_matrix, np.arange(4, dtype=float))28# Check that the zero vector results in a zero vector output.29zero_vector = np.zeros(4, dtype=float)30add_testcase(identity_matrix, zero_vector)31def generate_random_cases(number_cases):32 for i in range(number_cases):33 rand_matrix = np.random.rand(4,4)34 rand_vector = np.random.rand(4)35 add_testcase(rand_matrix, rand_vector)36generate_random_cases(10)...

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