[gnome-keysign: 5/16] test_gpgmeh: remove deprecated assert_equals



commit b454a64cc3795632bc131eb997c073d6f8c59741
Author: RyuzakiKK <aasonykk gmail com>
Date:   Wed Dec 5 16:02:56 2018 +0100

    test_gpgmeh: remove deprecated assert_equals

 tests/test_gpgmeh.py | 133 +++++++++++++++++++++++++--------------------------
 1 file changed, 65 insertions(+), 68 deletions(-)
---
diff --git a/tests/test_gpgmeh.py b/tests/test_gpgmeh.py
index 200bf64..faa5828 100644
--- a/tests/test_gpgmeh.py
+++ b/tests/test_gpgmeh.py
@@ -49,15 +49,18 @@ def get_fixture_dir(fixture=""):
     dname = os.path.join(thisdir, "fixtures", fixture)
     return dname
 
+
 def get_fixture_file(fixture):
     fname = os.path.join(get_fixture_dir(), fixture)
     return fname
 
+
 def read_fixture_file(fixture):
     fname = get_fixture_file(fixture)
     data = open(fname, 'rb').read()
     return data
 
+
 @raises(ValueError)
 def test_uid_export_0():
     "You should not be able to export uid < 1"
@@ -65,6 +68,7 @@ def test_uid_export_0():
     uid_data = UIDExport(data, 0)
     assert False
 
+
 def test_uid_export_single():
     # This key contains only one UID
     data = read_fixture_file("pubkey-1.asc")
@@ -81,7 +85,7 @@ def test_uid_export_single():
     logging.info("Result: %r", result)
     fpr = result.imports[0].fpr
     uids = c.get_key(fpr).uids
-    assert_equals(1, len(uids))
+    assert_equal(1, len(uids))
 
     # The first exported UID
     c = TempContext()
@@ -89,12 +93,12 @@ def test_uid_export_single():
     c.op_import(uid1_data)
     result = c.op_import_result()
     imports = result.imports
-    assert_equals(1, len(imports))
+    assert_equal(1, len(imports))
     uids1_key = c.get_key(fpr).uids
-    assert_equals(1, len(uids1_key))
+    assert_equal(1, len(uids1_key))
     uid1 = uids1_key[0]
-    # assert_equals(uid1, uids[0])
-    assert_equals(uid1.uid, uids[0].uid)
+    # assert_equal(uid1, uids[0])
+    assert_equal(uid1.uid, uids[0].uid)
 
 
 def test_uid_export_double():
@@ -108,7 +112,7 @@ def test_uid_export_double():
         log.exception("Meh.")
         raise RuntimeError()
 
-    assert_not_equals(uid1_data, uid2_data)
+    assert_not_equal(uid1_data, uid2_data)
 
     # The original key
     c = TempContext()
@@ -117,7 +121,7 @@ def test_uid_export_double():
     logging.info("Result: %r", result)
     fpr = result.imports[0].fpr
     uids = c.get_key(fpr).uids
-    assert_equals(2, len(uids))
+    assert_equal(2, len(uids))
 
     # The first exported UID
     c = TempContext()
@@ -125,27 +129,25 @@ def test_uid_export_double():
     c.op_import(uid1_data)
     result = c.op_import_result()
     imports = result.imports
-    assert_equals(1, len(imports))
+    assert_equal(1, len(imports))
     uids1_key = c.get_key(fpr).uids
-    assert_equals(1, len(uids1_key))
+    assert_equal(1, len(uids1_key))
     uid1 = uids1_key[0]
-    # assert_equals(uid1, uids[0])
-    assert_equals(uid1.uid, uids[0].uid)
+    # assert_equal(uid1, uids[0])
+    assert_equal(uid1.uid, uids[0].uid)
 
     # The second exported UID
     c = TempContext()
     c.op_import(uid2_data)
     result = c.op_import_result()
     imports = result.imports
-    assert_equals(1, len(imports))
+    assert_equal(1, len(imports))
     uids2_key = c.get_key(fpr).uids
-    assert_equals(1, len(uids2_key))
+    assert_equal(1, len(uids2_key))
     uid2 = uids2_key[0]
     # FIXME: The objects don't implement __eq__ it seems :-/
-    # assert_equals(uid2, uids[1])
-    assert_equals(uid2.uid, uids[1].uid)
-
-
+    # assert_equal(uid2, uids[1])
+    assert_equal(uid2.uid, uids[1].uid)
 
 
 def test_export_uids():
@@ -160,44 +162,42 @@ def test_export_uids():
     logging.info("Result: %r", result)
     fpr = result.imports[0].fpr
     uids = c.get_key(fpr).uids
-    assert_equals(2, len(uids))
+    assert_equal(2, len(uids))
 
     exported_uids = list(export_uids(data))
-    assert_equals(2, len(exported_uids))
+    assert_equal(2, len(exported_uids))
 
     exported_uid1 = exported_uids[0]
     uid1, uid1_data = exported_uid1
     exported_uid2 = exported_uids[1]
     uid2, uid2_data = exported_uid2
-    assert_equals(uids[0].uid, uid1)
-    assert_equals(uids[1].uid, uid2)
-
+    assert_equal(uids[0].uid, uid1)
+    assert_equal(uids[1].uid, uid2)
 
     # The first exported UID
     c = TempContext()
     c.op_import(uid1_data)
     result = c.op_import_result()
     imports = result.imports
-    assert_equals(1, len(imports))
+    assert_equal(1, len(imports))
     uids1_key = c.get_key(fpr).uids
-    assert_equals(1, len(uids1_key))
+    assert_equal(1, len(uids1_key))
     uid1_key = uids1_key[0]
-    # assert_equals(uid1, uids[0])
-    assert_equals(uid1_key.uid, uids[0].uid)
+    # assert_equal(uid1, uids[0])
+    assert_equal(uid1_key.uid, uids[0].uid)
 
     # The second exported UID
     c = TempContext()
     c.op_import(uid2_data)
     result = c.op_import_result()
     imports = result.imports
-    assert_equals(1, len(imports))
+    assert_equal(1, len(imports))
     uids2_key = c.get_key(fpr).uids
-    assert_equals(1, len(uids2_key))
+    assert_equal(1, len(uids2_key))
     uid2_key = uids2_key[0]
     # FIXME: The objects don't implement __eq__ it seems :-/
-    # assert_equals(uid2, uids[1])
-    assert_equals(uid2_key.uid, uids[1].uid)
-
+    # assert_equal(uid2, uids[1])
+    assert_equal(uid2_key.uid, uids[1].uid)
 
 
 def test_export_alpha_uids():
@@ -215,7 +215,7 @@ def test_export_alpha_uids():
     fpr = result.imports[0].fpr
     uids = c.get_key(fpr).uids
     logging.info("UIDs: %r", uids)
-    assert_equals(3, len(uids))
+    assert_equal(3, len(uids))
     
     for i, uid in enumerate(uids, start=1):
         exported_uid = UIDExport(data, i)
@@ -224,7 +224,7 @@ def test_export_alpha_uids():
         result = tmp.op_import_result()
         logging.debug("UID %d %r import result: %r", i, uid, result)
         uid_key = tmp.get_key(result.imports[0].fpr)
-        assert_equals(1, len(uid_key.uids))
+        assert_equal(1, len(uid_key.uids))
         key_uid = uid_key.uids[0]
         # FIXME: Enable __eq__
         # assert_equal(uids[i-1], key_uid)
@@ -232,7 +232,6 @@ def test_export_alpha_uids():
         assert_equal(uids[i-1].email, key_uid.email)
 
 
-
 @raises(ValueError)
 def test_fingerprint_from_data():
     fingerprint = fingerprint_from_keydata("This is not a key...")
@@ -245,23 +244,25 @@ class TestKey1:
         self.key = openpgpkey_from_data(data)
 
     def test_fingerprint(self):
-        assert_equals("ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55",
-                      self.key.fingerprint)
+        assert_equal("ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55",
+                     self.key.fingerprint)
 
     def test_uids(self):
         uids = self.key.uidslist
-        assert_equals(1, len(uids))
+        assert_equal(1, len(uids))
         uid = uids[0]
-        assert_equals('Joe Random Hacker',
-                      uid.name)
-        assert_equals('joe example com',
-                      uid.email)
+        assert_equal('Joe Random Hacker',
+                     uid.name)
+        assert_equal('joe example com',
+                     uid.email)
+
 
 @raises(ValueError)
 def test_get_public_key_no_data():
     tmp = tempfile.mkdtemp()
     d = get_public_key_data(None, homedir=tmp)
-    assert_equals("", d)
+    assert_equal("", d)
+
 
 class TestGetPublicKeyData:
     def setup(self):
@@ -288,13 +289,13 @@ class TestGetPublicKeyData:
         newkey = openpgpkey_from_data(data)
         # Hrm. We may be better off checking for a few things
         # we actually care about rather than delegating to the Key() itself.
-        assert_equals(self.originalkey, newkey)
+        assert_equal(self.originalkey, newkey)
 
     def test_get_public_key_data(self):
         fpr = self.originalkey.fingerprint
         data = get_public_key_data(fpr, homedir=self.homedir)
         newkey = openpgpkey_from_data(data)
-        assert_equals(fpr, newkey.fingerprint)
+        assert_equal(fpr, newkey.fingerprint)
 
     @raises(ValueError)
     def test_no_match(self):
@@ -304,11 +305,11 @@ class TestGetPublicKeyData:
         assert False
 
 
-
 def test_get_empty_usable_keys():
     homedir = tempfile.mkdtemp()
     keys = get_usable_keys(homedir=homedir)
-    assert_equals(0, len(keys))
+    assert_equal(0, len(keys))
+
 
 class TestGetUsableKeys:
     def setup(self):
@@ -330,18 +331,16 @@ class TestGetUsableKeys:
 
     def test_get_usable_key_no_pattern(self):
         keys = get_usable_keys(homedir=self.homedir)
-        assert_equals(1, len(keys))
+        assert_equal(1, len(keys))
         key = keys[0]
-        assert_equals(self.originalkey, key)
-
+        assert_equal(self.originalkey, key)
 
     def test_get_usable_key_fpr(self):
         fpr = self.originalkey.fingerprint
         keys = get_usable_keys(fpr, homedir=self.homedir)
-        assert_equals(1, len(keys))
+        assert_equal(1, len(keys))
         key = keys[0]
-        assert_equals(fpr, self.originalkey.fingerprint)
-
+        assert_equal(fpr, self.originalkey.fingerprint)
 
 
 class TestGetUsableSecretKeys:
@@ -364,18 +363,16 @@ class TestGetUsableSecretKeys:
 
     def test_get_usable_key_no_pattern(self):
         keys = get_usable_secret_keys(homedir=self.homedir)
-        assert_equals(1, len(keys))
+        assert_equal(1, len(keys))
         key = keys[0]
-        assert_equals(self.originalkey, key)
-
+        assert_equal(self.originalkey, key)
 
     def test_get_usable_key_fpr(self):
         fpr = self.originalkey.fingerprint
         keys = get_usable_secret_keys(fpr, homedir=self.homedir)
-        assert_equals(1, len(keys))
+        assert_equal(1, len(keys))
         key = keys[0]
-        assert_equals(fpr, self.originalkey.fingerprint)
-
+        assert_equal(fpr, self.originalkey.fingerprint)
 
 
 def get_signatures_for_uids_on_key(ctx, key):
@@ -442,17 +439,17 @@ class TestSignAndEncrypt:
         public_sender_key = sink.read()
 
         keys = get_usable_keys(homedir=self.key_sender_homedir)
-        assert_equals(1, len(keys))
+        assert_equal(1, len(keys))
         key = keys[0]
         uids = key.uidslist
         # Now finally call the function under test
         uid_encrypted = list(sign_keydata_and_encrypt(public_sender_key,
-            error_cb=None, homedir=self.key_receiver_homedir))
-        assert_equals(len(uids), len(uid_encrypted))
+                             error_cb=None, homedir=self.key_receiver_homedir))
+        assert_equal(len(uids), len(uid_encrypted))
 
         # We need to explicitly request signatures
         uids_before = uids
-        assert_equals (len(uids_before), len(sender.get_key(fpr).uids))
+        assert_equal(len(uids_before), len(sender.get_key(fpr).uids))
 
         sigs_before = [s for l in get_signatures_for_uids_on_key(sender,
                                     key).values() for s in l]
@@ -462,7 +459,7 @@ class TestSignAndEncrypt:
             uid_enc_str = uid_enc[0].uid
             # The test doesn't work so well, because comments
             # are not rendered :-/
-            # assert_equals(uid, uid_enc[0])
+            # assert_equal(uid, uid_enc[0])
             assert_in(uid.name, uid_enc_str)
             assert_in(uid.email, uid_enc_str)
             ciphertext = uid_enc[1]
@@ -472,7 +469,7 @@ class TestSignAndEncrypt:
             sender.op_import(plaintext)
             import_result = sender.op_import_result()
             log.debug("Import Result: %r", import_result)
-            assert_equals(1, import_result.new_signatures)
+            assert_equal(1, import_result.new_signatures)
             updated_key = sender.get_key(fpr)
             log.debug("updated key: %r", updated_key)
             log.debug("updated key sigs: %r", [(uid, uid.signatures) for uid in updated_key.uids])
@@ -513,8 +510,8 @@ class TestSignAndEncrypt:
         public_sender_key = sink.read()
         # Now finally call the function under test
         uid_encrypted = list(sign_keydata_and_encrypt(public_sender_key,
-            error_cb=None, homedir=self.key_receiver_homedir))
-        assert_equals(len(sender_key.uids), len(uid_encrypted))
+                             error_cb=None, homedir=self.key_receiver_homedir))
+        assert_equal(len(sender_key.uids), len(uid_encrypted))
 
         uids_before = sender.get_key(fpr).uids
         sigs_before = [s for l in get_signatures_for_uids_on_key(sender,
@@ -523,7 +520,7 @@ class TestSignAndEncrypt:
             uid_enc_str = uid_enc[0].uid
             log.info("Uid enc str: %r", uid_enc_str)
             log.info("Uid name: %r", uid.name)
-            # FIXME: assert_equals(uid, uid_enc[0])
+            # FIXME: assert_equal(uid, uid_enc[0])
             # It's a bit weird to re-use the string treatment here.
             # But gpgme may return unencodable bytes (and uid, here, is
             # coming straight from gpgme).  We opted for our UID wrapper
@@ -538,7 +535,7 @@ class TestSignAndEncrypt:
             import_result = sender.op_import_result()
             log.debug("Import Result: %r", import_result)
             # Here is the important check for two new signatures
-            assert_equals(2, import_result.new_signatures)
+            assert_equal(2, import_result.new_signatures)
             updated_key = sender.get_key(fpr)
             log.debug("updated key: %r", updated_key)
             log.debug("updated key sigs: %r", [(uid, uid.signatures) for uid in updated_key.uids])


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]