How to use assertTrue method in autotest

Best Python code snippet using autotest_python

test_context.py

Source:test_context.py Github

copy

Full Screen

...53 def f(arg1, arg2=1, *arg3, **arg4):54 pass55 F = context.recompile(f)56 F(1.0)57 self.assertTrue('arg1' in context.sym_vars)58 self.assertTrue('arg2' in context.sym_vars)59 self.assertTrue('arg3' not in context.sym_vars)60 self.assertTrue('arg4' not in context.sym_vars)61class ForceFloatX(unittest.TestCase):62 def test_force_floatX(self):63 def f(x):64 return x65 ctx = autodiff.context.Context(force_floatX=False)66 ctx_floatX = autodiff.context.Context(force_floatX=True)67 F = ctx.recompile(f)68 F_floatX = ctx_floatX.recompile(f)69 x = np.array([1, 2, 3])70 self.assertTrue(F(x).dtype == 'int64')71 self.assertTrue(F_floatX(x).dtype == theano.config.floatX)72class Signatures(unittest.TestCase):73 def test_sig_no_arg(self):74 def f():75 return 176 self.assertTrue(checkfn(f))77 def test_sig_one_arg(self):78 def f(x):79 return x80 self.assertRaises(TypeError, f)81 self.assertRaises(TypeError, f, a=2)82 self.assertTrue(checkfn(f, [], 2))83 self.assertTrue(checkfn(f, [], x=2))84 def test_sig_mult_args(self):85 # multiple args, no default86 def f(x, y):87 return x * y88 self.assertRaises(TypeError, f)89 self.assertRaises(TypeError, f, 2)90 self.assertRaises(TypeError, f, a=2, b=2)91 self.assertTrue(checkfn(f, [], 2, 3))92 self.assertTrue(checkfn(f, [], y=4, x=5))93 def test_sig_var_args(self):94 # var args, no default95 def f(x, y, *z):96 return x * y * sum(z)97 self.assertRaises(TypeError, f)98 self.assertRaises(TypeError, f, 2)99 self.assertRaises(TypeError, f, a=2, b=2)100 self.assertTrue(checkfn(f, [], 2, 3))101 self.assertTrue(checkfn(f, [], 2, 3, 4))102 self.assertTrue(checkfn(f, [], 2, 3, 4, 5))103 def test_sig_default_args(self):104 # multiple args, one default105 def f(x, y=2):106 return x * y107 self.assertRaises(TypeError, f)108 self.assertRaises(TypeError, f, y=3)109 self.assertTrue(checkfn(f, [], 2))110 self.assertTrue(checkfn(f, [], 2, 3))111 self.assertTrue(checkfn(f, [], y=4, x=5))112 self.assertTrue(checkfn(f, [], x=5))113 # multiple args, all default114 def f(x=1, y=2):115 return x * y116 self.assertTrue(checkfn(f))117 self.assertTrue(checkfn(f, [], 1))118 self.assertTrue(checkfn(f, [], 1, 2))119 self.assertTrue(checkfn(f, [], y=2, x=1))120 self.assertTrue(checkfn(f, [], x=5))121 self.assertTrue(checkfn(f, [], y=5))122 def test_sig_default_var_args(self):123 # multiple var args, all default124 def f(x=1, y=2, *z):125 return x * y * sum(z)126 self.assertTrue(checkfn(f))127 self.assertTrue(checkfn(f, [], 1))128 self.assertTrue(checkfn(f, [], 1, 2))129 self.assertTrue(checkfn(f, [], 1, 2, 3))130 self.assertTrue(checkfn(f, [], 1, 2, 3, 4))131 def test_sig_kwargs(self):132 # kwargs133 def f(**kwargs):134 x = kwargs['x']135 y = kwargs['y']136 z = kwargs['z']137 return x * y * z138 self.assertRaises(KeyError, f)139 self.assertRaises(TypeError, f, 1)140 self.assertTrue(checkfn(f, [], x=1, y=2, z=3))141 def test_sig_varargs_kwargs(self):142 # varargs and kwargs143 def f(a, *b, **kwargs):144 x = kwargs['x']145 y = kwargs['y']146 z = kwargs['z']147 return x * y * z148 self.assertRaises(TypeError, f)149 self.assertRaises(KeyError, f, 1)150 self.assertRaises(TypeError, f, x=1, y=2, z=3)151 self.assertTrue(checkfn(f, [], 1, x=1, y=2, z=3))152 self.assertTrue(checkfn(f, [], 1, 2, 3, x=1, y=2, z=3))153 # varargs and kwargs, use varargs154 def f(a, *b, **kwargs):155 x = kwargs['x']156 y = kwargs['y']157 z = kwargs['z']158 return x * y * z * b[0]159 self.assertTrue(checkfn(f, [], 1, 2, x=1, y=2, z=3))160 self.assertTrue(checkfn(f, [], 1, 2, 3, x=1, y=2, z=3))161 def test_expand_varargs(self):162 def f(*args):163 return args[1]164 def g(x):165 args = (x, np.ones((2, 3)), 5)166 return f(*args)167 self.assertTrue(checkfn(g, [], 1))168 def test_expand_kwargs(self):169 def f(**args):170 return args['x']171 def g(x):172 args = dict(x=x, y=np.ones((2, 3)), z=5)173 return f(**args)174 self.assertTrue(checkfn(g, [], 1))175class Python(unittest.TestCase):176 def test_range(self):177 def f(x):178 for i in range(3):179 x += 5180 return x181 self.assertTrue(checkfn(f, [1]))182 def f(x):183 a = 3184 for i in range(a):185 x += 5186 return x187 self.assertTrue(checkfn(f, [1]))188 def f(x):189 a = x[0] + 10190 for i in range(int(a)):191 x += 5192 return x193 self.assertTrue(checkfn(f, [1]))194 def f(x, a):195 for i in range(a):196 x += 5197 return x198 self.assertTrue(checkfn(f, [1], 3))199 def f():200 l = []201 for i in range(3):202 l.append(i)203 return l204 self.assertTrue(checkfn(f, []))205 def f():206 l1 = {i:i for i in range(3)}207 l2 = [l1[i] for i in range(3)]208 return l2209 self.assertRaises(KeyError, checkfn, f, [])210 def f():211 l1 = {escape(i):i for i in range(3)}212 l2 = [l1[escape(i)] for i in range(3)]213 return l2214 self.assertTrue(checkfn(f, []))215 def test_pass(self):216 def fn(x):217 pass218 self.assertTrue(checkfn(fn, [1]))219 def test_if(self):220 # test that if statements escape their test arguments221 def f(switch):222 if switch > 0:223 return 1224 else:225 return -1226 self.assertTrue(checkfn(f, [], -10))227 def test_for(self):228 def f():229 x = 0230 for i in range(5):231 x += i232 return x233 self.assertTrue(checkfn(f))234 def f(x):235 for i in range(5):236 x += i237 return x238 self.assertTrue(checkfn(f, [1]))239 def test_enumerate(self):240 def f1(x):241 z = np.arange(x.shape[0])242 for i, xi in enumerate(range(4)):243 z[i] += xi244 return z245 self.assertTrue(checkfn(f1, [1]))246 def f2(x):247 z = np.arange(x.shape[0])248 for i, xi in enumerate(x):249 z[i] += xi250 return z251 self.assertRaises(TypeError, checkfn, f2, [1])252 def test_sum(self):253 def f():254 x = np.ones(5)255 y = np.ones(5) * 5256 return builtins.sum([x, y])257 self.assertTrue(checkfn(f, []))258 def test_max(self):259 def f():260 x = np.arange(5)261 return builtins.max(x)262 self.assertTrue(checkfn(f, []))263 def f(x):264 return builtins.max(x)265 self.assertTrue(checkfn(f, [1]))266 def test_min(self):267 def f():268 x = np.arange(5)269 return builtins.min(x)270 self.assertTrue(checkfn(f, []))271 def f(x):272 return builtins.min(x)273 self.assertTrue(checkfn(f, [1]))274 def test_isinstance(self):275 def f(x):276 if isinstance(x, int):277 return 1278 elif isinstance(x, float):279 return -1280 self.assertTrue(checkfn(f, [], 1, test_floatX=False))281 self.assertTrue(checkfn(f, [], 1.0, test_floatX=False))282 def test_tuple_index(self):283 def f(*x):284 return x[1]285 self.assertTrue(checkfn(f, [], 1, 2, 3))286 def test_nested_tuple_index(self):287 def f(*x):288 return x[1]289 def g(*x):290 return f(*x)291 self.assertTrue(checkfn(g, [], 1, 2, 3))292 def test_nested_def_tuple_index(self):293 def g(*x):294 def f(*x):295 return x[1]296 return f(*x)297 self.assertTrue(checkfn(g, [], 1, 2, 3))298 def test_append(self):299 def f():300 l = []301 for i in range(5):302 l.append(i)303 return l304 self.assertTrue(checkfn(f, []))305 def test_list_comprehension(self):306 def f():307 x = np.arange(10.0)308 y = [xi + 10 for xi in escape(x)]309 return y310 self.assertTrue(checkfn(f, []))311 def test_dict_comprehension(self):312 def f():313 x = np.arange(10.0)314 y = {escape(xi): xi + 10 for xi in escape(x)}315 return y[5]316 self.assertTrue(checkfn(f, []))317 def test_tuple_type(self):318 def f():319 x = tuple((3, 4, 5))320 return x321 def f2(x, y):322 return tuple(i for i in [x, y])323 self.assertTrue(checkfn(f, []))324 self.assertTrue(checkfn(f2, [], 1.0, 2.0))325 def test_inplace_container(self):326 def f():327 x = {3,4,5}328 x.remove(4)329 return sum(x)330 self.assertTrue(checkfn(f, []))331class BasicMath(unittest.TestCase):332 def test_basic_ops(self):333 for d in range(3):334 self.assertTrue(checkfn(lambda x: x + 2, [d]))335 self.assertTrue(checkfn(lambda x: x - 2, [d]))336 self.assertTrue(checkfn(lambda x: x * 2, [d]))337 self.assertTrue(checkfn(lambda x: x / 2, [d]))338 self.assertTrue(checkfn(lambda x: x / 2.0, [d]))339 self.assertTrue(checkfn(lambda x: x // 2.0, [d]))340 self.assertTrue(checkfn(lambda x: x ** 2, [d]))341 self.assertTrue(checkfn(lambda x: x % 2, [d]))342 def test_comparisons(self):343 for d in range(3):344 self.assertTrue(checkfn(lambda x, y: x > y, [d, d]))345 self.assertTrue(checkfn(lambda x, y: x < y, [d, d]))346 self.assertTrue(checkfn(lambda x, y: x >= y, [d, d]))347 self.assertTrue(checkfn(lambda x, y: x <= y, [d, d]))348 self.assertTrue(checkfn(lambda x, y: x == y, [d, d]))349 self.assertTrue(checkfn(lambda x, y: x != y, [d, d]))350 def test_inplace(self):351 def iadd(x):352 x += 10353 return x354 def isub(x):355 x -= 10356 return x357 def imul(x):358 x *= 10359 return x360 def idiv(x):361 x /= 10.0362 return x363 for d in range(3):364 for f in [iadd, isub, imul, idiv]:365 self.assertTrue(checkfn(f, [d]))366class NumpyFns(unittest.TestCase):367 """368 Test for coverage of functions in np namespace369 """370 def test_all(self):371 def fn(x):372 return np.all(x > .5)373 self.assertTrue(checkfn(fn, [2]))374 def test_any(self):375 def fn(x):376 return np.any(x > .5)377 self.assertTrue(checkfn(fn, [2]))378 def test_arange(self):379 self.assertTrue(checkfn(lambda: np.arange(3), []))380 # numpy arange doesn't return an array with the same dtype as its381 # argument, but theano arange does. In Context, the numpy arange382 # should be cast to match the theano one.383 self.assertTrue(checkfn(lambda: np.arange(np.float32(3.)), []))384 def test_abs(self):385 def fn1(x):386 return np.abs(x)387 def fn2(x):388 return abs(x)389 self.assertTrue(checkfn(fn1, [2]))390 self.assertTrue(checkfn(fn2, [2]))391 def test_dot(self):392 def fn(x, y):393 return np.dot(x, y)394 for nd in np.ndindex(*([3] * fn.__code__.co_argcount)):395 self.assertTrue(checkfn(fn, nd))396 def test_exp(self):397 def fn(x):398 return np.exp(x)399 self.assertTrue(checkfn(fn, [2]))400 def test_log(self):401 def fn(x):402 return np.log(x)403 self.assertTrue(checkfn(fn, [2]))404 def test_log1p(self):405 def fn(x):406 return np.log1p(x)407 self.assertTrue(checkfn(fn, [2]))408 def test_log10(self):409 def fn(x):410 return np.log10(x)411 self.assertTrue(checkfn(fn, [2]))412 def test_max(self):413 def fn(x):414 return np.max(x, 0)415 self.assertTrue(checkfn(fn, [2]))416 def test_min(self):417 def fn(x):418 return np.min(x, 0)419 self.assertTrue(checkfn(fn, [2]))420 def test_maximum(self):421 def fn(x, y):422 return np.maximum(x, y)423 self.assertTrue(checkfn(fn, [2, 2]))424 def test_minimum(self):425 def fn(x, y):426 return np.minimum(x, y)427 self.assertTrue(checkfn(fn, [2, 2]))428 def test_reshape(self):429 def fn(x, shape):430 return np.reshape(x, shape)431 self.assertTrue(checkfn(fn, [2], [2, 8]))432 def fn(x, shape1, shape2):433 return np.reshape(x, [shape1, shape2])434 self.assertTrue(checkfn(fn, [2], 2, 8))435 self.assertTrue(checkfn(fn, [2], 2, -1))436 self.assertTrue(checkfn(lambda x: np.reshape(x, x.shape), [2]))437 self.assertTrue(checkfn(438 lambda x: np.reshape(x, (x.shape[0], x.shape[1])), [2]))439 def test_sum(self):440 self.assertTrue(checkfn(lambda x: np.sum(x), [2]))441 self.assertTrue(checkfn(lambda x: np.sum(x, 1), [2]))442 self.assertTrue(checkfn(lambda x: np.sum(x, axis=1), [2]))443 self.assertTrue(checkfn(lambda x: np.sum(x, axis=1), [2]))444 self.assertTrue(checkfn(lambda x: np.sum(x, axis=None), [2]))445 self.assertTrue(checkfn(lambda x, a: np.sum(x, a), [2], 0))446 self.assertTrue(checkfn(lambda x, a: np.sum(x, a), [2], None))447 self.assertTrue(checkfn(lambda x, a: np.sum(x, axis=a), [2], 0))448 def test_sqrt(self):449 def fn(x):450 return np.sqrt(x)451 self.assertTrue(checkfn(fn, [2]))452 def test_tanh(self):453 def fn(x):454 return np.tanh(x)455 self.assertTrue(checkfn(fn, [2]))456 def test_transpose(self):457 self.assertTrue(checkfn(lambda x: np.transpose(x), [2]))458 self.assertTrue(checkfn(lambda x: np.transpose(x, (0, 1)), [2]))459 self.assertTrue(checkfn(lambda x, a: np.transpose(x, a), [2], (0, 1)))460 self.assertTrue(checkfn(461 lambda x, a0, a1: np.transpose(x, (a0, a1)), [2], 0, 1))462 def test_zeros_like(self):463 def fn(x):464 return np.zeros_like(x)465 self.assertTrue(checkfn(fn, [2]))466 def test_astype(self):467 self.assertTrue(checkfn(lambda x: x.astype('float32'), [2]))468 def test_astype_numpy_class(self):469 self.assertTrue(checkfn(lambda x: x.astype(np.float32), [2]))470 def test_cast(self):471 self.assertTrue(checkfn(lambda x: int(x), [0]))472 self.assertTrue(checkfn(lambda x: float(x), [0]))473 self.assertTrue(checkfn(lambda x: bool(x), [0]))474 self.assertTrue(checkfn(lambda x: np.float_(x), [2]))475 self.assertTrue(checkfn(lambda x: np.float32(x), [2]))476 self.assertTrue(checkfn(lambda x: np.float64(x), [2]))477 self.assertTrue(checkfn(lambda x: np.int_(x), [2]))478 self.assertTrue(checkfn(lambda x: np.int16(x), [2]))479 self.assertTrue(checkfn(lambda x: np.bool_(x), [2]))480 self.assertTrue(checkfn(lambda x: np.bool(x), [0]))481 def test_alloc(self):482 self.assertTrue(checkfn(lambda: np.ones(5), []))483 self.assertTrue(checkfn(lambda: np.ones((2, 5)), []))484 self.assertTrue(checkfn(lambda x: np.ones(x.shape), [0]))485 self.assertTrue(checkfn(lambda x: np.ones(x.shape), [1]))486 self.assertTrue(checkfn(lambda x: np.ones(x.shape), [2]))487 def test_sort(self):488 self.assertTrue(checkfn(lambda x: np.sort(x), [2]))489 self.assertTrue(checkfn(lambda x: np.sort(x, 0), [2]))490 def test_concatenate(self):491 self.assertTrue(checkfn(lambda x, y: np.vstack((x, y)), [2, 2]))492 self.assertTrue(checkfn(lambda x, y: np.hstack((x, y)), [2, 2]))493 def test_axis(self):494 def f(x, axis=1):495 return np.std(x, axis=axis)496 self.assertTrue(checkfn(f, [2]))497class RandomNumbers(unittest.TestCase):498 def check_random(self, fn, *args, **kwargs):499 context.reset()500 F = context.recompile(fn)501 result1 = F(*args, **kwargs).eval()502 result2 = F(*args, **kwargs).eval()503 return np.allclose(result1, result2)504 def test_random(self):505 self.assertFalse(506 self.check_random(lambda: np.random.random((10, 10))))507 self.assertFalse(508 self.check_random(lambda s: np.random.random(s), 10.0))509 self.assertFalse(510 self.check_random(lambda s: np.random.random(s), (10, 10)))511 def test_random_shape(self):512 self.assertFalse(513 self.check_random(514 lambda x: np.random.random(x.shape), np.ones((10, 10))))515 def test_random_binomial(self):516 self.assertFalse(517 self.check_random(lambda: np.random.binomial(1, .5, (10, 10))))518 self.assertFalse(519 self.check_random(lambda s: np.random.binomial(1, .5, s), 10.0))520 self.assertFalse(self.check_random(521 lambda s: np.random.binomial(1, .5, s), (10, 10)))522class ArrayMethodsAttributes(unittest.TestCase):523 """524 Test for coverage of array methods and attributes525 """526 def test_argmax(self):527 self.assertTrue(checkfn(lambda x: x.argmax(), [2]))528 self.assertTrue(checkfn(lambda x: x.argmax(1), [2]))529 self.assertTrue(checkfn(lambda x: x.argmax(axis=1), [2]))530 self.assertTrue(checkfn(lambda x, a: x.argmax(a), [2], 0))531 self.assertTrue(checkfn(lambda x, a: x.argmax(axis=a), [2], 0))532 def test_argmin(self):533 self.assertTrue(checkfn(lambda x: x.argmin(), [2]))534 self.assertTrue(checkfn(lambda x: x.argmin(1), [2]))535 self.assertTrue(checkfn(lambda x: x.argmin(axis=1), [2]))536 self.assertTrue(checkfn(lambda x, a: x.argmin(a), [2], 0))537 self.assertTrue(checkfn(lambda x, a: x.argmin(axis=a), [2], 0))538 def test_argsort(self):539 self.assertTrue(checkfn(lambda x: x.argsort(), [2]))540 self.assertTrue(checkfn(lambda x: x.argsort(1), [2]))541 self.assertTrue(checkfn(lambda x: x.argsort(axis=1), [2]))542 self.assertTrue(checkfn(lambda x, a: x.argsort(a), [2], 0))543 self.assertTrue(checkfn(lambda x, a: x.argsort(axis=a), [2], 0))544 def test_clip(self):545 def fn(x, a, b):546 return x.clip(a, b)547 self.assertTrue(checkfn(fn, [2], .4, .45))548 def test_conj(self):549 def fn(x):550 return x.conj()551 self.assertTrue(checkfn(fn, [2]))552 def test_conjugate(self):553 def fn(x):554 return x.conjugate()555 self.assertTrue(checkfn(fn, [2]))556 def test_copy(self):557 def fn(x):558 return x.copy()559 self.assertTrue(checkfn(fn, [2]))560 def test_diagonal(self):561 def fn(x):562 return x.diagonal()563 self.assertTrue(checkfn(fn, [2]))564 def test_dot(self):565 def fn(x, y):566 return x.dot(y)567 self.assertTrue(checkfn(fn, [2, 2]))568 self.assertTrue(checkfn(fn, [1, 2]))569 def test_imag(self):570 def fn(x):571 return x.imag572 self.assertTrue(checkfn(fn, [2]))573 def test_flatten(self):574 def fn(x):575 return x.flatten()576 self.assertTrue(checkfn(fn, [2]))577 def test_max(self):578 self.assertTrue(checkfn(lambda x: x.max(), [2]))579 self.assertTrue(checkfn(lambda x: x.max(1), [2]))580 self.assertTrue(checkfn(lambda x: x.max(axis=1), [2]))581 self.assertTrue(checkfn(lambda x, a: x.max(a), [2], 0))582 self.assertTrue(checkfn(lambda x, a: x.max(axis=a), [2], 0))583 def test_mean(self):584 self.assertTrue(checkfn(lambda x: x.mean(), [2]))585 self.assertTrue(checkfn(lambda x: x.mean(1), [2]))586 self.assertTrue(checkfn(lambda x: x.mean(axis=1), [2]))587 self.assertTrue(checkfn(lambda x, a: x.mean(a), [2], 0))588 self.assertTrue(checkfn(lambda x, a: x.mean(axis=a), [2], 0))589 def test_min(self):590 self.assertTrue(checkfn(lambda x: x.min(), [2]))591 self.assertTrue(checkfn(lambda x: x.min(1), [2]))592 self.assertTrue(checkfn(lambda x: x.min(axis=1), [2]))593 self.assertTrue(checkfn(lambda x, a: x.min(a), [2], 0))594 self.assertTrue(checkfn(lambda x, a: x.min(axis=a), [2], 0))595 def test_prod(self):596 self.assertTrue(checkfn(lambda x: x.prod(), [2]))597 self.assertTrue(checkfn(lambda x: x.prod(1), [2]))598 self.assertTrue(checkfn(lambda x: x.prod(axis=1), [2]))599 self.assertTrue(checkfn(lambda x, a: x.prod(a), [2], 0))600 self.assertTrue(checkfn(lambda x, a: x.prod(axis=a), [2], 0))601 def test_ravel(self):602 def fn(x):603 return x.ravel()604 self.assertTrue(checkfn(fn, [2]))605 def test_repeat(self):606 def fn(x, repeats):607 return x.repeat(repeats, axis=1)608 self.assertTrue(checkfn(fn, [2], 5))609 def test_real(self):610 def fn(x):611 return x.real612 self.assertTrue(checkfn(fn, [2]))613 def test_reshape(self):614 def fn(x, shape):615 return x.reshape(shape)616 self.assertTrue(checkfn(fn, [2], [2, 8]))617 def fn(x, s1, s2):618 return x.reshape(s1, s2)619 self.assertTrue(checkfn(fn, [2], 2, 8))620 self.assertTrue(checkfn(fn, [2], 2, -1))621 def fn(x):622 return x.reshape(2, 8)623 self.assertTrue(checkfn(fn, [2]))624 def test_sort(self):625 def fn(x):626 x.sort()627 return x628 self.assertRaises(ValueError, checkfn, fn, [2])629 def fn(x):630 x.sort(1)631 return x632 self.assertRaises(ValueError, checkfn, fn, [2])633 def fn(x):634 x.sort(axis=1)635 return x636 self.assertRaises(ValueError, checkfn, fn, [2])637 def fn(x, a):638 x.sort(a)639 return x640 self.assertRaises(ValueError, checkfn, fn, [2], 0)641 def test_sum(self):642 self.assertTrue(checkfn(lambda x: x.sum(), [2]))643 self.assertTrue(checkfn(lambda x: x.sum(1), [2]))644 self.assertTrue(checkfn(lambda x: x.sum(axis=1), [2]))645 self.assertTrue(checkfn(lambda x, a: x.sum(a), [2], 0))646 self.assertTrue(checkfn(lambda x, a: x.sum(axis=a), [2], 0))647 def test_swapaxes(self):648 def fn(x, a1, a2):649 return x.swapaxes(a1, a2)650 self.assertTrue(checkfn(fn, [2], 0, 1))651 def test_astype(self):652 self.assertTrue(checkfn(lambda x: x.astype('int8'), [2]))653 self.assertTrue(checkfn(lambda x: x.astype('float32'), [2]))654 self.assertTrue(checkfn(lambda x: x.astype(np.float32), [2]))655 self.assertTrue(checkfn(lambda x: x.astype(dtype='float32'), [2]))656 self.assertTrue(checkfn(lambda x: x.astype(dtype=np.float32), [2]))657 def test_std(self):658 self.assertTrue(checkfn(lambda x: x.std(), [2]))659 self.assertTrue(checkfn(lambda x: x.std(1), [2]))660 self.assertTrue(checkfn(lambda x: x.std(axis=1), [2]))661 self.assertTrue(checkfn(lambda x, a: x.std(a), [2], 0))662 self.assertTrue(checkfn(lambda x, a: x.std(axis=a), [2], 0))663 def test_size(self):664 self.assertTrue(checkfn(lambda x: np.arange(x.size), [1]))665 self.assertTrue(checkfn(lambda x: np.arange(x.size), [2]))666 def test_T(self):667 def fn(x):668 return x.T669 self.assertTrue(checkfn(fn, [1]))670 self.assertTrue(checkfn(fn, [2]))671 def test_transpose(self):672 def fn(x):673 return x.transpose()674 self.assertTrue(checkfn(fn, [1]))675 self.assertTrue(checkfn(fn, [2]))676 def test_var(self):677 self.assertTrue(checkfn(lambda x: x.var(), [2]))678 self.assertTrue(checkfn(lambda x: x.var(1), [2]))679 self.assertTrue(checkfn(lambda x: x.var(axis=1), [2]))680 self.assertTrue(checkfn(lambda x, a: x.var(a), [2], 0))681 self.assertTrue(checkfn(lambda x, a: x.var(axis=a), [2], 0))682class Namespaces(unittest.TestCase):683 def test_global(self):684 x = np.ones((3, 4))685 def f():686 return x.swapaxes(0, 1)687 self.assertTrue(checkfn(f, []))688 def test_nested_functions(self):689 def g(x):690 def h(x):691 return x.swapaxes(1, 0)692 return h(x)693 def f(x):694 return g(x)695 self.assertTrue(checkfn(f, [2]))696 def test_define_class(self):697 """698 This fails due to shadowing of s (and then not being to set values)699 """700 def f():701 class StringAttr(object):702 def __init__(self):703 self.s = "string"704 S = StringAttr()705 def f2(**kwargs):706 if kwargs['string'] == 5:707 return 1708 else:709 return 0710 return f2(**{S.s: 5})711 self.assertTrue(checkfn(f, []))712 def test_freevars(self):713 class Test(object):714 def __init__(self):715 self.x = np.arange(5.) - 10.0716 def getx(self):717 return self.x718 t = Test()719 def f(x):720 return np.dot(x, t.x)721 x = np.arange(5.)722 self.assertTrue(checkfn(f, [], x))723 self.assertTrue(id(t.x) in context.sym_vars)724class ArraySubscripts(unittest.TestCase):725 def test_indexing(self):726 self.assertTrue(checkfn(lambda x: x[2], [1]))727 self.assertTrue(checkfn(lambda x: x[-2], [1]))728 self.assertTrue(checkfn(lambda x: x[2], [2]))729 self.assertTrue(checkfn(lambda x: x[-2], [2]))730 self.assertTrue(checkfn(lambda x: x[2, 2], [2]))731 self.assertTrue(checkfn(lambda x: x[-2, -2], [2]))732 def test_adv_index(self):733 self.assertTrue(checkfn(lambda x: x[[3, 2, 1], [1, 2, 3]], [2]))734 self.assertTrue(checkfn(lambda x: x[x > .5], [2]))735 self.assertTrue(checkfn(lambda x: x[(x > .1) * (x < .5)], [2]))736 self.assertTrue(checkfn(lambda x: x[[2, 3], 1:], [2]))737 # @unittest.expectedFailure738 # def test_adv_index_known_failures(self):739 # self.assertTrue(checkfn(lambda x: x[1:, x > .5], [2]))740 # self.assertTrue(checkfn(lambda x: x[x > .5, 1:], [2]))741 def test_slicing(self):742 # SLICE+0743 self.assertTrue(checkfn(lambda x: x[:], [1]))744 self.assertTrue(checkfn(lambda x: x[:], [2]))745 # SLICE+1746 self.assertTrue(checkfn(lambda x: x[1:], [1]))747 self.assertTrue(checkfn(lambda x: x[-2:], [1]))748 self.assertTrue(checkfn(lambda x: x[1:, 1:], [2]))749 self.assertTrue(checkfn(lambda x: x[-2:, -2:], [2]))750 # SLICE+2751 self.assertTrue(checkfn(lambda x: x[:2], [1]))752 self.assertTrue(checkfn(lambda x: x[:-2], [1]))753 self.assertTrue(checkfn(lambda x: x[:2, :2], [2]))754 self.assertTrue(checkfn(lambda x: x[:-2, :-2], [2]))755 # SLICE+3756 self.assertTrue(checkfn(lambda x: x[1:3], [1]))757 self.assertTrue(checkfn(lambda x: x[-3:-1], [1]))758 self.assertTrue(checkfn(lambda x: x[1:3, 1:3], [2]))759 self.assertTrue(checkfn(lambda x: x[-3:-1, -3:-1], [2]))760 def test_index_and_slice(self):761 self.assertTrue(checkfn(lambda x: x[1:3, 2], [2]))762 def test_index_assign(self):763 def f():764 x = np.ones((3, 4))765 x[2] = 100766 return x767 self.assertTrue(checkfn(f, []))768 def f():769 x = np.ones((3, 4))770 x[2, 2] = 100771 return x772 self.assertTrue(checkfn(f, []))773 def f():774 x = np.ones((3, 4))775 x[2, 2] += 100776 return x777 self.assertTrue(checkfn(f, []))778 def f(x):779 x[2, 2] = 100780 return x781 self.assertTrue(checkfn(f, [2]))782 def f(x):783 x[2, 2] += 100784 return x785 self.assertTrue(checkfn(f, [2]))786 def test_slice_assign(self):787 def f():788 x = np.ones((3, 4))789 x[2:3] = 100790 return x791 self.assertTrue(checkfn(f, []))792 def f():793 x = np.ones((3, 4))794 x[2:3, 2:3] += 100795 return x796 self.assertTrue(checkfn(f, []))797 def f(x):798 x[2:3, 2:3] += 100799 return x800 self.assertTrue(checkfn(f, [2]))801 def test_store_slice(self):802 # STORE_SLICE+0803 def f(x):804 x[:] = 5805 x[:] += 5806 return x807 self.assertTrue(checkfn(f, [1]))808 self.assertTrue(checkfn(f, [2]))809 # STORE_SLICE+1810 def f(x):811 x[2:] = 5812 x[-2:] += 5813 return x814 def f2(x):815 x[2:, 2:] = 5816 x[-2:, -2:] += 5817 return x818 self.assertTrue(checkfn(f, [1]))819 self.assertTrue(checkfn(f, [2]))820 self.assertTrue(checkfn(f2, [2]))821 # STORE_SLICE+2822 def f(x):823 x[:2] = 5824 x[:-2] += 5825 return x826 def f2(x):827 x[:2, :2] = 5828 x[:-2, :-2] += 5829 return x830 self.assertTrue(checkfn(f, [1]))831 self.assertTrue(checkfn(f, [2]))832 self.assertTrue(checkfn(f2, [2]))833 # STORE_SLICE+3834 def f(x):835 x[1:3] = 5836 x[-3:-1] += 5837 return x838 def f2(x):839 x[1:3, 1:3] = 5840 x[-3:-1, -3:-1] += 5841 return x842 self.assertTrue(checkfn(f, [1]))843 self.assertTrue(checkfn(f, [2]))844 self.assertTrue(checkfn(f2, [2]))845 def test_array_assign(self):846 def f(x):847 o = np.ones((2, 3))848 x[1:3, 1:4] = o849 return x850 self.assertTrue(checkfn(f, [2]))851 def test_nested_assign(self):852 def f(x):853 x[2:4][1, 2] = 100854 return x855 self.assertTrue(checkfn(f, [2]))856 def f(x):857 x[2:4][1, 2] += 100858 return x859 self.assertTrue(checkfn(f, [2]))860 def f():861 d = {1: {2: 3}}862 d[1][2] = 4863 return d[1][2]864 self.assertTrue(checkfn(f, []))865class TestMethods(unittest.TestCase):866 def test_instance_method(self):867 class Test(object):868 def test(self, x):869 return x * 2870 t = Test()871 self.assertTrue(checkfn(t.test, [2]))872 def test_class_method(self):873 class Test(object):874 @classmethod875 def test(cls, x):876 return x * 2877 t = Test()878 self.assertTrue(checkfn(t.test, [2]))879 self.assertTrue(checkfn(Test.test, [2]))880 def test_static_method(self):881 class Test(object):882 @staticmethod883 def test(x):884 return x * 2885 t = Test()886 self.assertTrue(checkfn(t.test, [2]))887 self.assertTrue(checkfn(Test.test, [2]))888class NumberMethodsAttributes(unittest.TestCase):889 """890 Test for coverage of NumPy number methods and attributes891 """892 def test_reduce_method(self):893 self.assertTrue(checkfn(lambda x: np.dot(x, x).sum(), [1]))894 self.assertTrue(checkfn(lambda x: np.dot(x, x).mean(), [1]))895class Ops(unittest.TestCase):896 """897 test bytecode op coverage for misc cases898 """899 def test_DUP_TOP(self):900 def f(x):901 x[:] += 100902 return x903 self.assertTrue(checkfn(f, [2]))904class Collections(unittest.TestCase):905 def test_views(self):906 from collections import OrderedDict907 def f():908 d = {1: 2, 3: 4, 5: 6}909 return list(v for v in d.values())910 self.assertTrue(checkfn(f, []))911 def test_OrderedDict(self):912 from collections import OrderedDict913 o = OrderedDict(a=1, b=2, c=3)914 def f():915 x = 0916 for v in o.values():917 x += v918 return x919 self.assertTrue(checkfn(f, []))920class InferUpdates(unittest.TestCase):921 def test_assign_updates(self):922 c = autodiff.context.Context(infer_updates=False)923 c_upd = autodiff.context.Context(infer_updates=True)924 class Test:925 def __init__(self):926 self.reset()927 def reset(self):928 self.tmp = 0.0929 test = Test()930 def f(x):931 test.tmp = test.tmp + x932 return test.tmp933 F = c.recompile(f)934 F_upd = c_upd.recompile(f)935 inp = 5.0936 test.reset()937 out = F(inp)938 test.reset()939 out_upd = F_upd(inp)940 compiled = theano.function([], out, updates=c.updates)941 compiled_upd = theano.function([], out_upd, updates=c_upd.updates)942 self.assertTrue(np.allclose(compiled(), 5.0))943 self.assertTrue(np.allclose(compiled(), 5.0))944 self.assertTrue(np.allclose(compiled_upd(), 5.0))945 self.assertTrue(np.allclose(compiled_upd(), 10.0))946 def test_augassign_updates(self):947 c = autodiff.context.Context(infer_updates=False)948 c_upd = autodiff.context.Context(infer_updates=True)949 class Test:950 def __init__(self):951 self.reset()952 def reset(self):953 self.tmp = 0.0954 test = Test()955 def f(x):956 test.tmp += x957 return test.tmp958 F = c.recompile(f)959 F_upd = c_upd.recompile(f)960 inp = 5.0961 test.reset()962 out = F(inp)963 test.reset()964 out_upd = F_upd(inp)965 compiled = theano.function([], out, updates=c.updates)966 compiled_upd = theano.function([], out_upd, updates=c_upd.updates)967 self.assertTrue(np.allclose(compiled(), 5.0))968 self.assertTrue(np.allclose(compiled(), 5.0))969 self.assertTrue(np.allclose(compiled_upd(), 5.0))...

Full Screen

Full Screen

test_object_graph.py

Source:test_object_graph.py Github

copy

Full Screen

...20 return '<ArgNode %s>'%(self.graphident,)21class TestObjectGraph (unittest.TestCase):22 def test_constructor(self):23 graph = ObjectGraph()24 self.assertTrue(isinstance(graph, ObjectGraph))25 g = Graph()26 graph = ObjectGraph(g)27 self.assertTrue(graph.graph is g)28 self.assertEqual(graph.debug, 0)29 self.assertEqual(graph.indent, 0)30 graph = ObjectGraph(debug=5)31 self.assertEqual(graph.debug, 5)32 def test_repr(self):33 graph = ObjectGraph()34 self.assertEqual(repr(graph), '<ObjectGraph>')35 def testNodes(self):36 graph = ObjectGraph()37 n1 = Node("n1")38 n2 = Node("n2")39 n3 = Node("n3")40 n4 = Node("n4")41 n1b = Node("n1")42 self.assertTrue(graph.getIdent(graph) is graph)43 self.assertTrue(graph.getRawIdent(graph) is graph)44 graph.addNode(n1)45 graph.addNode(n2)46 graph.addNode(n3)47 self.assertTrue(n1 in graph)48 self.assertFalse(n4 in graph)49 self.assertTrue("n1" in graph)50 self.assertFalse("n4" in graph)51 self.assertTrue(graph.findNode(n1) is n1)52 self.assertTrue(graph.findNode(n1b) is n1)53 self.assertTrue(graph.findNode(n2) is n2)54 self.assertTrue(graph.findNode(n4) is None)55 self.assertTrue(graph.findNode("n1") is n1)56 self.assertTrue(graph.findNode("n2") is n2)57 self.assertTrue(graph.findNode("n4") is None)58 self.assertEqual(graph.getRawIdent(n1), "n1")59 self.assertEqual(graph.getRawIdent(n1b), "n1")60 self.assertEqual(graph.getRawIdent(n4), "n4")61 self.assertEqual(graph.getRawIdent("n1"), None)62 self.assertEqual(graph.getIdent(n1), "n1")63 self.assertEqual(graph.getIdent(n1b), "n1")64 self.assertEqual(graph.getIdent(n4), "n4")65 self.assertEqual(graph.getIdent("n1"), "n1")66 self.assertTrue(n3 in graph)67 graph.removeNode(n3)68 self.assertTrue(n3 not in graph)69 graph.addNode(n3)70 self.assertTrue(n3 in graph)71 n = graph.createNode(SubNode, "n1")72 self.assertTrue(n is n1)73 n = graph.createNode(SubNode, "n8")74 self.assertTrue(isinstance(n, SubNode))75 self.assertTrue(n in graph)76 self.assertTrue(graph.findNode("n8") is n)77 n = graph.createNode(ArgNode, "args", 1, 2, 3, a='a', b='b')78 self.assertTrue(isinstance(n, ArgNode))79 self.assertTrue(n in graph)80 self.assertTrue(graph.findNode("args") is n)81 self.assertEqual(n.args, (1, 2, 3))82 self.assertEqual(n.kwds, {'a':'a', 'b':'b'})83 def testEdges(self):84 graph = ObjectGraph()85 n1 = graph.createNode(ArgNode, "n1", 1)86 n2 = graph.createNode(ArgNode, "n2", 1)87 n3 = graph.createNode(ArgNode, "n3", 1)88 n4 = graph.createNode(ArgNode, "n4", 1)89 graph.createReference(n1, n2, "n1-n2")90 graph.createReference("n1", "n3", "n1-n3")91 graph.createReference("n2", n3)92 g = graph.graph93 e = g.edge_by_node("n1", "n2")94 self.assertTrue(e is not None)95 self.assertEqual(g.edge_data(e), "n1-n2")96 e = g.edge_by_node("n1", "n3")97 self.assertTrue(e is not None)98 self.assertEqual(g.edge_data(e), "n1-n3")99 e = g.edge_by_node("n2", "n3")100 self.assertTrue(e is not None)101 self.assertEqual(g.edge_data(e), None)102 e = g.edge_by_node("n1", "n4")103 self.assertTrue(e is None)104 graph.removeReference(n1, n2)105 e = g.edge_by_node("n1", "n2")106 self.assertTrue(e is None)107 graph.removeReference("n1", "n3")108 e = g.edge_by_node("n1", "n3")109 self.assertTrue(e is None)110 graph.createReference(n1, n2, "foo")111 e = g.edge_by_node("n1", "n2")112 self.assertTrue(e is not None)113 self.assertEqual(g.edge_data(e), "foo")114 def test_flatten(self):115 graph = ObjectGraph()116 n1 = graph.createNode(ArgNode, "n1", 1)117 n2 = graph.createNode(ArgNode, "n2", 2)118 n3 = graph.createNode(ArgNode, "n3", 3)119 n4 = graph.createNode(ArgNode, "n4", 4)120 n5 = graph.createNode(ArgNode, "n5", 5)121 n6 = graph.createNode(ArgNode, "n6", 6)122 n7 = graph.createNode(ArgNode, "n7", 7)123 n8 = graph.createNode(ArgNode, "n8", 8)124 graph.createReference(graph, n1)125 graph.createReference(graph, n7)126 graph.createReference(n1, n2)127 graph.createReference(n1, n4)128 graph.createReference(n2, n3)129 graph.createReference(n2, n5)130 graph.createReference(n5, n6)131 graph.createReference(n4, n6)132 graph.createReference(n4, n2)133 self.assertFalse(isinstance(graph.flatten(), list))134 fl = list(graph.flatten())135 self.assertTrue(n1 in fl)136 self.assertTrue(n2 in fl)137 self.assertTrue(n3 in fl)138 self.assertTrue(n4 in fl)139 self.assertTrue(n5 in fl)140 self.assertTrue(n6 in fl)141 self.assertTrue(n7 in fl)142 self.assertFalse(n8 in fl)143 fl = list(graph.flatten(start=n2))144 self.assertFalse(n1 in fl)145 self.assertTrue(n2 in fl)146 self.assertTrue(n3 in fl)147 self.assertFalse(n4 in fl)148 self.assertTrue(n5 in fl)149 self.assertTrue(n6 in fl)150 self.assertFalse(n7 in fl)151 self.assertFalse(n8 in fl)152 graph.createReference(n1, n5)153 fl = list(graph.flatten(lambda n: n.args[0] % 2 != 0))154 self.assertTrue(n1 in fl)155 self.assertFalse(n2 in fl)156 self.assertFalse(n3 in fl)157 self.assertFalse(n4 in fl)158 self.assertTrue(n5 in fl)159 self.assertFalse(n6 in fl)160 self.assertTrue(n7 in fl)161 self.assertFalse(n8 in fl)162 def test_iter_nodes(self):163 graph = ObjectGraph()164 n1 = graph.createNode(ArgNode, "n1", 1)165 n2 = graph.createNode(ArgNode, "n2", 2)166 n3 = graph.createNode(ArgNode, "n3", 3)167 n4 = graph.createNode(ArgNode, "n4", 4)168 n5 = graph.createNode(ArgNode, "n5", 5)169 n6 = graph.createNode(ArgNode, "n6", 5)170 nodes = graph.nodes()171 if sys.version[0] == '2':172 self.assertTrue(hasattr(nodes, 'next'))173 else:174 self.assertTrue(hasattr(nodes, '__next__'))175 self.assertTrue(hasattr(nodes, '__iter__'))176 nodes = list(nodes)177 self.assertEqual(len(nodes), 6)178 self.assertTrue(n1 in nodes)179 self.assertTrue(n2 in nodes)180 self.assertTrue(n3 in nodes)181 self.assertTrue(n4 in nodes)182 self.assertTrue(n5 in nodes)183 self.assertTrue(n6 in nodes)184 def test_get_edges(self):185 graph = ObjectGraph()186 n1 = graph.createNode(ArgNode, "n1", 1)187 n2 = graph.createNode(ArgNode, "n2", 2)188 n3 = graph.createNode(ArgNode, "n3", 3)189 n4 = graph.createNode(ArgNode, "n4", 4)190 n5 = graph.createNode(ArgNode, "n5", 5)191 n6 = graph.createNode(ArgNode, "n6", 5)192 graph.createReference(n1, n2)193 graph.createReference(n1, n3)194 graph.createReference(n3, n1)195 graph.createReference(n5, n1)196 graph.createReference(n2, n4)197 graph.createReference(n2, n5)198 graph.createReference(n6, n2)199 outs, ins = graph.get_edges(n1)200 self.assertFalse(isinstance(outs, list))201 self.assertFalse(isinstance(ins, list))202 ins = list(ins)203 outs = list(outs)204 self.assertTrue(n1 not in outs)205 self.assertTrue(n2 in outs)206 self.assertTrue(n3 in outs)207 self.assertTrue(n4 not in outs)208 self.assertTrue(n5 not in outs)209 self.assertTrue(n6 not in outs)210 self.assertTrue(n1 not in ins)211 self.assertTrue(n2 not in ins)212 self.assertTrue(n3 in ins)213 self.assertTrue(n4 not in ins)214 self.assertTrue(n5 in ins)215 self.assertTrue(n6 not in ins)216 def test_filterStack(self):217 graph = ObjectGraph()218 n1 = graph.createNode(ArgNode, "n1", 0)219 n11 = graph.createNode(ArgNode, "n1.1", 1)220 n12 = graph.createNode(ArgNode, "n1.2", 0)221 n111 = graph.createNode(ArgNode, "n1.1.1", 0)222 n112 = graph.createNode(ArgNode, "n1.1.2",2)223 n2 = graph.createNode(ArgNode, "n2", 0)224 n3 = graph.createNode(ArgNode, "n2", 0)225 graph.createReference(None, n1)226 graph.createReference(None, n2)227 graph.createReference(n1, n11)228 graph.createReference(n1, n12)229 graph.createReference(n11, n111)230 graph.createReference(n11, n112)231 self.assertTrue(n1 in graph)232 self.assertTrue(n2 in graph)233 self.assertTrue(n11 in graph)234 self.assertTrue(n12 in graph)235 self.assertTrue(n111 in graph)236 self.assertTrue(n112 in graph)237 self.assertTrue(n2 in graph)238 self.assertTrue(n3 in graph)239 visited, removes, orphans = graph.filterStack(240 [lambda n: n.args[0] != 1, lambda n: n.args[0] != 2])241 self.assertEqual(visited, 6)242 self.assertEqual(removes, 2)243 self.assertEqual(orphans, 1)244 e = graph.graph.edge_by_node(n1.graphident, n111.graphident)245 self.assertEqual(graph.graph.edge_data(e), "orphan")246 self.assertTrue(n1 in graph)247 self.assertTrue(n2 in graph)248 self.assertTrue(n11 not in graph)249 self.assertTrue(n12 in graph)250 self.assertTrue(n111 in graph)251 self.assertTrue(n112 not in graph)252 self.assertTrue(n2 in graph)253 self.assertTrue(n3 in graph)254class TestObjectGraphIO (unittest.TestCase):255 def setUp(self):256 self._stdout = sys.stdout257 def tearDown(self):258 sys.stdout = self._stdout259 def test_msg(self):260 graph = ObjectGraph()261 sys.stdout = fp = StringIO()262 graph.msg(0, "foo")263 self.assertEqual(fp.getvalue(), "foo \n")264 sys.stdout = fp = StringIO()265 graph.msg(5, "foo")266 self.assertEqual(fp.getvalue(), "")267 sys.stdout = fp = StringIO()...

Full Screen

Full Screen

test_expressionparser.py

Source:test_expressionparser.py Github

copy

Full Screen

...16 self.assertEqual(parse("foo", foo=1), 1)17 self.assertEqual(parse("bar", bar=True), True)18 self.assertEqual(parse("abc123", abc123="xyz"), 'xyz')19 def test_equality(self):20 self.assertTrue(parse("true == true"))21 self.assertTrue(parse("false == false"))22 self.assertTrue(parse("1 == 1"))23 self.assertTrue(parse("100 == 100"))24 self.assertTrue(parse('"some text" == "some text"'))25 self.assertTrue(parse("true != false"))26 self.assertTrue(parse("1 != 2"))27 self.assertTrue(parse('"text" != "other text"'))28 self.assertTrue(parse("foo == true", foo=True))29 self.assertTrue(parse("foo == 1", foo=1))30 self.assertTrue(parse('foo == "bar"', foo='bar'))31 self.assertTrue(parse("foo == bar", foo=True, bar=True))32 self.assertTrue(parse("true == foo", foo=True))33 self.assertTrue(parse("foo != true", foo=False))34 self.assertTrue(parse("foo != 2", foo=1))35 self.assertTrue(parse('foo != "bar"', foo='abc'))36 self.assertTrue(parse("foo != bar", foo=True, bar=False))37 self.assertTrue(parse("true != foo", foo=False))38 self.assertTrue(parse("!false"))39 def test_conjunctures(self):40 self.assertTrue(parse("true && true"))41 self.assertTrue(parse("true || false"))42 self.assertFalse(parse("false || false"))43 self.assertFalse(parse("true && false"))44 self.assertTrue(parse("true || false && false"))45 def test_parentheses(self):46 self.assertTrue(parse("(true)"))47 self.assertEqual(parse("(10)"), 10)48 self.assertEqual(parse('("foo")'), 'foo')49 self.assertEqual(parse("(foo)", foo=1), 1)50 self.assertTrue(parse("(true == true)"), True)51 self.assertTrue(parse("(true != false)"))52 self.assertTrue(parse("(true && true)"))53 self.assertTrue(parse("(true || false)"))54 self.assertTrue(parse("(true && true || false)"))55 self.assertFalse(parse("(true || false) && false"))56 self.assertTrue(parse("(true || false) && true"))57 self.assertTrue(parse("true && (true || false)"))58 self.assertTrue(parse("true && (true || false)"))59 self.assertTrue(parse("(true && false) || (true && (true || false))"))60 def test_comments(self):61 # comments in expressions work accidentally, via an implementation62 # detail - the '#' character doesn't match any of the regular63 # expressions we specify as tokens, and thus are ignored.64 # However, having explicit tests for them means that should the65 # implementation ever change, comments continue to work, even if that66 # means a new implementation must handle them explicitly.67 self.assertTrue(parse("true == true # it does!"))68 self.assertTrue(parse("false == false # it does"))69 self.assertTrue(parse("false != true # it doesnt"))70 self.assertTrue(parse('"string with #" == "string with #" # really, it does'))71 self.assertTrue(parse('"string with #" != "string with # but not the same" # no match!'))72 def test_not(self):73 """74 Test the ! operator.75 """76 self.assertTrue(parse("!false"))77 self.assertTrue(parse("!(false)"))78 self.assertFalse(parse("!true"))79 self.assertFalse(parse("!(true)"))80 self.assertTrue(parse("!true || true)"))81 self.assertTrue(parse("true || !true)"))82 self.assertFalse(parse("!true && true"))83 self.assertFalse(parse("true && !true"))84 def test_lesser_than(self):85 """86 Test the < operator.87 """88 self.assertTrue(parse("1 < 2"))89 self.assertFalse(parse("3 < 2"))90 self.assertTrue(parse("false || (1 < 2)"))91 self.assertTrue(parse("1 < 2 && true"))92 self.assertTrue(parse("true && 1 < 2"))93 self.assertTrue(parse("!(5 < 1)"))94 self.assertTrue(parse("'abc' < 'def'"))95 self.assertFalse(parse("1 < 1"))96 self.assertFalse(parse("'abc' < 'abc'"))97 def test_greater_than(self):98 """99 Test the > operator.100 """101 self.assertTrue(parse("2 > 1"))102 self.assertFalse(parse("2 > 3"))103 self.assertTrue(parse("false || (2 > 1)"))104 self.assertTrue(parse("2 > 1 && true"))105 self.assertTrue(parse("true && 2 > 1"))106 self.assertTrue(parse("!(1 > 5)"))107 self.assertTrue(parse("'def' > 'abc'"))108 self.assertFalse(parse("1 > 1"))109 self.assertFalse(parse("'abc' > 'abc'"))110 def test_lesser_or_equals_than(self):111 """112 Test the <= operator.113 """114 self.assertTrue(parse("1 <= 2"))115 self.assertFalse(parse("3 <= 2"))116 self.assertTrue(parse("false || (1 <= 2)"))117 self.assertTrue(parse("1 < 2 && true"))118 self.assertTrue(parse("true && 1 <= 2"))119 self.assertTrue(parse("!(5 <= 1)"))120 self.assertTrue(parse("'abc' <= 'def'"))121 self.assertTrue(parse("1 <= 1"))122 self.assertTrue(parse("'abc' <= 'abc'"))123 def test_greater_or_equals_than(self):124 """125 Test the > operator.126 """127 self.assertTrue(parse("2 >= 1"))128 self.assertFalse(parse("2 >= 3"))129 self.assertTrue(parse("false || (2 >= 1)"))130 self.assertTrue(parse("2 >= 1 && true"))131 self.assertTrue(parse("true && 2 >= 1"))132 self.assertTrue(parse("!(1 >= 5)"))133 self.assertTrue(parse("'def' >= 'abc'"))134 self.assertTrue(parse("1 >= 1"))135 self.assertTrue(parse("'abc' >= 'abc'"))136if __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 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