|
From: <mi...@us...> - 2012-09-03 09:17:26
|
Revision: 7505
http://docutils.svn.sourceforge.net/docutils/?rev=7505&view=rev
Author: milde
Date: 2012-09-03 09:17:15 +0000 (Mon, 03 Sep 2012)
Log Message:
-----------
Allow running test_buildhtml.py from anywhere, also with Python 3.
Fixes [ 3521167 ] and [ 3521168 ].
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/tools/test/test_buildhtml.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2012-08-27 07:55:20 UTC (rev 7504)
+++ trunk/docutils/HISTORY.txt 2012-09-03 09:17:15 UTC (rev 7505)
@@ -34,6 +34,11 @@
- Fix [ 3546533 ] Unicode error with `date` directive.
+* docutils/tools/test/test_buildhtml.py
+
+ - Fix [ 3521167 ] allow running in any directory.
+ - Fix [ 3521168 ] allow running with Python 3.
+
* docutils/writers/manpage.py
- Apply [ 3527401 ] addmonition's don't preserve indentation
Modified: trunk/docutils/tools/test/test_buildhtml.py
===================================================================
--- trunk/docutils/tools/test/test_buildhtml.py 2012-08-27 07:55:20 UTC (rev 7504)
+++ trunk/docutils/tools/test/test_buildhtml.py 2012-09-03 09:17:15 UTC (rev 7505)
@@ -34,40 +34,49 @@
except ImportError:
pass
+
+buildhtml_path = os.path.abspath(os.path.join(
+ os.path.dirname(__file__) or os.curdir,
+ '..', 'buildhtml.py'))
+
def process_and_return_filelist(options):
dirs = []
files = []
try:
- p = Popen("../buildhtml.py "+options, shell=True,
+ p = Popen(buildhtml_path+" "+options, shell=True,
stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
(cin, cout) = (p.stdin, p.stdout)
except NameError:
- cin, cout = os.popen4("../buildhtml.py "+options)
+ cin, cout = os.popen4(buildhtml_path+" "+options)
while 1:
line = cout.readline()
if not line:
break
+ # in Py 3x, cout.readline() returns `bytes` and the processing fails
+ line = line.decode('ascii', 'replace')
# BUG no colon in filename/path allowed
- item = line.split(":")[-1].strip()
+ item = line.split(": ")[-1].strip()
if line.startswith(" "):
files.append(item)
else:
dirs.append(item)
+ cin.close()
+ cout.close()
return (dirs, files)
class BuildHtmlTests(unittest.TestCase):
tree = ( "_tmp_test_tree",
- "_tmp_test_tree/one.txt",
- "_tmp_test_tree/two.txt",
- "_tmp_test_tree/dir1",
- "_tmp_test_tree/dir1/one.txt",
- "_tmp_test_tree/dir1/two.txt",
- "_tmp_test_tree/dir2",
- "_tmp_test_tree/dir2/one.txt",
- "_tmp_test_tree/dir2/two.txt",
- "_tmp_test_tree/dir2/sub",
- "_tmp_test_tree/dir2/sub/one.txt",
- "_tmp_test_tree/dir2/sub/two.txt",
+ "_tmp_test_tree/one.txt",
+ "_tmp_test_tree/two.txt",
+ "_tmp_test_tree/dir1",
+ "_tmp_test_tree/dir1/one.txt",
+ "_tmp_test_tree/dir1/two.txt",
+ "_tmp_test_tree/dir2",
+ "_tmp_test_tree/dir2/one.txt",
+ "_tmp_test_tree/dir2/two.txt",
+ "_tmp_test_tree/dir2/sub",
+ "_tmp_test_tree/dir2/sub/one.txt",
+ "_tmp_test_tree/dir2/sub/two.txt",
)
def setUp(self):
@@ -76,13 +85,15 @@
except NameError:
self.root = os.tempnam()
os.mkdir(self.root)
-
+
for s in self.tree:
s = os.path.join(self.root, s)
if not "." in s:
os.mkdir(s)
else:
- open(s, "w").write("dummy")
+ fd_s = open(s, "w")
+ fd_s.write("dummy")
+ fd_s.close()
def tearDown(self):
for i in range(len(self.tree) - 1, -1, -1):
@@ -96,13 +107,13 @@
def test_1(self):
opts = "--dry-run "+ self.root
dirs, files = process_and_return_filelist( opts )
- self.assertEquals(files.count("one.txt"), 4)
+ self.assertEqual(files.count("one.txt"), 4)
def test_local(self):
opts = "--dry-run --local "+ self.root
dirs, files = process_and_return_filelist( opts )
- self.assertEquals( len(dirs), 1)
- self.assertEquals( files, [])
+ self.assertEqual( len(dirs), 1)
+ self.assertEqual( files, [])
if __name__ == '__main__':
unittest.main()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|