def testFunctionImportIsAdded(self): imports, _, _ = create_python_api.get_api_init_text( packages=[create_python_api._DEFAULT_PACKAGE], packages_to_ignore=[], output_package='tensorflow', api_name='tensorflow', api_version=1) if create_python_api._LAZY_LOADING: expected_import = ( '\'test_op1\': ' '(\'tensorflow.python.test_module\',' ' \'test_op\')') else: expected_import = ( 'from tensorflow.python.test_module ' 'import test_op as test_op1') self.assertTrue( expected_import in str(imports), msg='%s not in %s' % (expected_import, str(imports))) if create_python_api._LAZY_LOADING: expected_import = ( '\'test_op\': ' '(\'tensorflow.python.test_module\',' ' \'test_op\')') else: expected_import = ( 'from tensorflow.python.test_module ' 'import test_op') self.assertTrue( expected_import in str(imports), msg='%s not in %s' % (expected_import, str(imports))) # Also check that compat.v1 is not added to imports. self.assertFalse('compat.v1' in imports, msg='compat.v1 in %s' % str(imports.keys()))
def testClassImportIsAdded(self): imports = create_python_api.get_api_init_text( package=create_python_api._DEFAULT_PACKAGE, output_package='tensorflow', api_name='tensorflow') expected_import = ('from tensorflow.python.test_module ' 'import TestClass') self.assertTrue('TestClass' in str(imports), msg='%s not in %s' % (expected_import, str(imports)))
def testConstantIsAdded(self): imports = create_python_api.get_api_init_text( package=create_python_api._DEFAULT_PACKAGE, output_package='tensorflow', api_name='tensorflow', api_version=1) expected = ('from tensorflow.python.test_module ' 'import _TEST_CONSTANT') self.assertTrue(expected in str(imports), msg='%s not in %s' % (expected, str(imports)))
def testClassImportIsAdded(self): imports = create_python_api.get_api_init_text( package=create_python_api._DEFAULT_PACKAGE, output_package='tensorflow', api_name='tensorflow', api_version=2) expected_import = ('from tensorflow.python.test_module ' 'import TestClass') self.assertTrue( 'TestClass' in str(imports), msg='%s not in %s' % (expected_import, str(imports)))
def testClassImportIsAdded(self): imports, _ = create_python_api.get_api_init_text( packages=[create_python_api._DEFAULT_PACKAGE], output_package='tensorflow', api_name='tensorflow', api_version=2) expected_import = ('\'NewTestClass\':' ' (\'tensorflow.python.test_module\',' ' \'TestClass\')') self.assertTrue('TestClass' in str(imports), msg='%s not in %s' % (expected_import, str(imports)))
def testCompatModuleIsAdded(self): imports, _ = create_python_api.get_api_init_text( packages=[create_python_api._DEFAULT_PACKAGE], output_package='tensorflow', api_name='tensorflow', api_version=2, compat_api_versions=[1]) self.assertTrue('compat.v1' in imports, msg='compat.v1 not in %s' % str(imports.keys())) self.assertTrue('compat.v1.test' in imports, msg='compat.v1.test not in %s' % str(imports.keys()))
def testCompatModuleIsAdded(self): imports = create_python_api.get_api_init_text( packages=[create_python_api._DEFAULT_PACKAGE], output_package='tensorflow', api_name='tensorflow', api_version=2, compat_api_versions=[1]) self.assertTrue('compat.v1' in imports, msg='compat.v1 not in %s' % str(imports.keys())) self.assertTrue('compat.v1.test' in imports, msg='compat.v1.test not in %s' % str(imports.keys()))
def testConstantIsAdded(self): imports, _ = create_python_api.get_api_init_text( packages=[create_python_api._DEFAULT_PACKAGE], output_package='tensorflow', api_name='tensorflow', api_version=1) if create_python_api._LAZY_LOADING: expected = ('\'_TEST_CONSTANT\':' ' (\'tensorflow.python.test_module\',' ' \'_TEST_CONSTANT\')') else: expected = ('from tensorflow.python.test_module ' 'import _TEST_CONSTANT') self.assertTrue(expected in str(imports), msg='%s not in %s' % (expected, str(imports)))
def testDeprecatedAliasIsAdded(self): imports = create_python_api.get_api_init_text( packages=[create_python_api._DEFAULT_PACKAGE], output_package='tensorflow', api_name='tensorflow', api_version=1) expected_import = ('from tensorflow.python.test_module ' 'import deprecated_test_op as _deprecated_test_op') self.assertTrue(expected_import in str(imports), msg='%s not in %s' % (expected_import, str(imports))) expected_import = ( 'foo = _deprecated_alias(\'tf.test.foo\', \'tf.foo\', ' '_deprecated_test_op)') self.assertTrue(expected_import in str(imports), msg='%s not in %s' % (expected_import, str(imports)))
def testNestedCompatModulesAreAdded(self): imports, _, _ = create_python_api.get_api_init_text( packages=[create_python_api._DEFAULT_PACKAGE], packages_to_ignore=[], output_package='tensorflow', api_name='tensorflow', api_version=2, compat_api_versions=[1, 2]) self.assertIn('compat.v1.compat.v1', imports, msg='compat.v1.compat.v1 not in %s' % str(imports.keys())) self.assertIn('compat.v1.compat.v2', imports, msg='compat.v1.compat.v2 not in %s' % str(imports.keys())) self.assertIn('compat.v2.compat.v1', imports, msg='compat.v2.compat.v1 not in %s' % str(imports.keys())) self.assertIn('compat.v2.compat.v2', imports, msg='compat.v2.compat.v2 not in %s' % str(imports.keys()))
def testFunctionImportIsAdded(self): imports = create_python_api.get_api_init_text( package=create_python_api._DEFAULT_PACKAGE, output_package='tensorflow', api_name='tensorflow', api_version=1) expected_import = ( 'from tensorflow.python.test_module ' 'import test_op as test_op1') self.assertTrue( expected_import in str(imports), msg='%s not in %s' % (expected_import, str(imports))) expected_import = ('from tensorflow.python.test_module ' 'import test_op') self.assertTrue( expected_import in str(imports), msg='%s not in %s' % (expected_import, str(imports)))
def testDeprecatedAliasIsAdded(self): imports = create_python_api.get_api_init_text( packages=[create_python_api._DEFAULT_PACKAGE], output_package='tensorflow', api_name='tensorflow', api_version=1) expected_import = ( 'from tensorflow.python.test_module ' 'import deprecated_test_op as _deprecated_test_op') self.assertTrue( expected_import in str(imports), msg='%s not in %s' % (expected_import, str(imports))) expected_import = ( 'foo = _deprecated_alias(\'tf.test.foo\', \'tf.foo\', ' '_deprecated_test_op)') self.assertTrue( expected_import in str(imports), msg='%s not in %s' % (expected_import, str(imports)))
def testFunctionImportIsAdded(self): imports = create_python_api.get_api_init_text( package=create_python_api._DEFAULT_PACKAGE, output_package='tensorflow', api_name='tensorflow', api_version=1) expected_import = ('from tensorflow.python.test_module ' 'import test_op as test_op1') self.assertTrue(expected_import in str(imports), msg='%s not in %s' % (expected_import, str(imports))) expected_import = ('from tensorflow.python.test_module ' 'import test_op') self.assertTrue(expected_import in str(imports), msg='%s not in %s' % (expected_import, str(imports))) # Also check that compat.v1 is not added to imports. self.assertFalse('compat.v1' in imports, msg='compat.v1 in %s' % str(imports.keys()))
def testFunctionImportIsAdded(self): imports = create_python_api.get_api_init_text( package=create_python_api._DEFAULT_PACKAGE, output_package='tensorflow', api_name='tensorflow', api_version=1) expected_import = ( 'from tensorflow.python.test_module ' 'import test_op as test_op1') self.assertTrue( expected_import in str(imports), msg='%s not in %s' % (expected_import, str(imports))) expected_import = ('from tensorflow.python.test_module ' 'import test_op') self.assertTrue( expected_import in str(imports), msg='%s not in %s' % (expected_import, str(imports))) # Also check that compat.v1 is not added to imports. self.assertFalse('compat.v1' in imports, msg='compat.v1 in %s' % str(imports.keys()))