예제 #1
0
    def test_method(self):
        class TestClass(object):
            def test_fn(self, l):
                def inner_fn(i):
                    return i + 1

                l += 1
                return l, inner_fn(l)

        ns = {'TestClass': TestClass}
        node, ctx = self.prepare(TestClass, ns)
        node = function_scopes.transform(node, ctx)

        with self.compiled(node, {}, ops.name_scope) as result:
            first, second = result.TestClass().test_fn(constant_op.constant(1))
            self.assertIn('TestClass/test_fn/', first.op.name)
            self.assertNotIn('inner_fn', first.op.name)
            self.assertIn('TestClass/test_fn/inner_fn/', second.op.name)
  def test_method(self):

    class TestClass(object):

      def test_fn(self, l):

        def inner_fn(i):
          return i + 1

        l += 1
        return l, inner_fn(l)

    ns = {'TestClass': TestClass}
    node, ctx = self.prepare(TestClass, ns, owner_type=TestClass)
    node = function_scopes.transform(node, ctx)

    with self.compiled(node, {}, ops.name_scope) as result:
      first, second = result.TestClass().test_fn(constant_op.constant(1))
      self.assertIn('TestClass/test_fn/', first.op.name)
      self.assertNotIn('inner_fn', first.op.name)
      self.assertIn('TestClass/test_fn/inner_fn/', second.op.name)