Skip to content

Commit cb3e635

Browse files
author
Matthew
committed
fix bug#777: close issue failed with unicode labels
1 parent 6e110c5 commit cb3e635

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

github3/issues/issue.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ def close(self):
147147
"""
148148
assignee = self.assignee.login if self.assignee else ''
149149
number = self.milestone.number if self.milestone else None
150-
labels = [str(l) for l in self.original_labels]
150+
try:
151+
labels = [str(l) for l in self.original_labels]
152+
except UnicodeEncodeError:
153+
labels = [l.name for l in self.original_labels]
154+
151155
return self.edit(self.title, self.body, assignee, 'closed',
152156
number, labels)
153157

tests/unit/test_issues_issue.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232

3333
class TestIssueRequiresAuth(helper.UnitRequiresAuthenticationHelper):
34-
3534
"""Test Issue methods that require Authentication."""
3635

3736
described_class = github3.issues.Issue
@@ -83,7 +82,6 @@ def test_unlock(self):
8382

8483

8584
class TestIssue(helper.UnitHelper):
86-
8785
"""Test Issue methods that make simple requests."""
8886

8987
described_class = github3.issues.Issue
@@ -120,7 +118,11 @@ def test_assign_empty_username(self):
120118
def test_close(self):
121119
"""Verify the request for closing an issue."""
122120
self.instance.close()
123-
labels = [str(label) for label in self.instance.original_labels]
121+
try:
122+
labels = [str(label) for label in self.instance.original_labels]
123+
except UnicodeEncodeError:
124+
labels = [label.name for label in self.instance.original_labels]
125+
124126
self.patch_called_with(
125127
url_for(),
126128
data={
@@ -169,6 +171,21 @@ def test_comment_positive_id(self):
169171
self.instance.comment(-1)
170172
assert self.session.get.called is False
171173

174+
def test_close_with_unicode_labels(self):
175+
"""Verify the request for closeing an issue."""
176+
data = {
177+
'title': 'issue title',
178+
'body': 'issue body',
179+
'assignee': 'sigmavirus24',
180+
'state': 'closed',
181+
'labels': [u"标签1", u"标签2"]
182+
}
183+
self.instance.edit(**data)
184+
self.patch_called_with(
185+
url_for(),
186+
data=data
187+
)
188+
172189
def test_edit(self):
173190
"""Verify the request for editing an issue."""
174191
data = {
@@ -323,7 +340,6 @@ def test_replace_labels(self):
323340

324341

325342
class TestIssueIterators(helper.UnitIteratorHelper):
326-
327343
"""Test Issue methods that return iterators."""
328344

329345
described_class = github3.issues.Issue
@@ -364,7 +380,6 @@ def test_labels(self):
364380

365381

366382
class TestLabelRequiresAuth(helper.UnitRequiresAuthenticationHelper):
367-
368383
"""Test that ensure certain methods on Label class requires auth."""
369384

370385
described_class = github3.issues.label.Label
@@ -429,7 +444,6 @@ def test_update(self):
429444

430445

431446
class TestIssueEvent(helper.UnitHelper):
432-
433447
"""Unit test for IssueEvent."""
434448

435449
described_class = github3.issues.event.IssueEvent

0 commit comments

Comments
 (0)