changeset 4019:db5023512482

merged main
author Byeongweon [tasyblue@gmail.com]
date Mon, 18 Aug 2008 02:27:53 +0900
parents 6d7d40363f3c (current diff) 62b9f61eb526 (diff)
children b1e192a3651a
files
diffstat 16 files changed, 89 insertions(+), 167 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/__init__.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/_tests/__init__.py	Mon Aug 18 02:27:53 2008 +0900
@@ -3,16 +3,19 @@
     MoinMoin - some common code for testing
 
     @copyright: 2007 MoinMoin:KarolNowak,
-                2008 MoinMoin:ThomasWaldmann
+                2008 MoinMoin:ThomasWaldmann, MoinMoin:ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
 
 import os, shutil
 
+from MoinMoin.parser.text import Parser
+from MoinMoin.formatter.text_html import Formatter
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.util import random_string
 from MoinMoin import caching, user
+
 # Promoting the test user -------------------------------------------
 # Usually the tests run as anonymous user, but for some stuff, you
 # need more privs...
@@ -82,6 +85,12 @@
     page.saveText(content, 0)
     return page
 
+def nuke_eventlog(request):
+    """ removes event-log file """
+    fpath = request.rootpage.getPagePath('event-log', isfile=1)
+    if os.path.exists(fpath):
+        os.remove(fpath)
+
 def nuke_page(request, pagename):
     """ completely delete a page, everything in the pagedir """
     page = PageEditor(request, pagename, do_editor_backup=False)
@@ -94,3 +103,15 @@
     """ creates a list of random strings """
     chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
     return [u"%s" % random_string(length, chars) for counter in range(count)]
+
+def make_macro(request, page):
+    """ creates the macro """
+    from MoinMoin import macro
+    p = Parser("##\n", request)
+    p.formatter = Formatter(request)
+    p.formatter.page = page
+    request.page = page
+    request.formatter = p.formatter
+    p.form = request.form
+    m = macro.Macro(p)
+    return m
--- a/MoinMoin/_tests/test_sourcecode.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/_tests/test_sourcecode.py	Mon Aug 18 02:27:53 2008 +0900
@@ -32,6 +32,8 @@
 
 try:
     import xattr
+    if not hasattr(xattr, "xattr"): # there seem to be multiple modules with that name
+        raise ImportError
     def mark_file_ok(path, mtime):
         x = xattr.xattr(path)
         try:
--- a/MoinMoin/auth/ldap_login.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/auth/ldap_login.py	Mon Aug 18 02:27:53 2008 +0900
@@ -140,7 +140,7 @@
                         (ldap.OPT_X_TLS, self.start_tls),
                         #(ldap.OPT_X_TLS_ALLOW, 1),
                     ):
-                        if value:
+                        if value is not None:
                             ldap.set_option(option, value)
 
                 server = self.server_uri
--- a/MoinMoin/conftest.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/conftest.py	Mon Aug 18 02:27:53 2008 +0900
@@ -170,9 +170,9 @@
 
 class MoinTestFunction(py.test.collect.Function):
     def execute(self, target, *args):
+        request = self.parent.request
         co = target.func_code
         if 'request' in co.co_varnames[:co.co_argcount]:
-            request = init_test_request()
             target(request, *args)
         else:
             target(*args)
@@ -183,9 +183,8 @@
 
     def setup(self):
         cls = self.obj
-        if not hasattr(cls, 'request'):
-            cls.request = init_test_request()
-            cls.TestConfig = TestConfig(cls.request)
+        cls.request = self.parent.request
+        cls.TestConfig = TestConfig(cls.request)
         super(MoinClassCollector, self).setup()
 
 
@@ -193,6 +192,10 @@
     Class = MoinClassCollector
     Function = MoinTestFunction
 
+    def __init__(self, *args, **kwargs):
+        self.request = init_test_request()
+        super(Module, self).__init__(*args, **kwargs)
+
     def run(self, *args, **kwargs):
         if coverage is not None:
             coverage_modules.update(getattr(self.obj, 'coverage_modules', []))
--- a/MoinMoin/filter/__init__.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/filter/__init__.py	Mon Aug 18 02:27:53 2008 +0900
@@ -17,12 +17,27 @@
 
 standard_codings = ['utf-8', 'iso-8859-15', 'iso-8859-1', ]
 
+
+def quote_filename(filename):
+    """ quote a filename (could contain blanks or other special chars) in a
+        way suitable for the platform we run on.
+    """
+    # XXX Use os.name AND/OR sys.platform?
+    if os.name == 'posix':
+        filename = "'%s'" % filename
+    elif sys.platform == 'win32':
+        filename = '"%s"' % filename
+    else:
+        raise ValueError("MoinMoin.filter.quote_filename: os/platform not supported")
+    return filename
+
+
 def execfilter(cmd, filename, codings=standard_codings):
     """ use cmd to get plaintext content of filename
         to decode to unicode, we use the first coding of codings list that
         does not throw an exception or force ascii
     """
-    filter_cmd = cmd % filename
+    filter_cmd = cmd % quote_filename(filename)
     child_stdin, child_stdout, child_stderr = os.popen3(filter_cmd)
     data = child_stdout.read()
     errors = child_stderr.read()
--- a/MoinMoin/filter/application_msword.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/filter/application_msword.py	Mon Aug 18 02:27:53 2008 +0900
@@ -4,12 +4,15 @@
 
     Depends on: antiword command from antiword package
 
-    @copyright: 2006 MoinMoin:ThomasWaldmann
+    @copyright: 2006-2008 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 
 from MoinMoin.filter import execfilter
 
 def execute(indexobj, filename):
-    return execfilter("HOME=/tmp antiword '%s'", filename) # no HOME makes antiword complain
+    cmd = "antiword %s"
+    if os.name == 'posix':
+        cmd = "HOME=/tmp " + cmd  # no HOME makes antiword complain (on Linux)
+    return execfilter(cmd, filename)
 
--- a/MoinMoin/filter/application_pdf.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/filter/application_pdf.py	Mon Aug 18 02:27:53 2008 +0900
@@ -11,5 +11,5 @@
 from MoinMoin.filter import execfilter
 
 def execute(indexobj, filename):
-    return execfilter("pdftotext -enc UTF-8 '%s' -", filename)
+    return execfilter("pdftotext -enc UTF-8 %s -", filename)
 
--- a/MoinMoin/filter/application_vnd_ms_excel.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/filter/application_vnd_ms_excel.py	Mon Aug 18 02:27:53 2008 +0900
@@ -11,7 +11,7 @@
 from MoinMoin.filter import execfilter
 
 def execute(indexobj, filename):
-    data = execfilter("xls2csv '%s'", filename)
+    data = execfilter("xls2csv %s", filename)
     # xls2csv uses comma as field separator and "field content",
     # we strip both to not confuse the indexer
     data = data.replace(u',', u' ').replace(u'"', u' ')
--- a/MoinMoin/macro/_tests/test_Action.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/macro/_tests/test_Action.py	Mon Aug 18 02:27:53 2008 +0900
@@ -3,46 +3,31 @@
     MoinMoin - MoinMoin.macro.Action Tests
 
     @copyright: 2007 MoinMoin:ReimarBauer
-
     @license: GNU GPL, see COPYING for details.
 """
 import os
+
 from MoinMoin import macro
 from MoinMoin.macro import Action
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
 
-from MoinMoin._tests import become_trusted, create_page, nuke_page
+from MoinMoin._tests import become_trusted, create_page, make_macro, nuke_page
 
 class TestAction:
     """ testing macro Action calling action raw """
     pagename = u'AutoCreatedMoinMoinTemporaryTestPageForAction'
 
-    def _make_macro(self):
-        """Test helper"""
-        from MoinMoin.parser.text import Parser
-        from MoinMoin.formatter.text_html import Formatter
-        p = Parser("##\n", self.request)
-        p.formatter = Formatter(self.request)
-        p.formatter.page = self.page
-        self.request.formatter = p.formatter
-        p.form = self.request.form
-        m = macro.Macro(p)
-        return m
-
     def testActionCallingRaw(self):
         """ module_tested: executes raw by macro Action on existing page"""
         request = self.request
         become_trusted(request)
-
         self.page = create_page(request, self.pagename, u'= title1 =\n||A||B||\n')
-        m = self._make_macro()
+        m = make_macro(self.request, self.page)
         result = Action.macro_Action(m, 'raw')
         nuke_page(request, self.pagename)
-
         expected = '<a href="./AutoCreatedMoinMoinTemporaryTestPageForAction?action=raw">raw</a>'
         assert result == expected
 
-
 coverage_modules = ['MoinMoin.macro.Action']
 
--- a/MoinMoin/macro/_tests/test_EmbedObject.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/macro/_tests/test_EmbedObject.py	Mon Aug 18 02:27:53 2008 +0900
@@ -4,16 +4,14 @@
 
     @copyright: 2008 MoinMoin:ReimarBauer,
                 2008 MoinMoin:JohannesBerg
-
     @license: GNU GPL, see COPYING for details.
 """
-
 import py
 
 from MoinMoin import macro
 from MoinMoin.action import AttachFile
 
-from MoinMoin._tests import become_trusted, create_page, nuke_page
+from MoinMoin._tests import become_trusted, create_page, make_macro, nuke_page
 
 class TestEmbedObject:
     """ testing macro Action calling action raw """
@@ -22,10 +20,8 @@
     def setup_class(self):
         request = self.request
         pagename = self.pagename
-
         become_trusted(request)
         self.page = create_page(request, pagename, u"Foo")
-
         AttachFile.getAttachDir(request, pagename)
         test_files = [
             ('test.ogg', 'vorbis'),
@@ -40,18 +36,6 @@
     def teardown_class(self):
         nuke_page(self.request, self.pagename)
 
-    def _make_macro(self):
-        """ Test helper """
-        from MoinMoin.parser.text import Parser
-        from MoinMoin.formatter.text_html import Formatter
-        p = Parser("##\n", self.request)
-        p.formatter = Formatter(self.request)
-        p.formatter.page = self.page
-        self.request.formatter = p.formatter
-        p.form = self.request.form
-        m = macro.Macro(p)
-        return m
-
     def testEmbedObjectMimetype(self):
         """ tests defined mimetyes """
         tests = [
@@ -61,13 +45,13 @@
             (u'test.mp3', 'audio/mpeg'),
         ]
         for filename, mimetype in tests:
-            m = self._make_macro()
+            m = make_macro(self.request, self.page)
             result = m.execute('EmbedObject', filename)
             assert mimetype in result
 
     def testEmbedObjectDefaultValues(self):
         """ tests default values of macro EmbedObject """
-        m = self._make_macro()
+        m = make_macro(self.request, self.page)
         filename = 'test.mpg'
         result = m.execute('EmbedObject', u'%s' % filename)
         assert '<object data="./AutoCreatedMoinMoinTemporaryTestPageForEmbedObject?action=AttachFile&amp;do=get&amp;target=test.mpg"' in result
@@ -76,7 +60,7 @@
 
     def testEmbedObjectPercentHeight(self):
         """ tests a unit value for macro EmbedObject """
-        m = self._make_macro()
+        m = make_macro(self.request, self.page)
         filename = 'test.mpg'
         height = '50 %' # also tests that space is allowed in there
         result = m.execute('EmbedObject', u'target=%s, height=%s' % (filename, height))
@@ -86,7 +70,7 @@
 
     def testEmbedObjectFromUrl(self):
         """ tests using a URL for macro EmbedObject """
-        m = self._make_macro()
+        m = make_macro(self.request, self.page)
         target = 'http://localhost/%s?action=AttachFile&do=view&target=test.mpg' % self.pagename
         result = m.execute('EmbedObject', u'target=%s, url_mimetype=video/mpeg' % target)
         assert '<object data="http://localhost/AutoCreatedMoinMoinTemporaryTestPageForEmbedObject?action=AttachFile&amp;do=view&amp;target=test.mpg" type="video/mpeg"' in result
--- a/MoinMoin/macro/_tests/test_FootNote.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/macro/_tests/test_FootNote.py	Mon Aug 18 02:27:53 2008 +0900
@@ -3,16 +3,15 @@
     MoinMoin - MoinMoin.macro.FootNote Tests
 
     @copyright: 2008 MoinMoin:ReimarBauer
-
     @license: GNU GPL, see COPYING for details.
 """
 import os
+
 from MoinMoin import macro
 from MoinMoin.macro import FootNote
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
-
-from MoinMoin._tests import become_trusted, create_page, nuke_page
+from MoinMoin._tests import become_trusted, create_page, make_macro, nuke_page
 
 class TestFootNote:
     """ testing macro Action calling action raw """
@@ -25,28 +24,14 @@
     def teardown_class(self):
         nuke_page(self.request, self.pagename)
 
-    def _make_macro(self):
-        """Test helper"""
-        from MoinMoin.parser.text import Parser
-        from MoinMoin.formatter.text_html import Formatter
-        p = Parser("##\n", self.request)
-        p.formatter = Formatter(self.request)
-        p.formatter.page = self.page
-        self.request.formatter = p.formatter
-        p.form = self.request.form
-        m = macro.Macro(p)
-        return m
-
     def test_enumbering(self):
         """ module_tested: enumbering of Footnotes"""
-        m = self._make_macro()
+        m = make_macro(self.request, self.page)
         text = 'a'
         FootNote.execute(m, text)
         text = 'b'
         FootNote.execute(m, text)
         result = FootNote.emit_footnotes(m.request, m.request.formatter)
-
         assert result.endswith('2</a>)</li></ol></div>')
 
-
 coverage_modules = ['MoinMoin.macro.FootNote']
--- a/MoinMoin/macro/_tests/test_GetVal.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/macro/_tests/test_GetVal.py	Mon Aug 18 02:27:53 2008 +0900
@@ -3,7 +3,6 @@
     MoinMoin - MoinMoin.macro GetVal tested
 
     @copyright: 2007 MoinMoin:ReimarBauer
-
     @license: GNU GPL, see COPYING for details.
 """
 import os, py
@@ -11,8 +10,7 @@
 from MoinMoin import macro
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
-
-from MoinMoin._tests import become_trusted, create_page, nuke_page
+from MoinMoin._tests import become_trusted, create_page, make_macro, nuke_page
 
 class TestGetVal:
     """GetVal: testing getVal macro """
@@ -25,43 +23,24 @@
     def teardown_class(self):
         nuke_page(self.request, self.pagename)
 
-    def _make_macro(self):
-        """Test helper"""
-        from MoinMoin.parser.text import Parser
-        from MoinMoin.formatter.text_html import Formatter
-        p = Parser("##\n", self.request)
-        p.formatter = Formatter(self.request)
-        p.formatter.page = self.page
-        self.request.formatter = p.formatter
-        p.form = self.request.form
-        m = macro.Macro(p)
-        return m
-
     def _test_macro(self, name, args):
-        m = self._make_macro()
+        m = make_macro(self.request, self.page)
         return m.execute(name, args)
 
     def testGetValNoACLs(self):
         """ macro GetVal test: 'reads VAR' """
-
         self.page = create_page(self.request, self.pagename, u' VAR:: This is an example')
-
         result = self._test_macro(u'GetVal', "%s,%s" % (self.pagename, u'VAR'))
-
         assert result == "This is an example"
 
     def testGetValAfterADictPageIsDeleted(self):
         """ macro GetVal test: 'reads Dict var after another Dict is removed' """
         request = self.request
-
         page = create_page(request, u'SomeDict', u" EXAMPLE:: This is an example text")
         page.deletePage()
-
         page = create_page(request, self.pagename, u' VAR:: This is a brand new example')
         result = self._test_macro(u'GetVal', "%s,%s" % (self.pagename, u'VAR'))
-
         nuke_page(request, u'SomeDict')
-
         assert result == "This is a brand new example"
 
     def testGetValACLs(self):
--- a/MoinMoin/macro/_tests/test_Hits.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/macro/_tests/test_Hits.py	Mon Aug 18 02:27:53 2008 +0900
@@ -11,8 +11,7 @@
 from MoinMoin.logfile import eventlog
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.Page import Page
-
-from MoinMoin._tests import become_trusted, create_page, nuke_page
+from MoinMoin._tests import become_trusted, create_page, make_macro, nuke_eventlog, nuke_page
 
 class TestHits:
     """Hits: testing Hits macro """
@@ -22,39 +21,21 @@
         request = self.request
         become_trusted(request)
         self.page = create_page(request, self.pagename, u"Foo!")
-
         # for that test eventlog needs to be empty
-        fpath = request.rootpage.getPagePath('event-log', isfile=1)
-        if os.path.exists(fpath):
-            os.remove(fpath)
-
+        nuke_eventlog(request)
         # hits is based on hitcounts which reads the cache
         caching.CacheEntry(request, 'charts', 'hitcounts', scope='wiki').remove()
 
     def teardown_class(self):
         nuke_page(self.request, self.pagename)
 
-    def _make_macro(self):
-        """Test helper"""
-        from MoinMoin.parser.text import Parser
-        from MoinMoin.formatter.text_html import Formatter
-        p = Parser("##\n", self.request)
-        p.formatter = Formatter(self.request)
-        p.formatter.page = self.page
-        self.request.formatter = p.formatter
-        p.form = self.request.form
-        m = macro.Macro(p)
-        return m
-
     def _test_macro(self, name, args):
-        m = self._make_macro()
+        m = make_macro(self.request, self.page)
         return m.execute(name, args)
 
     def _cleanStats(self):
         # cleans all involved cache and log files
-        fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
-        if os.path.exists(fpath):
-            os.remove(fpath)
+        nuke_eventlog(self.request)
         # hits is based on hitcounts which reads the cache
         caching.CacheEntry(self.request, 'charts', 'hitcounts', scope='wiki').remove()
         arena = Page(self.request, self.pagename)
@@ -67,7 +48,6 @@
         eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': 'WikiSandBox'})
         for i in range(count):
             eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': self.pagename})
-
         result = self._test_macro(u'Hits', u'')
         self._cleanStats()
         assert result == str(count)
@@ -81,7 +61,6 @@
         for i in range(count):
             for pagename in pagenames:
                 eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': pagename})
-
         result = self._test_macro(u'Hits', u'all=True')
         self._cleanStats()
         assert result == str(count * num_pages)
@@ -91,7 +70,6 @@
         eventlog.EventLog(self.request).add(self.request, 'SAVEPAGE', {'pagename': self.pagename})
         # simulate a log entry SAVEPAGE for WikiSandBox to destinguish current page
         eventlog.EventLog(self.request).add(self.request, 'SAVEPAGE', {'pagename': 'WikiSandBox'})
-
         result = self._test_macro(u'Hits', u'event_type=SAVEPAGE')
         self._cleanStats()
         assert result == "1"
@@ -100,7 +78,6 @@
         """ macro test: 'all=True, event_type=SAVEPAGE' for Hits (all pages are counted for SAVEPAGE)"""
         eventlog.EventLog(self.request).add(self.request, 'SAVEPAGE', {'pagename': 'WikiSandBox'})
         eventlog.EventLog(self.request).add(self.request, 'SAVEPAGE', {'pagename': self.pagename})
-
         result = self._test_macro(u'Hits', u'all=True, event_type=SAVEPAGE')
         self._cleanStats()
         assert result == "2"
--- a/MoinMoin/macro/_tests/test_PageHits.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/macro/_tests/test_PageHits.py	Mon Aug 18 02:27:53 2008 +0900
@@ -3,7 +3,6 @@
     MoinMoin - MoinMoin.macro PageHits tested
 
     @copyright: 2008 MoinMoin:ReimarBauer
-
     @license: GNU GPL, see COPYING for details.
 """
 import os
@@ -13,7 +12,7 @@
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.Page import Page
 
-from MoinMoin._tests import become_trusted, create_page, nuke_page
+from MoinMoin._tests import become_trusted, create_page, make_macro, nuke_eventlog, nuke_page
 
 class TestHits:
     """Hits: testing Hits macro """
@@ -23,12 +22,8 @@
         request = self.request
         become_trusted(request)
         self.page = create_page(request, self.pagename, u"Foo!")
-
         # for that test eventlog needs to be empty
-        fpath = request.rootpage.getPagePath('event-log', isfile=1)
-        if os.path.exists(fpath):
-            os.remove(fpath)
-
+        nuke_eventlog(self.request)
         # hits is based on hitcounts which reads the cache
         caching.CacheEntry(request, 'charts', 'pagehits', scope='wiki').remove()
         caching.CacheEntry(request, 'charts', 'hitcounts', scope='wiki').remove()
@@ -36,20 +31,8 @@
     def teardown_class(self):
         nuke_page(self.request, self.pagename)
 
-    def _make_macro(self):
-        """Test helper"""
-        from MoinMoin.parser.text import Parser
-        from MoinMoin.formatter.text_html import Formatter
-        p = Parser("##\n", self.request)
-        p.formatter = Formatter(self.request)
-        p.formatter.page = self.page
-        self.request.formatter = p.formatter
-        p.form = self.request.form
-        m = macro.Macro(p)
-        return m
-
     def _test_macro(self, name, args):
-        m = self._make_macro()
+        m = make_macro(self.request, self.page)
         return m.execute(name, args)
 
     def testPageHits(self):
@@ -58,7 +41,6 @@
         for counter in range(count):
             eventlog.EventLog(self.request).add(self.request, 'VIEWPAGE', {'pagename': 'PageHits'})
             result = self._test_macro(u'PageHits', u'') # XXX SENSE???
-
         cache = caching.CacheEntry(self.request, 'charts', 'pagehits', scope='wiki', use_pickle=True)
         date, hits = 0, {}
         if cache.exists():
--- a/MoinMoin/macro/_tests/test_StatsChart.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/macro/_tests/test_StatsChart.py	Mon Aug 18 02:27:53 2008 +0900
@@ -3,7 +3,6 @@
     MoinMoin - MoinMoin.macro StatsChart tested
 
     @copyright: 2008 MoinMoin:ReimarBauer
-
     @license: GNU GPL, see COPYING for details.
 """
 import os
@@ -12,7 +11,7 @@
 from MoinMoin.logfile import eventlog
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.Page import Page
-from MoinMoin._tests import become_trusted, create_page, nuke_page
+from MoinMoin._tests import become_trusted, create_page, make_macro, nuke_page
 
 class TestStatsCharts:
     """StartsChart: testing StatsChart macro """
@@ -28,21 +27,8 @@
     def teardown_class(self):
         nuke_page(self.request, self.pagename)
 
-    def _make_macro(self):
-        """Test helper"""
-        from MoinMoin.parser.text import Parser
-        from MoinMoin.formatter.text_html import Formatter
-        p = Parser("##\n", self.request)
-        p.formatter = Formatter(self.request)
-        p.formatter.page = self.page
-        self.request.page = self.page
-        self.request.formatter = p.formatter
-        p.form = self.request.form
-        m = macro.Macro(p)
-        return m
-
     def _test_macro(self, name, args):
-        m = self._make_macro()
+        m = make_macro(self.request, self.page)
         return m.execute(name, args)
 
     def testStatsChart_useragents(self):
--- a/MoinMoin/macro/_tests/test_macro.py	Sun Aug 17 23:18:35 2008 +0900
+++ b/MoinMoin/macro/_tests/test_macro.py	Mon Aug 18 02:27:53 2008 +0900
@@ -10,25 +10,25 @@
 from MoinMoin import macro
 from MoinMoin.parser.text import Parser
 from MoinMoin.formatter.text_html import Formatter
-
+from MoinMoin._tests import become_trusted, create_page, make_macro, nuke_page
 
 class TestMacro:
+    pagename = u'AutoCreatedMoinMoinTemporaryTestPageForTestMacro'
+
+    def setup_class(self):
+        request = self.request
+        become_trusted(request)
+        self.page = create_page(request, self.pagename, u"Foo!")
+
+    def teardown_class(self):
+        nuke_page(self.request, self.pagename)
+
     def testTrivialMacro(self):
         """macro: trivial macro works"""
-        m = self._make_macro()
+        m = make_macro(self.request, self.page)
         expected = m.formatter.linebreak(0)
         result = m.execute("BR", "")
         assert result == expected
 
-    def _make_macro(self):
-        """Test helper"""
-        p = Parser("##\n", self.request)
-        p.formatter = Formatter(self.request)
-        self.request.formatter = p.formatter
-        p.form = self.request.form
-        m = macro.Macro(p)
-        return m
-
-
 coverage_modules = ['MoinMoin.macro']