mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 01:35:35 +00:00
Bug 1452864 - [mozfile] tree() broken with Unicode characters in path. r=gbrown
The patch correctly marks the delimiters for the tree output as Unicode, and also updates mozprofile to correctly serialize the Profile object when str() is used. MozReview-Commit-ID: AjUHa6zGHQe --HG-- extra : rebase_source : d4fa6c5db91184dee6a2abe788aa23d0c6255be6
This commit is contained in:
parent
06df983ba2
commit
7524e36b05
@ -261,9 +261,9 @@ ascii_delimeters = {
|
||||
|
||||
# unicode delimiters
|
||||
unicode_delimeters = {
|
||||
'vertical_line': '│',
|
||||
'item_marker': '├',
|
||||
'last_child': '└'
|
||||
'vertical_line': u'│',
|
||||
'item_marker': u'├',
|
||||
'last_child': u'└'
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,4 +5,5 @@ subsuite = mozbase, os == "linux"
|
||||
[test_move_remove.py]
|
||||
[test_tempdir.py]
|
||||
[test_tempfile.py]
|
||||
[test_tree.py]
|
||||
[test_url.py]
|
||||
|
33
testing/mozbase/mozfile/tests/test_tree.py
Normal file
33
testing/mozbase/mozfile/tests/test_tree.py
Normal file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=UTF-8
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import mozunit
|
||||
|
||||
from mozfile import tree
|
||||
|
||||
|
||||
class TestTree(unittest.TestCase):
|
||||
"""Test the tree function."""
|
||||
|
||||
def test_unicode_paths(self):
|
||||
"""Test creating tree structure from a Unicode path."""
|
||||
try:
|
||||
tmpdir = tempfile.mkdtemp(suffix=u'tmp🍪')
|
||||
os.mkdir(os.path.join(tmpdir, u'dir🍪'))
|
||||
with open(os.path.join(tmpdir, u'file🍪'), 'w') as f:
|
||||
f.write('foo')
|
||||
|
||||
self.assertEqual(u'{}\n├file🍪\n└dir🍪'.format(tmpdir), tree(tmpdir))
|
||||
finally:
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
mozunit.main()
|
@ -358,7 +358,11 @@ class Profile(object):
|
||||
for key, value in parts]))
|
||||
return retval
|
||||
|
||||
__str__ = summary
|
||||
def __str__(self):
|
||||
return unicode(self).encode('utf-8')
|
||||
|
||||
def __unicode__(self):
|
||||
return self.summary()
|
||||
|
||||
|
||||
class FirefoxProfile(Profile):
|
||||
|
@ -44,13 +44,15 @@ class TestProfilePrint(unittest.TestCase):
|
||||
finally:
|
||||
mozfile.rmtree(tempdir)
|
||||
|
||||
def test_strcast(self):
|
||||
"""
|
||||
test casting to a string
|
||||
"""
|
||||
|
||||
def test_str_cast(self):
|
||||
"""Test casting to a string."""
|
||||
profile = mozprofile.Profile()
|
||||
self.assertEqual(str(profile), profile.summary())
|
||||
self.assertEqual(str(profile), profile.summary().encode("UTF-8"))
|
||||
|
||||
def test_unicode_cast(self):
|
||||
"""Test casting to a unicode string."""
|
||||
profile = mozprofile.Profile()
|
||||
self.assertEqual(unicode(profile), profile.summary())
|
||||
|
||||
def test_profile_diff(self):
|
||||
profile1 = mozprofile.Profile()
|
||||
|
Loading…
Reference in New Issue
Block a user