Best Python code snippet using pyshould_python
test_custom_classes.py
Source:test_custom_classes.py
...10 library_filename = library_filename[0]11 path = os.path.abspath(library_filename)12 assert os.path.exists(path), path13 return path14def test_equality(f, cmp_key):15 obj1 = f()16 obj2 = jit.script(f)()17 return (cmp_key(obj1), cmp_key(obj2))18class TestCustomOperators(unittest.TestCase):19 def setUp(self):20 ops.load_library(get_custom_class_library_path())21 def test_no_return_class(self):22 def f():23 val = torch.classes.Foo(5, 3)24 return val.info()25 self.assertEqual(*test_equality(f, lambda x: x))26 def test_constructor_with_args(self):27 def f():28 val = torch.classes.Foo(5, 3)29 return val30 self.assertEqual(*test_equality(f, lambda x: x.info()))31 def test_function_call_with_args(self):32 def f():33 val = torch.classes.Foo(5, 3)34 val.increment(1)35 return val36 self.assertEqual(*test_equality(f, lambda x: x.info()))37 def test_function_method_wrong_type(self):38 def f():39 val = torch.classes.Foo(5, 3)40 val.increment("asdf")41 return val42 with self.assertRaisesRegex(RuntimeError, "Expected"):43 jit.script(f)()44 @unittest.skip("We currently don't support passing custom classes to custom methods.")45 def test_input_class_type(self):46 def f():47 val = torch.classes.Foo(1, 2)48 val2 = torch.classes.Foo(2, 3)49 val.combine(val2)50 return val51 self.assertEqual(*test_equality(f, lambda x: x.info()))52 def test_stack_string(self):53 def f():54 val = torch.classes.StackString(["asdf", "bruh"])55 return val.pop()56 self.assertEqual(*test_equality(f, lambda x: x))57 def test_stack_push_pop(self):58 def f():59 val = torch.classes.StackString(["asdf", "bruh"])60 val2 = torch.classes.StackString(["111", "222"])61 val.push(val2.pop())62 return val.pop() + val2.pop()63 self.assertEqual(*test_equality(f, lambda x: x))64if __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!!