Edgewall Software
Modify

Opened 9 years ago

Closed 8 years ago

#12233 closed enhancement (fixed)

Make formatter.suite available to plugins

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Milestone: 1.2
Component: wiki system Version:
Severity: normal Keywords: tests
Cc: Branch:
Release Notes:

Added function wikisyntax_test_suite in trac.wiki.test, which plugins can use to create wiki syntax tests.

API Changes:
Internal Changes:

Description

formatter.suite is useful for writing macro test cases, as seen in macros.py. However, from trac.wiki.tests import formatter fails in a plugin when the Trac is not installed in develop (editable) mode.

Attachments (1)

t12233-add-env-kwargs.diff (3.4 KB ) - added by Jun Omae 8 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 by Ryan J Ollos, 8 years ago

Edit: Created #12487 for proposed changes.

Last edited 8 years ago by Ryan J Ollos (previous) (diff)

comment:2 by Ryan J Ollos, 8 years ago

Component: generalwiki system
Keywords: tests added
Milestone: next-major-releases1.2

The only way I see to solve this is to either add trac.wiki.tests.formatter directly to the distributed package, or move the code in that file. I considered moving to trac.test, but maybe it would make sense to move to trac.wiki.test: log:rjollos.git:t12233_formatter_test_suite.

comment:3 by Jun Omae, 8 years ago

Why HelloWorldMacro is moved to trac.wiki.test package? I think WikiTestCase, subclasses of the WikiTestCase and wikisyntax_test_suite() only should be moved.

comment:4 by Ryan J Ollos, 8 years ago

WikiTestCase uses HelloWorldMacro to create an environment: trunk/trac/wiki/tests/formatter.py@14791:161-164#L143.

comment:5 by Jun Omae, 8 years ago

I think we should allow to specify components to enable for WikiTestCase and wikisyntax_test_suite. Otherwise, it wouldn't be useful to test for plugins.

comment:6 by Ryan J Ollos, 8 years ago

Owner: set to Ryan J Ollos
Status: newassigned

comment:7 by Ryan J Ollos, 8 years ago

I found we can use Environment.enable_component to enable components in the setup function that is passed to trac.wiki.test.wikisyntax_test_suite. This hadn't worked for me in the past, but the problem was that I specified a component rule rather than a module name (e.g. tractags.* rather than tractags).

Proposed changes in log:rjollos.git:t12233_formatter_test_suite.2. See th:#12788 for a patch that uses trac.wiki.test.wikisyntax_test_suite in the TagsPlugin codebase.

comment:8 by Ryan J Ollos, 8 years ago

Release Notes: modified (diff)

by Jun Omae, 8 years ago

Attachment: t12233-add-env-kwargs.diff added

comment:9 by Jun Omae, 8 years ago

How about adding arguments for EnvironmentStub like this?

 def wikisyntax_test_suite(data=None, setup=None, file=None, teardown=None,
-                          context=None):
+                          context=None, default_data=False,
+                          enable_components=None, disable_components=None,
+                          env_path=None, destroying=False):

t12233-add-env-kwargs.diff

comment:10 by Ryan J Ollos, 8 years ago

That change looks good. I'll include it in the commit.

comment:11 by Ryan J Ollos, 8 years ago

I modified the patch in th:#12788 to use enable_components. I was seeing a traceback because the tags tables aren't created when the WikiPage is created at the end of the WikiTestCase.setUp method, and TagsPlugin implements IWikiChangeListener.

======================================================================
ERROR: test (trac.wiki.test.WikiTestCase)
Test invalid realm
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/wiki/test.py", line 94, in setUp
    wiki.save('joe', 'Entry page', '::1', datetime_now(utc))
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/wiki/model.py", line 185, in save
    for listener in WikiSystem(self.env).change_listeners:
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/core.py", line 82, in extensions
    components = [component.compmgr[cls] for cls in classes]
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/core.py", line 212, in __getitem__
    component = cls(self)
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/core.py", line 144, in __call__
    self.__init__()
  File "/Users/rjollos/Documents/Workspace/trac-dev/test/tagsplugin-trunk/tractags/wiki.py", line 90, in __init__
    self.tag_system = TagSystem(self.env)
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/core.py", line 144, in __call__
    self.__init__()
  File "/Users/rjollos/Documents/Workspace/trac-dev/test/tagsplugin-trunk/tractags/api.py", line 369, in __init__
    self._populate_provider_map()
  File "/Users/rjollos/Documents/Workspace/trac-dev/test/tagsplugin-trunk/tractags/api.py", line 585, in _populate_provider_map
    for provider in self.tag_providers)
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/core.py", line 82, in extensions
    components = [component.compmgr[cls] for cls in classes]
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/core.py", line 212, in __getitem__
    component = cls(self)
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/core.py", line 144, in __call__
    self.__init__()
  File "/Users/rjollos/Documents/Workspace/trac-dev/test/tagsplugin-trunk/tractags/ticket.py", line 53, in __init__
    self._fetch_tkt_tags()
  File "/Users/rjollos/Documents/Workspace/trac-dev/test/tagsplugin-trunk/tractags/ticket.py", line 224, in _fetch_tkt_tags
    (self.realm,))
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/db/util.py", line 61, in execute
    r = self.cursor.execute(sql_escape_percent(sql), args)
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/db/sqlite_backend.py", line 87, in execute
    result = PyFormatCursor.execute(self, *args)
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/db/sqlite_backend.py", line 63, in execute
    args or [])
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/db/sqlite_backend.py", line 54, in _rollback_on_error
    return function(self, *args, **kwargs)
OperationalError: no such table: tags

----------------------------------------------------------------------
Ran 12 tests in 0.351s

FAILED (errors=2)

I considered a few solutions, such upgrading the environment in setUp:

        if self.env.needs_upgrade():
            self.env.upgrade()

One problem is that upgrade closes the database connections, so I was seeing cannot operate on closed cursor errors.

The simplest solution seems to be calling the user-specified setup function before creating the WikiPage.

  • trac/wiki/test.py

    diff --git a/trac/wiki/test.py b/trac/wiki/test.py
    index 281e513..70db7de 100644
    a b class WikiTestCase(unittest.TestCase):  
    8888        # instead of env.href
    8989        self.env.href = self.req.href
    9090        self.env.abs_href = self.req.abs_href
     91        if self._setup:
     92            self._setup(self)
    9193        wiki = WikiPage(self.env)
    9294        wiki.name = 'WikiStart'
    9395        wiki.text = '--'
    9496        wiki.save('joe', 'Entry page', '::1', datetime_now(utc))
    95         if self._setup:
    96             self._setup(self)
    9797
    9898    def tearDown(self):
    9999        self.env.reset_db()

comment:12 by Ryan J Ollos, 8 years ago

Latest proposed changes in log:rjollos.git:t12233_formatter_test_suite.3.

comment:13 by Ryan J Ollos, 8 years ago

Just spotted some test failures. I'll revise changes.

comment:14 by Ryan J Ollos, 8 years ago

Issue described in comment:11 could be avoided by inserting the page directly to the database: [83c4d2b5/rjollos.git].

comment:15 by Ryan J Ollos, 8 years ago

Resolution: fixed
Status: assignedclosed

Committed to trunk in [14840].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.