← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/turnip:py3-test-hooks-bytes-strings into turnip:master

 

Thiago F. Pappacena has proposed merging ~pappacena/turnip:py3-test-hooks-bytes-strings into turnip:master.

Commit message:
Making test_hooks compatible with python3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/turnip/+git/turnip/+merge/394146
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/turnip:py3-test-hooks-bytes-strings into turnip:master.
diff --git a/turnip/pack/hooks/hook.py b/turnip/pack/hooks/hook.py
index de9aa5c..e0257b2 100755
--- a/turnip/pack/hooks/hook.py
+++ b/turnip/pack/hooks/hook.py
@@ -37,7 +37,7 @@ def check_ancestor(old, new):
         return False
     # https://git-scm.com/docs/git-merge-base#_discussion
     return_code = subprocess.call(
-        ['git', 'merge-base', '--is-ancestor', old, new])
+        [b'git', b'merge-base', b'--is-ancestor', old, new])
     return return_code == 0
 
 
diff --git a/turnip/pack/tests/test_hooks.py b/turnip/pack/tests/test_hooks.py
index 374097f..bef4aae 100644
--- a/turnip/pack/tests/test_hooks.py
+++ b/turnip/pack/tests/test_hooks.py
@@ -374,7 +374,7 @@ class TestUpdateHook(TestCase):
     def patched_ancestor_check(self, old, new):
         # Avoid a subprocess call to execute on a git repository
         # that we haven't created.
-        if old == 'old':
+        if old == b'old':
             return False
         return True
 
@@ -387,11 +387,11 @@ class TestUpdateHook(TestCase):
     def test_fast_forward(self):
         # If the old sha is a merge ancestor of the new
         self.assertEqual(
-            [], hook.match_update_rules({}, ['ref', 'somehex', 'new']))
+            [], hook.match_update_rules({}, [b'ref', b'somehex', b'new']))
 
     def test_rules_fall_through(self):
         # The default is to deny
-        output = hook.match_update_rules({}, ['ref', 'old', 'new'])
+        output = hook.match_update_rules({}, [b'ref', b'old', b'new'])
         self.assertEqual(
             [b'You do not have permission to force-push to ref.'], output)
 
@@ -399,14 +399,14 @@ class TestUpdateHook(TestCase):
         # No matches means deny by default
         output = hook.match_update_rules(
             {'notamatch': []},
-            [b'ref', 'old', 'new'])
+            [b'ref', b'old', b'new'])
         self.assertEqual(
             [b'You do not have permission to force-push to ref.'], output)
 
     def test_no_matching_non_utf8_ref(self):
         # An unmatched non-UTF-8 ref is denied.
         output = hook.match_update_rules(
-            {}, [b'refs/heads/\x80', 'old', 'new'])
+            {}, [b'refs/heads/\x80', b'old', b'new'])
         self.assertEqual(
             [b'You do not have permission to force-push to refs/heads/\x80.'],
             output)
@@ -414,7 +414,7 @@ class TestUpdateHook(TestCase):
     def test_no_matching_utf8_ref(self):
         # An unmatched UTF-8 ref is denied.
         output = hook.match_update_rules(
-            {}, [u'refs/heads/géag'.encode('UTF-8'), 'old', 'new'])
+            {}, [u'refs/heads/géag'.encode('UTF-8'), b'old', b'new'])
         self.assertEqual(
             [b'You do not have permission to force-push to '
              b'refs/heads/g\xc3\xa9ag.'],
@@ -423,8 +423,8 @@ class TestUpdateHook(TestCase):
     def test_matching_ref(self):
         # Permission given to force-push
         output = hook.match_update_rules(
-            {'ref': ['force_push']},
-            ['ref', 'old', 'new'])
+            {b'ref': ['force_push']},
+            [b'ref', b'old', b'new'])
         self.assertEqual([], output)
 
     def test_matching_non_utf8_ref(self):
@@ -444,8 +444,8 @@ class TestUpdateHook(TestCase):
     def test_no_permission(self):
         # User does not have permission to force-push
         output = hook.match_update_rules(
-            {'ref': ['create']},
-            ['ref', 'old', 'new'])
+            {b'ref': ['create']},
+            [b'ref', b'old', b'new'])
         self.assertEqual(
             [b'You do not have permission to force-push to ref.'], output)
 
@@ -463,35 +463,37 @@ class TestDeterminePermissions(TestCase):
     def test_no_match_fallthrough(self):
         # No matching rule is deny by default
         output = hook.determine_permissions_outcome(
-            'old', 'ref', {})
+            b'old', b'ref', {})
         self.assertEqual(b"You do not have permission to push to ref.", output)
 
     def test_match_no_permissions(self):
         output = hook.determine_permissions_outcome(
-            'old', 'ref', {'ref': []})
+            b'old', b'ref', {'ref': []})
         self.assertEqual(b"You do not have permission to push to ref.", output)
 
     def test_match_with_create(self):
         output = hook.determine_permissions_outcome(
-            pygit2.GIT_OID_HEX_ZERO, 'ref', {'ref': ['create']})
+            six.ensure_binary(pygit2.GIT_OID_HEX_ZERO),
+            b'ref', {b'ref': ['create']})
         self.assertIsNone(output)
 
     def test_match_no_create_perms(self):
         output = hook.determine_permissions_outcome(
-            pygit2.GIT_OID_HEX_ZERO, 'ref', {'ref': []})
+            six.ensure_binary(pygit2.GIT_OID_HEX_ZERO), b'ref', {b'ref': []})
         self.assertEqual(b"You do not have permission to create ref.", output)
 
     def test_push(self):
         output = hook.determine_permissions_outcome(
-            'old', 'ref', {'ref': ['push']})
+            b'old', b'ref', {b'ref': ['push']})
         self.assertIsNone(output)
 
     def test_force_push(self):
         output = hook.determine_permissions_outcome(
-            'old', 'ref', {'ref': ['force_push']})
+            b'old', b'ref', {b'ref': ['force_push']})
         self.assertIsNone(output)
 
     def test_force_push_does_not_imply_create(self):
         output = hook.determine_permissions_outcome(
-            pygit2.GIT_OID_HEX_ZERO, 'ref', {'ref': ['force_push']})
+            six.ensure_binary(pygit2.GIT_OID_HEX_ZERO),
+            b'ref', {b'ref': ['force_push']})
         self.assertEqual(b"You do not have permission to create ref.", output)