Best Python code snippet using avocado_python
get_parents_test.py
Source:get_parents_test.py
...12 b = Normal(a, 1.0)13 c = Normal(0.0, 1.0)14 d = Normal(c, 1.0)15 e = Normal(b * d, 1.0)16 self.assertEqual(get_parents(a), [])17 self.assertEqual(get_parents(b), [a])18 self.assertEqual(get_parents(c), [])19 self.assertEqual(get_parents(d), [c])20 self.assertEqual(set(get_parents(e)), set([b, d]))21 def test_a_structure(self):22 """e <- d <- a -> b -> c"""23 with self.test_session():24 a = Normal(0.0, 1.0)25 b = Normal(a, 1.0)26 c = Normal(b, 1.0)27 d = Normal(a, 1.0)28 e = Normal(d, 1.0)29 self.assertEqual(get_parents(a), [])30 self.assertEqual(get_parents(b), [a])31 self.assertEqual(get_parents(c), [b])32 self.assertEqual(get_parents(d), [a])33 self.assertEqual(get_parents(e), [d])34 def test_chain_structure(self):35 """a -> b -> c -> d -> e"""36 with self.test_session():37 a = Normal(0.0, 1.0)38 b = Normal(a, 1.0)39 c = Normal(b, 1.0)40 d = Normal(c, 1.0)41 e = Normal(d, 1.0)42 self.assertEqual(get_parents(a), [])43 self.assertEqual(get_parents(b), [a])44 self.assertEqual(get_parents(c), [b])45 self.assertEqual(get_parents(d), [c])46 self.assertEqual(get_parents(e), [d])47 def test_tensor(self):48 with self.test_session():49 a = Normal(0.0, 1.0)50 b = tf.constant(2.0)51 c = a + b52 d = Normal(c, 1.0)53 self.assertEqual(get_parents(a), [])54 self.assertEqual(get_parents(b), [])55 self.assertEqual(get_parents(c), [a])56 self.assertEqual(get_parents(d), [a])57 def test_control_flow(self):58 with self.test_session():59 a = Bernoulli(0.5)60 b = Normal(0.0, 1.0)61 c = tf.constant(0.0)62 d = tf.cond(tf.cast(a, tf.bool), lambda: b, lambda: c)63 e = Normal(d, 1.0)64 self.assertEqual(get_parents(a), [])65 self.assertEqual(get_parents(b), [])66 self.assertEqual(get_parents(c), [])67 self.assertEqual(set(get_parents(d)), set([a, b]))68 self.assertEqual(set(get_parents(e)), set([a, b]))69 def test_scan(self):70 """copied from test_chain_structure"""71 def cumsum(x):72 return tf.scan(lambda a, x: a + x, x)73 with self.test_session():74 a = Normal(tf.ones([3]), tf.ones([3]))75 b = Normal(cumsum(a), tf.ones([3]))76 c = Normal(cumsum(b), tf.ones([3]))77 d = Normal(cumsum(c), tf.ones([3]))78 e = Normal(cumsum(d), tf.ones([3]))79 self.assertEqual(get_parents(a), [])80 self.assertEqual(get_parents(b), [a])81 self.assertEqual(get_parents(c), [b])82 self.assertEqual(get_parents(d), [c])83 self.assertEqual(get_parents(e), [d])84if __name__ == '__main__':...
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!!