Ver Fonte

HUE-8737 [hdfs] Fix webhdfs unit tests in py3
test_with_core_site (azure.tests.TestAzureAbfs)
test_with_credentials (azure.tests.TestAzureAbfs)
test_with_core_site (azure.tests.TestAzureAdl)
test_with_credentials (azure.tests.TestAzureAdl)
hadoop.tests.test_tricky_confparse
hadoop.tests.test_config_validator_basic

Ying Chen há 6 anos atrás
pai
commit
467955164b

+ 4 - 4
desktop/libs/azure/src/azure/tests.py

@@ -43,7 +43,7 @@ class TestAzureAdl(unittest.TestCase):
       finish = (conf.AZURE_ACCOUNTS.set_for_testing({'default': {}}),
                 conf.ADLS_CLUSTERS.set_for_testing({'default': {'fs_defaultfs': 'fs_defaultfs', 'webhdfs_url': 'webhdfs_url'}}))
       with patch('azure.client.conf_idbroker.get_conf') as get_conf:
-        with patch('azure.client.WebHdfs'):
+        with patch('azure.client.WebHdfs.get_client'):
           with patch('azure.client.ActiveDirectory.get_token') as get_token:
             with patch('azure.conf.core_site.get_conf') as core_site_get_conf:
               get_token.return_value = {'access_token': 'access_token', 'token_type': '', 'expires_on': None}
@@ -65,7 +65,7 @@ class TestAzureAdl(unittest.TestCase):
       finish = (conf.AZURE_ACCOUNTS.set_for_testing({'default': {'client_id':'client_id', 'client_secret': 'client_secret', 'tenant_id': 'tenant_id'}}),
                 conf.ADLS_CLUSTERS.set_for_testing({'default': {'fs_defaultfs': 'fs_defaultfs', 'webhdfs_url': 'webhdfs_url'}}))
       with patch('azure.client.conf_idbroker.get_conf') as get_conf:
-        with patch('azure.client.WebHdfs'):
+        with patch('azure.client.WebHdfs.get_client'):
           with patch('azure.client.ActiveDirectory.get_token') as get_token:
             get_token.return_value = {'access_token': 'access_token', 'token_type': '', 'expires_on': None}
             get_conf.return_value = {}
@@ -121,7 +121,7 @@ class TestAzureAbfs(unittest.TestCase):
       finish = (conf.AZURE_ACCOUNTS.set_for_testing({'default': {}}),
                 conf.ABFS_CLUSTERS.set_for_testing({'default': {'fs_defaultfs': 'fs_defaultfs', 'webhdfs_url': 'webhdfs_url'}}))
       with patch('azure.client.conf_idbroker.get_conf') as get_conf:
-        with patch('azure.client.ABFS'):
+        with patch('azure.client.ABFS.get_client'):
           with patch('azure.client.ActiveDirectory.get_token') as get_token:
             with patch('azure.conf.core_site.get_conf') as core_site_get_conf:
               get_token.return_value = {'access_token': 'access_token', 'token_type': '', 'expires_on': None}
@@ -143,7 +143,7 @@ class TestAzureAbfs(unittest.TestCase):
       finish = (conf.AZURE_ACCOUNTS.set_for_testing({'default': {'client_id':'client_id', 'client_secret': 'client_secret', 'tenant_id': 'tenant_id'}}),
                 conf.ABFS_CLUSTERS.set_for_testing({'default': {'fs_defaultfs': 'fs_defaultfs', 'webhdfs_url': 'webhdfs_url'}}))
       with patch('azure.client.conf_idbroker.get_conf') as get_conf:
-        with patch('azure.client.ABFS'):
+        with patch('azure.client.ABFS.get_client'):
           with patch('azure.client.ActiveDirectory.get_token') as get_token:
             get_token.return_value = {'access_token': 'access_token', 'token_type': '', 'expires_on': None}
             get_conf.return_value = {}

+ 3 - 5
desktop/libs/hadoop/src/hadoop/tests.py

@@ -36,10 +36,8 @@ from hadoop import pseudo_hdfs4
 
 if sys.version_info[0] > 2:
   from io import BytesIO as string_io
-  open_file = open
 else:
   from cStringIO import StringIO as string_io
-  open_file = file
 
 def test_confparse():
   data = """
@@ -91,9 +89,9 @@ def test_tricky_confparse():
   We found (experimentally) that dealing with a file
   sometimes triggered the wrong results here.
   """
-  cp_data = confparse.ConfParse(open_file(os.path.join(os.path.dirname(__file__),
+  cp_data = confparse.ConfParse(open(os.path.join(os.path.dirname(__file__),
                                                   "test_data",
-                                                  "sample_conf.xml")))
+                                                  "sample_conf.xml"), 'rb'))
   assert_equal("org.apache.hadoop.examples.SleepJob", cp_data["mapred.mapper.class"])
 
 
@@ -108,7 +106,7 @@ def test_config_validator_basic():
   try:
     cli = make_logged_in_client()
     resp = cli.get('/desktop/debug/check_config')
-    assert_true('hadoop.hdfs_clusters.default.webhdfs_url' in resp.content)
+    assert_true(b'hadoop.hdfs_clusters.default.webhdfs_url' in resp.content)
   finally:
     for old_conf in reset:
       old_conf()