From ec48017fdd62754dd73f442dce7e22ebf3d30be3 Mon Sep 17 00:00:00 2001 From: milde Date: Mon, 3 Sep 2012 09:17:15 +0000 Subject: [PATCH] Allow running test_buildhtml.py from anywhere, also with Python 3. Fixes [ 3521167 ] and [ 3521168 ]. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7505 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- HISTORY.txt | 5 +++++ tools/test/test_buildhtml.py | 49 +++++++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/HISTORY.txt b/HISTORY.txt index eec20a1b6..7995c4ddb 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -34,6 +34,11 @@ Changes Since 0.9.1 - 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 diff --git a/tools/test/test_buildhtml.py b/tools/test/test_buildhtml.py index 53baf6559..a0a670559 100644 --- a/tools/test/test_buildhtml.py +++ b/tools/test/test_buildhtml.py @@ -34,40 +34,49 @@ try: 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 @@ class BuildHtmlTests(unittest.TestCase): 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 @@ class BuildHtmlTests(unittest.TestCase): 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() -- 2.11.4.GIT