Merge ~cjwatson/turnip:remove-py2-rmtree-workarounds into turnip:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: ee2084faea189acbfb093ee52b2b12862e134aa2
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/turnip:remove-py2-rmtree-workarounds
Merge into: turnip:master
Diff against target: 86 lines (+9/-19)
2 files modified
turnip/api/store.py (+0/-4)
turnip/pack/tests/test_functional.py (+9/-15)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+405050@code.launchpad.net

Commit message

Remove workarounds for Python 2's shutil.rmtree

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/turnip/api/store.py b/turnip/api/store.py
2index 06d3e1c..f56962d 100644
3--- a/turnip/api/store.py
4+++ b/turnip/api/store.py
5@@ -466,10 +466,6 @@ def set_default_branch(repo_path, target):
6
7 def delete_repo(repo_path):
8 """Permanently delete a git repository from repo store."""
9- # XXX cjwatson 2018-11-20: Python 2's shutil.rmtree crashes if given a
10- # Unicode path to a directory that contains non-UTF-8 files.
11- if not isinstance(repo_path, bytes):
12- repo_path = repo_path.encode('UTF-8')
13 shutil.rmtree(repo_path)
14
15
16diff --git a/turnip/pack/tests/test_functional.py b/turnip/pack/tests/test_functional.py
17index cbc77f8..dbeb2dc 100644
18--- a/turnip/pack/tests/test_functional.py
19+++ b/turnip/pack/tests/test_functional.py
20@@ -103,20 +103,16 @@ class FunctionalTestMixin(WithScenarios):
21
22 def startHookRPC(self):
23 self.hookrpc_handler = HookRPCHandler(self.virtinfo_url, 15)
24- # XXX cjwatson 2018-11-20: Use bytes so that shutil.rmtree doesn't
25- # get confused on Python 2.
26- dir = tempfile.mkdtemp(prefix=b'turnip-test-hook-')
27+ dir = tempfile.mkdtemp(prefix='turnip-test-hook-')
28 self.addCleanup(shutil.rmtree, dir, ignore_errors=True)
29
30- self.hookrpc_sock_path = os.path.join(dir, b'hookrpc_sock')
31+ self.hookrpc_sock_path = os.path.join(dir, 'hookrpc_sock')
32 self.hookrpc_listener = reactor.listenUNIX(
33 self.hookrpc_sock_path, HookRPCServerFactory(self.hookrpc_handler))
34 self.addCleanup(self.hookrpc_listener.stopListening)
35
36 def startPackBackend(self):
37- # XXX cjwatson 2018-11-20: Use bytes so that shutil.rmtree doesn't
38- # get confused on Python 2.
39- self.root = tempfile.mkdtemp(prefix=b'turnip-test-root-')
40+ self.root = tempfile.mkdtemp(prefix='turnip-test-root-')
41 self.addCleanup(shutil.rmtree, self.root, ignore_errors=True)
42 self.statsd_client = MockStatsd()
43 self.backend_listener = reactor.listenTCP(
44@@ -670,10 +666,10 @@ class FrontendFunctionalTestMixin(FunctionalTestMixin):
45 self.startVirtInfo()
46 self.startHookRPC()
47 self.startPackBackend()
48- self.internal_name = six.ensure_binary(hashlib.sha256(
49- b'/test').hexdigest())
50+ self.internal_name = hashlib.sha256(b'/test').hexdigest()
51 yield self.assertCommandSuccess(
52- (b'git', b'init', b'--bare', self.internal_name), path=self.root)
53+ (b'git', b'init', b'--bare', self.internal_name.encode()),
54+ path=self.root)
55
56 self.virt_listener = reactor.listenTCP(
57 0,
58@@ -724,8 +720,7 @@ class FrontendFunctionalTestMixin(FunctionalTestMixin):
59 yield self.assertCommandSuccess(
60 (b'git', b'push', b'origin', b'master'), path=clone1)
61 self.assertEqual(
62- six.ensure_text(self.internal_name),
63- self.virtinfo.push_notifications[0][0])
64+ self.internal_name, self.virtinfo.push_notifications[0][0])
65
66 @defer.inlineCallbacks
67 def test_unicode_fault(self):
68@@ -842,8 +837,7 @@ class TestSmartHTTPFrontendFunctional(FrontendFunctionalTestMixin, TestCase):
69 head_target = yield self.get_symbolic_ref(repo, b'HEAD')
70 self.assertEqual(b'refs/heads/new-head', head_target)
71 self.assertEqual(
72- six.ensure_text(self.internal_name),
73- self.virtinfo.push_notifications[0][0])
74+ self.internal_name, self.virtinfo.push_notifications[0][0])
75 self.assertIsNotNone(
76 self.virtinfo.push_notifications[0][1].get('pack_count'))
77 self.assertIsNotNone(
78@@ -935,7 +929,7 @@ class TestSmartHTTPFrontendWithAuthFunctional(TestSmartHTTPFrontendFunctional):
79 (b'git', b'push', b'origin', b'master'), path=clone)
80 self.assertThat(self.virtinfo.ref_permissions_checks, MatchesListwise([
81 MatchesListwise([
82- Equals(six.ensure_text(self.internal_name)),
83+ Equals(self.internal_name),
84 Equals([b'refs/heads/master']),
85 MatchesDict({
86 'can-authenticate': Is(True),

Subscribers

People subscribed via source and target branches