add test for out of order methods (#17624)
authorMichael Suo <suo@fb.com>
Tue, 12 Mar 2019 02:07:57 +0000 (19:07 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 12 Mar 2019 02:13:54 +0000 (19:13 -0700)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17624

Just to make sure this path works

Reviewed By: shannonzhu

Differential Revision: D14288056

fbshipit-source-id: b719c0e90252b6821b1f9b22d3d98982985a6cb3

test/test_jit.py

index 47c408f..f769173 100644 (file)
@@ -13758,6 +13758,26 @@ class TestClassType(JitTestCase):
             input = torch.ones(1)
             self.assertEqual(fn2(input), input)
 
+    def test_out_of_order_methods(self):
+        # Remove this when import/export is implemented for classes
+        with self.disableModuleHook():
+            @torch.jit.script
+            class FooTest:
+                def __init__(self, x):
+                    self.x = x
+                    self.x = self.get_stuff(x)
+
+                def get_stuff(self, y):
+                    return self.x + y
+
+            @torch.jit.script
+            def fn(x):
+                f = FooTest(x)
+                return f.x
+
+            input = torch.ones(1)
+            self.assertEqual(fn(input), input + input)
+
 
 for test in autograd_method_tests():
     add_autograd_test(*test)