Skip to content

Commit d685855

Browse files
committed
fixes for printtree, tox ini changes
1 parent 959be2d commit d685855

3 files changed

Lines changed: 33 additions & 43 deletions

File tree

fs/tests/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ def test_invalid_chars(self):
6363
self.assertEqual(self.fs.validatepath('foo/bar'), None)
6464
self.assert_(self.fs.isvalidpath('foo/bar'))
6565

66+
def test_tree(self):
67+
"""Test tree print"""
68+
self.fs.makedir('foo')
69+
self.fs.createfile('foo/bar.txt')
70+
self.fs.tree()
71+
6672
def test_meta(self):
6773
"""Checks getmeta / hasmeta are functioning"""
6874
# getmeta / hasmeta are hard to test, since there is no way to validate

fs/utils.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,9 @@ def print_fs(fs,
533533
"""
534534

535535
if file_out is None:
536-
file_out = sys.stdout.buffer if PY3 else sys.stdout
536+
file_out = sys.stdout
537537

538-
file_encoding = getattr(file_out, 'encoding', 'utf-8') or 'utf-8'
538+
file_encoding = getattr(file_out, 'encoding', u'utf-8') or u'utf-8'
539539
file_encoding = file_encoding.upper()
540540

541541
if terminal_colors is None:
@@ -545,28 +545,31 @@ def print_fs(fs,
545545
terminal_colors = hasattr(file_out, 'isatty') and file_out.isatty()
546546

547547
def write(line):
548-
file_out.write(line.encode(file_encoding, 'replace') + b'\n')
548+
if PY3:
549+
file_out.write((line + u'\n'))
550+
else:
551+
file_out.write((line + u'\n').encode(file_encoding, 'replace'))
549552

550553
def wrap_prefix(prefix):
551554
if not terminal_colors:
552555
return prefix
553-
return '\x1b[32m%s\x1b[0m' % prefix
556+
return u'\x1b[32m%s\x1b[0m' % prefix
554557

555558
def wrap_dirname(dirname):
556559
if not terminal_colors:
557560
return dirname
558-
return '\x1b[1;34m%s\x1b[0m' % dirname
561+
return u'\x1b[1;34m%s\x1b[0m' % dirname
559562

560563
def wrap_error(msg):
561564
if not terminal_colors:
562565
return msg
563-
return '\x1b[31m%s\x1b[0m' % msg
566+
return u'\x1b[31m%s\x1b[0m' % msg
564567

565568
def wrap_filename(fname):
566569
if not terminal_colors:
567570
return fname
568-
if fname.startswith('.'):
569-
fname = '\x1b[33m%s\x1b[0m' % fname
571+
if fname.startswith(u'.'):
572+
fname = u'\x1b[33m%s\x1b[0m' % fname
570573
return fname
571574
dircount = [0]
572575
filecount = [0]
@@ -577,10 +580,10 @@ def print_dir(fs, path, levels=[]):
577580
char_line = u'──'
578581
char_corner = u'╰'
579582
else:
580-
char_vertline = '|'
581-
char_newnode = '|'
582-
char_line = '--'
583-
char_corner = '`'
583+
char_vertline = u'|'
584+
char_newnode = u'|'
585+
char_line = u'--'
586+
char_corner = u'`'
584587

585588
try:
586589
dirs = fs.listdir(path, dirs_only=True)
@@ -592,7 +595,7 @@ def print_dir(fs, path, levels=[]):
592595
[(False, p) for p in files] )
593596
except Exception, e:
594597
prefix = ''.join([(char_vertline + ' ', ' ')[last] for last in levels]) + ' '
595-
write(wrap_prefix(prefix[:-1] + ' ') + wrap_error("unable to retrieve directory list (%s) ..." % str(e)))
598+
write(wrap_prefix(prefix[:-1] + ' ') + wrap_error(u"unable to retrieve directory list (%s) ..." % str(e)))
596599
return 0
597600

598601
if hide_dotfiles:

tox.ini

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
11
[tox]
2-
envlist = py27,py34,py35,pypy
2+
envlist = py26, py27, py33, py34, py35, pypy
33
sitepackages = False
44

55
[testenv]
6-
deps = distribute
7-
six
8-
dexml
9-
paramiko
10-
boto
11-
nose
12-
mako
13-
pyftpdlib
6+
deps =
7+
six
8+
dexml
9+
nose
10+
py31,py32,py33,py34: winpdb
11+
py26,py27: paramiko
12+
py26,py27: boto
13+
py26,py27: mako
14+
py26,py27: pyftpdlib
1415
changedir=.tox
15-
commands = nosetests fs.tests -v \
16-
[]
17-
18-
[testenv:py34]
19-
commands = nosetests fs.tests -v \
20-
[]
21-
deps = distribute
22-
six
23-
dexml
24-
nose
25-
winpdb
26-
27-
[testenv:py35]
28-
commands = nosetests fs.tests -v \
29-
[]
30-
deps = distribute
31-
six
32-
dexml
33-
nose
34-
winpdb
35-
16+
commands = nosetests {posargs:-v fs.tests}

0 commit comments

Comments
 (0)