Merge lp:~twom/loggerhead/fix-text-types-python-2 into lp:loggerhead

Proposed by Tom Wardill
Status: Merged
Merged at revision: 502
Proposed branch: lp:~twom/loggerhead/fix-text-types-python-2
Merge into: lp:loggerhead
Diff against target: 60 lines (+6/-6)
2 files modified
loggerhead/controllers/view_ui.py (+1/-1)
loggerhead/tests/test_controllers.py (+5/-5)
To merge this branch: bzr merge lp:~twom/loggerhead/fix-text-types-python-2
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+386941@code.launchpad.net

Commit message

Check that path is a text_type, not str explicitly

Description of the change

In python2, the `path` argument is `unicode`, not `str`.
Check against utils.text_type rather than the string type explicitly.

To post a comment you must log in.
503. By Tom Wardill

Use unicode in test data

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loggerhead/controllers/view_ui.py'
2--- loggerhead/controllers/view_ui.py 2020-06-04 19:23:31 +0000
3+++ loggerhead/controllers/view_ui.py 2020-07-07 10:35:24 +0000
4@@ -50,7 +50,7 @@
5 template_name = 'view'
6
7 def tree_for(self, path, revid):
8- if not isinstance(path, str):
9+ if not isinstance(path, util.text_type):
10 raise TypeError(path)
11 if not isinstance(revid, bytes):
12 raise TypeError(revid)
13
14=== modified file 'loggerhead/tests/test_controllers.py'
15--- loggerhead/tests/test_controllers.py 2020-06-04 20:30:54 +0000
16+++ loggerhead/tests/test_controllers.py 2020-07-07 10:35:24 +0000
17@@ -200,7 +200,7 @@
18 # A lot of this state is set up by __call__, but we'll do it directly
19 # here.
20 ann_ui.args = ['rev2']
21- annotate_info = ann_ui.get_values('filename',
22+ annotate_info = ann_ui.get_values(u'filename',
23 kwargs={'file_id': 'file_id'}, headers={})
24 annotated = annotate_info['annotated']
25 self.assertEqual(2, len(annotated))
26@@ -213,7 +213,7 @@
27 ann_ui = self.make_annotate_ui_for_file_history(b'file_id', history)
28 ann_ui.args = ['rev2']
29 ann_ui.get_values(
30- 'filename', kwargs={'file_id': 'file_id'}, headers={})
31+ u'filename', kwargs={'file_id': 'file_id'}, headers={})
32
33 def test_annotate_file_zero_sized(self):
34 # Test against a zero-sized file without breaking. No annotation
35@@ -221,7 +221,7 @@
36 history = [(b'rev1', b'', '.')]
37 ann_ui = self.make_annotate_ui_for_file_history(b'file_id', history)
38 ann_ui.args = ['rev1']
39- annotate_info = ann_ui.get_values('filename',
40+ annotate_info = ann_ui.get_values(u'filename',
41 kwargs={'file_id': 'file_id'}, headers={})
42 annotated = annotate_info['annotated']
43 self.assertEqual(0, len(annotated))
44@@ -231,14 +231,14 @@
45 ann_ui = self.make_annotate_ui_for_file_history(b'file_id', history)
46 ann_ui.args = ['rev1']
47 self.assertRaises(
48- HTTPNotFound, ann_ui.get_values, 'not-filename', {}, {})
49+ HTTPNotFound, ann_ui.get_values, u'not-filename', {}, {})
50
51 def test_annotate_nonexistent_rev(self):
52 history = [(b'rev1', b'', '.')]
53 ann_ui = self.make_annotate_ui_for_file_history(b'file_id', history)
54 ann_ui.args = ['norev']
55 self.assertRaises(
56- HTTPNotFound, ann_ui.get_values, 'not-filename', {}, {})
57+ HTTPNotFound, ann_ui.get_values, u'not-filename', {}, {})
58
59
60 class TestFileDiffUI(BasicTests):

Subscribers

People subscribed via source and target branches