Best Python code snippet using autotest_python
cow.py
Source:cow.py
...167 ('dict', {})168 ])169 with self.checkReportsWarning("Warning: If you aren't going to change any of the values call with True."):170 b_gen = b.iteritems()171 self.assertTupleEqual(next(b_gen), ('a', 'a'))172 self.assertTupleEqual(next(b_gen), ('b', 'b'))173 self.assertTupleEqual(next(b_gen), ('c', 'b'))174 with self.checkReportsWarning("Warning: Doing a copy because dict is a mutable type."):175 self.assertTupleEqual(next(b_gen), ('dict', {}))176 with self.assertRaises(StopIteration):177 next(b_gen)178 b['dict']['a'] = 'b'179 b['a'] = 'c'180 self.checkStrOutput(a, 1, 4)181 self.checkStrOutput(b, 2, 3)182 with self.checkReportsWarning("Warning: If you aren't going to change any of the values call with True."):183 self.assertListEqual(list(a.iteritems()),184 [('a', 'a'),185 ('b', 'b'),186 ('dict', {})187 ])188 with self.checkReportsWarning("Warning: If you aren't going to change any of the values call with True."):189 b_gen = b.iteritems()190 self.assertTupleEqual(next(b_gen), ('a', 'c'))191 self.assertTupleEqual(next(b_gen), ('b', 'b'))192 self.assertTupleEqual(next(b_gen), ('c', 'b'))193 self.assertTupleEqual(next(b_gen), ('dict', {'a': 'b'}))194 with self.assertRaises(StopIteration):195 next(b_gen)196 with self.assertRaises(KeyError):197 print(b["dict2"])198 a['set'] = COWSetBase()199 a['set'].add("o1")200 a['set'].add("o1")201 a['set'].add("o2")202 self.assertSetEqual(set(a['set'].itervalues()), {"o1", "o2"})203 self.assertSetEqual(set(b['set'].itervalues()), {"o1", "o2"})204 b['set'].add('o3')205 self.assertSetEqual(set(a['set'].itervalues()), {"o1", "o2"})206 self.assertSetEqual(set(b['set'].itervalues()), {"o1", "o2", "o3"})207 a['set2'] = set()208 a['set2'].add("o1")209 a['set2'].add("o1")210 a['set2'].add("o2")211 # We don't expect 'a' to change anymore212 def check_a():213 with self.checkReportsWarning("Warning: If you aren't going to change any of the values call with True."):214 a_gen = a.iteritems()215 self.assertTupleEqual(next(a_gen), ('a', 'a'))216 self.assertTupleEqual(next(a_gen), ('b', 'b'))217 self.assertTupleEqual(next(a_gen), ('dict', {}))218 self.assertTupleEqual(next(a_gen), ('set2', {'o1', 'o2'}))219 a_sub_set = next(a_gen)220 self.assertEqual(a_sub_set[0], 'set')221 self.checkStrOutput(a_sub_set[1], 1, 2)222 self.assertSetEqual(set(a_sub_set[1].itervalues()), {'o1', 'o2'})223 check_a()224 b_gen = b.iteritems(readonly=True)225 self.assertTupleEqual(next(b_gen), ('a', 'c'))226 self.assertTupleEqual(next(b_gen), ('b', 'b'))227 self.assertTupleEqual(next(b_gen), ('c', 'b'))228 self.assertTupleEqual(next(b_gen), ('dict', {'a': 'b'}))229 self.assertTupleEqual(next(b_gen), ('set2', {'o1', 'o2'}))230 b_sub_set = next(b_gen)231 self.assertEqual(b_sub_set[0], 'set')232 self.checkStrOutput(b_sub_set[1], 2, 1)233 self.assertSetEqual(set(b_sub_set[1].itervalues()), {'o1', 'o2', 'o3'})234 del b['b']235 with self.assertRaises(KeyError):236 print(b['b'])237 self.assertFalse('b' in b)238 check_a()239 b.__revertitem__('b')240 check_a()241 self.assertEqual(b['b'], 'b')242 self.assertTrue('b' in b)243 b.__revertitem__('dict')244 check_a()245 b_gen = b.iteritems(readonly=True)246 self.assertTupleEqual(next(b_gen), ('a', 'c'))247 self.assertTupleEqual(next(b_gen), ('b', 'b'))248 self.assertTupleEqual(next(b_gen), ('c', 'b'))249 self.assertTupleEqual(next(b_gen), ('dict', {}))250 self.assertTupleEqual(next(b_gen), ('set2', {'o1', 'o2'}))251 b_sub_set = next(b_gen)252 self.assertEqual(b_sub_set[0], 'set')253 self.checkStrOutput(b_sub_set[1], 2, 1)254 self.assertSetEqual(set(b_sub_set[1].itervalues()), {'o1', 'o2', 'o3'})255 self.checkStrOutput(a, 1, 6)256 self.checkStrOutput(b, 2, 3)257 def testSetMethods(self):258 s = COWSetBase()259 with self.assertRaises(TypeError):260 print(s.iteritems())261 with self.assertRaises(TypeError):...
scopes_test.py
Source:scopes_test.py
...74 func1_kwargs = {'a': 1, 'b': None, 'c': [1]}75 with self.test_session():76 with scopes.arg_scope([func1], a=1, b=None, c=[1]):77 args, kwargs = func1(0)78 self.assertTupleEqual(args, func1_args)79 self.assertDictEqual(kwargs, func1_kwargs)80 def testSimpleArgScopeWithTuple(self):81 func1_args = (0,)82 func1_kwargs = {'a': 1, 'b': None, 'c': [1]}83 with self.test_session():84 with scopes.arg_scope((func1,), a=1, b=None, c=[1]):85 args, kwargs = func1(0)86 self.assertTupleEqual(args, func1_args)87 self.assertDictEqual(kwargs, func1_kwargs)88 def testOverwriteArgScope(self):89 func1_args = (0,)90 func1_kwargs = {'a': 1, 'b': 2, 'c': [1]}91 with scopes.arg_scope([func1], a=1, b=None, c=[1]):92 args, kwargs = func1(0, b=2)93 self.assertTupleEqual(args, func1_args)94 self.assertDictEqual(kwargs, func1_kwargs)95 def testNestedArgScope(self):96 func1_args = (0,)97 func1_kwargs = {'a': 1, 'b': None, 'c': [1]}98 with scopes.arg_scope([func1], a=1, b=None, c=[1]):99 args, kwargs = func1(0)100 self.assertTupleEqual(args, func1_args)101 self.assertDictEqual(kwargs, func1_kwargs)102 func1_kwargs['b'] = 2103 with scopes.arg_scope([func1], b=2):104 args, kwargs = func1(0)105 self.assertTupleEqual(args, func1_args)106 self.assertDictEqual(kwargs, func1_kwargs)107 def testSharedArgScope(self):108 func1_args = (0,)109 func1_kwargs = {'a': 1, 'b': None, 'c': [1]}110 with scopes.arg_scope([func1, func2], a=1, b=None, c=[1]):111 args, kwargs = func1(0)112 self.assertTupleEqual(args, func1_args)113 self.assertDictEqual(kwargs, func1_kwargs)114 args, kwargs = func2(0)115 self.assertTupleEqual(args, func1_args)116 self.assertDictEqual(kwargs, func1_kwargs)117 def testSharedArgScopeTuple(self):118 func1_args = (0,)119 func1_kwargs = {'a': 1, 'b': None, 'c': [1]}120 with scopes.arg_scope((func1, func2), a=1, b=None, c=[1]):121 args, kwargs = func1(0)122 self.assertTupleEqual(args, func1_args)123 self.assertDictEqual(kwargs, func1_kwargs)124 args, kwargs = func2(0)125 self.assertTupleEqual(args, func1_args)126 self.assertDictEqual(kwargs, func1_kwargs)127 def testPartiallySharedArgScope(self):128 func1_args = (0,)129 func1_kwargs = {'a': 1, 'b': None, 'c': [1]}130 func2_args = (1,)131 func2_kwargs = {'a': 1, 'b': None, 'd': [2]}132 with scopes.arg_scope([func1, func2], a=1, b=None):133 with scopes.arg_scope([func1], c=[1]), scopes.arg_scope([func2], d=[2]):134 args, kwargs = func1(0)135 self.assertTupleEqual(args, func1_args)136 self.assertDictEqual(kwargs, func1_kwargs)137 args, kwargs = func2(1)138 self.assertTupleEqual(args, func2_args)139 self.assertDictEqual(kwargs, func2_kwargs)140if __name__ == '__main__':...
test_cifar.py
Source:test_cifar.py
...7 @skipUnlessRunDatasetsTests()8 def test_fetch_cifar10(self):9 # test channels_last = True, normalize_x = False10 (train_x, train_y), (test_x, test_y) = load_cifar10()11 self.assertTupleEqual(train_x.shape, (50000, 32, 32, 3))12 self.assertTupleEqual(train_y.shape, (50000,))13 self.assertTupleEqual(test_x.shape, (10000, 32, 32, 3))14 self.assertTupleEqual(test_y.shape, (10000,))15 self.assertGreater(np.max(train_x), 128.)16 self.assertEqual(np.max(train_y), 9)17 # test channels_last = False, normalize_x = True18 (train_x, train_y), (test_x, test_y) = load_cifar10(channels_last=False,19 normalize_x=True)20 self.assertTupleEqual(train_x.shape, (50000, 3, 32, 32))21 self.assertTupleEqual(train_y.shape, (50000,))22 self.assertTupleEqual(test_x.shape, (10000, 3, 32, 32))23 self.assertTupleEqual(test_y.shape, (10000,))24 self.assertLess(np.max(train_x), 1. + 1e-5)25 # test x_shape26 (train_x, train_y), (test_x, test_y) = load_cifar10(x_shape=(1024, 3))27 self.assertTupleEqual(train_x.shape, (50000, 1024, 3))28 self.assertTupleEqual(test_x.shape, (10000, 1024, 3))29 with pytest.raises(ValueError,30 match='`x_shape` does not product to 3072'):31 _ = load_cifar10(x_shape=(1, 2, 3))32 @skipUnlessRunDatasetsTests()33 def test_fetch_cifar100(self):34 # test channels_last = True, normalize_x = False35 (train_x, train_y), (test_x, test_y) = load_cifar100()36 self.assertTupleEqual(train_x.shape, (50000, 32, 32, 3))37 self.assertTupleEqual(train_y.shape, (50000,))38 self.assertTupleEqual(test_x.shape, (10000, 32, 32, 3))39 self.assertTupleEqual(test_y.shape, (10000,))40 self.assertGreater(np.max(train_x), 128.)41 self.assertEqual(np.max(train_y), 99)42 # test channels_last = False, normalize_x = True43 (train_x, train_y), (test_x, test_y) = load_cifar100(44 label_mode='coarse', channels_last=False, normalize_x=True)45 self.assertTupleEqual(train_x.shape, (50000, 3, 32, 32))46 self.assertTupleEqual(train_y.shape, (50000,))47 self.assertTupleEqual(test_x.shape, (10000, 3, 32, 32))48 self.assertTupleEqual(test_y.shape, (10000,))49 self.assertLess(np.max(train_x), 1. + 1e-5)50 self.assertEqual(np.max(train_y), 19)51 # test x_shape52 (train_x, train_y), (test_x, test_y) = load_cifar100(x_shape=(1024, 3))53 self.assertTupleEqual(train_x.shape, (50000, 1024, 3))54 self.assertTupleEqual(test_x.shape, (10000, 1024, 3))55 with pytest.raises(ValueError,56 match='`x_shape` does not product to 3072'):...
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!!