فهرست منبع

[test] convert remaining nose based test to pytest (#3705)

Ayush Goyal 1 سال پیش
والد
کامیت
432cd98818

+ 15 - 6
apps/beeswax/src/beeswax/test_base.py

@@ -77,7 +77,10 @@ def _start_server(cluster):
 
   env = cluster._mr2_env.copy()
 
-  hadoop_cp_proc = subprocess.Popen(args=[get_run_root('ext/hadoop/hadoop') + '/bin/hadoop', 'classpath'], env=env, cwd=cluster._tmpdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+  hadoop_cp_proc = subprocess.Popen(
+    args=[get_run_root('ext/hadoop/hadoop') + '/bin/hadoop', 'classpath'],
+    env=env, cwd=cluster._tmpdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE
+  )
   hadoop_cp_proc.wait()
   hadoop_cp = hadoop_cp_proc.stdout.read().strip()
 
@@ -343,10 +346,16 @@ def verify_history(client, fragment, design=None, reverse=False, server_name='be
   Return the size of the history; -1 if we fail to determine it.
   """
   resp = client.get('/%(server_name)s/query_history' % {'server_name': server_name})
-  my_assert = reverse and assert_false or assert_true
-  my_assert(fragment in resp.content, resp.content)
-  if design:
-    my_assert(design in resp.content, resp.content)
+  if reverse:
+    if fragment in resp.content:
+      raise AssertionError(f"Unexpected fragment '{fragment}' found in response:\n{resp.content}")
+    if design and design in resp.content:
+      raise AssertionError(f"Unexpected design '{design}' found in response:\n{resp.content}")
+  else:
+    if fragment not in resp.content:
+      raise AssertionError(f"Fragment '{fragment}' not found in response:\n{resp.content}")
+    if design and design not in resp.content:
+      raise AssertionError(f"Design '{design}' not found in response:\n{resp.content}")
 
   if resp.context:
     try:
@@ -377,7 +386,7 @@ class BeeswaxSampleProvider(TestCase):
     grant_access('test', 'test', 'metastore')
 
     # Weird redirection to avoid binding nonsense.
-    cls.shutdown = [ shutdown ]
+    cls.shutdown = [shutdown]
     cls.init_beeswax_db()
 
   @classmethod

+ 13 - 10
apps/metastore/src/metastore/tests.py

@@ -455,23 +455,26 @@ class TestMetastoreWithHadoop(BeeswaxSampleProvider):
     grant_access("write_access_frontend", "write_access_frontend", "metastore")
     user = User.objects.get(username='write_access_frontend')
     
-    def check(client, assertz):
-      response = client.get("/metastore/databases")
-      assertz("Drop</button>" in response.content, response.content)
-      assertz("Create a new database" in response.content, response.content)
-      
-      response = client.get("/metastore/tables/")
-      assertz("Drop</button>" in response.content, response.content)
-      assertz("Create a new table" in response.content, response.content)
+    response = client.get("/metastore/databases")
+    assert not "Drop</button>" in response.content, response.content
+    assert not "Create a new database" in response.content, response.content
     
-    check(client, assert_false)
+    response = client.get("/metastore/tables/")
+    assert not "Drop</button>" in response.content, response.content
+    assert not "Create a new table" in response.content, response.content
     
     # Add access
     group, created = Group.objects.get_or_create(name='write_access_frontend')
     perm, created = HuePermission.objects.get_or_create(app='metastore', action='write')
     GroupPermission.objects.get_or_create(group=group, hue_permission=perm)
+
+    response = client.get("/metastore/databases")
+    assert "Drop</button>" in response.content, response.content
+    assert "Create a new database" in response.content, response.content
     
-    check(client, assert_true)
+    response = client.get("/metastore/tables/")
+    assert "Drop</button>" in response.content, response.content
+    assert "Create a new table" in response.content, response.content
   
   def test_has_write_access_backend(self):
     client = make_logged_in_client(username='write_access_backend', groupname='write_access_backend',

+ 4 - 6
apps/security/src/security/tests.py

@@ -33,19 +33,17 @@ class TestSecurity(object):
     grant_access("test_permissions", "test_permissions", "security")
     user = User.objects.get(username='test_permissions')
 
-    def check(client, assertz):
-      response = client.get(reverse("security:hive"))
-      assertz("Impersonate the user" in response.content, response.content)
-
     # Forbidden
-    check(client, assert_false)
+    response = client.get(reverse("security:hive"))
+    assert not "Impersonate the user" in response.content, response.content
 
     # Allowed
     group, created = Group.objects.get_or_create(name='test_permissions')
     perm, created = HuePermission.objects.get_or_create(app='security', action='impersonate')
     GroupPermission.objects.get_or_create(group=group, hue_permission=perm)
 
-    check(client, assert_true)
+    response = client.get(reverse("security:hive"))
+    assert "Impersonate the user" in response.content, response.content
 
   def test_permissions(self):
     privilege = {

+ 4 - 2
desktop/libs/hadoop/src/hadoop/fs/test_webhdfs.py

@@ -306,9 +306,11 @@ class WebhdfsTests(TestCase):
       sys.setdefaultencoding('utf-8')
 
     def check_existence(name, parent, present=True):
-      assertion = present and assert_true or assert_false
       listing = self.cluster.fs.listdir(parent)
-      assertion(name in listing, "%s should be in %s" % (name, listing))
+      if present:
+        assert name in listing, f"{name} should be in {listing}"
+      else:
+        assert not name in listing, f"{name} should not be in {listing}"
 
     name = u'''pt-Olá_ch-你好_ko-안녕_ru-Здравствуйте%20,.<>~`!@$%^&()_-+='"'''
     prefix = self.prefix + '/tmp/i18n'