Skip to content

Commit

Permalink
Fix remaining test failures on Windows
Browse files Browse the repository at this point in the history
I'm doing this blind BTW, since working via rdesktop in that infernal
Windows console is a pain.
  • Loading branch information
mgedmin committed Feb 1, 2014
1 parent 0dd8fff commit 0ab2875
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/restview/restviewhttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ def handle_rest_data(self, data, mtime=None):
return html

def collect_files(self, dirname):
if not dirname.endswith('/'):
dirname += '/'
if not dirname.endswith(os.path.sep):
dirname += os.path.sep
files = []
for dirpath, dirnames, filenames in os.walk(dirname):
dirnames[:] = [dn for dn in dirnames
Expand Down Expand Up @@ -229,11 +229,11 @@ def handle_list(self, list_of_files_or_dirs):
files = []
for idx, fn in enumerate(list_of_files_or_dirs):
if os.path.isdir(fn):
files.extend([(os.path.join(str(idx), f),
files.extend([('%s/%s' % (idx, f.replace(os.path.sep, '/')),
os.path.join(fn, f))
for f in self.collect_files(fn)])
else:
files.append((os.path.join(str(idx), os.path.basename(fn)),
files.append(('%s/%s' % (idx, os.path.basename(fn)),
fn))
html = self.render_dir_listing("RST files", files)
if isinstance(html, unicode):
Expand Down
20 changes: 12 additions & 8 deletions src/restview/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def test_do_GET_or_HEAD_polling(self):
handler.path = '/polling?pathname=a.txt&mtime=12345'
handler.server.renderer.root = self.root
handler.handle_polling = lambda fn, mt: 'Got update for %s since %s' % (fn, mt)
body = handler.do_GET_or_HEAD()
with patch('os.path.isdir', lambda dir: dir == self.root):
body = handler.do_GET_or_HEAD()
expected_fn = self.filepath('a.txt')
self.assertEqual(body, 'Got update for %s since 12345' % expected_fn)

Expand Down Expand Up @@ -346,30 +347,33 @@ def test_handle_dir(self):
"text/html; charset=UTF-8")
self.assertEqual(handler.headers['Content-Length'],
str(len(body)))
where = os.path.abspath('/path/to/dir').encode()
self.assertEqual(body,
b"<title>RST files in /path/to/dir</title>\n"
b"<title>RST files in " + where + b"</title>\n"
b"a.txt - a.txt\n"
b"b/c.txt - b/c.txt")

def test_handle_list(self):
handler = MyRequestHandlerForTests()
handler.collect_files = lambda dir: ['a.txt', 'b/c.txt']
handler.collect_files = lambda dir: ['a.txt', os.path.join('b', 'c.txt')]
handler.render_dir_listing = lambda title, files: \
unicode("<title>%s</title>\n%s" % (
title,
'\n'.join('%s - %s' % (path, fn) for path, fn in files)))
with patch('os.path.isdir', lambda fn: fn == 'subdir'):
body = handler.handle_list(['/path/to/file.txt', 'subdir'])
body = handler.handle_list([os.path.normpath('/path/to/file.txt'),
'subdir'])
self.assertEqual(handler.status, 200)
self.assertEqual(handler.headers['Content-Type'],
"text/html; charset=UTF-8")
self.assertEqual(handler.headers['Content-Length'],
str(len(body)))
self.assertEqual(body,
b"<title>RST files</title>\n"
b"0/file.txt - /path/to/file.txt\n"
b"1/a.txt - subdir/a.txt\n"
b"1/b/c.txt - subdir/b/c.txt")
b"0/file.txt - #path#to#file.txt\n"
b"1/a.txt - subdir#a.txt\n"
b"1/b/c.txt - subdir#b#c.txt"
.replace(b"#", os.path.sep.encode()))


def doctest_MyRequestHandler_render_dir_listing():
Expand Down Expand Up @@ -760,7 +764,7 @@ def test_suite():
unittest.makeSuite(TestRestViewer),
unittest.makeSuite(TestGlobals),
unittest.makeSuite(TestMain),
doctest.DocTestSuite(optionflags=doctest.ELLIPSIS|doctest.REPORT_NDIFF),
doctest.DocTestSuite(optionflags=doctest.ELLIPSIS | doctest.REPORT_NDIFF),
doctest.DocTestSuite('restview.restviewhttp'),
])

Expand Down

0 comments on commit 0ab2875

Please sign in to comment.