Opened 9 years ago
Closed 9 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 |
||
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)
Change History (16)
comment:2 by , 9 years ago
Component: | general → wiki system |
---|---|
Keywords: | tests added |
Milestone: | next-major-releases → 1.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 , 9 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 , 9 years ago
WikiTestCase
uses HelloWorldMacro
to create an environment: trunk/trac/wiki/tests/formatter.py@14791:161-164#L143.
comment:5 by , 9 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 , 9 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:7 by , 9 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 , 9 years ago
Release Notes: | modified (diff) |
---|
by , 9 years ago
Attachment: | t12233-add-env-kwargs.diff added |
---|
comment:9 by , 9 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):
comment:11 by , 9 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): 88 88 # instead of env.href 89 89 self.env.href = self.req.href 90 90 self.env.abs_href = self.req.abs_href 91 if self._setup: 92 self._setup(self) 91 93 wiki = WikiPage(self.env) 92 94 wiki.name = 'WikiStart' 93 95 wiki.text = '--' 94 96 wiki.save('joe', 'Entry page', '::1', datetime_now(utc)) 95 if self._setup:96 self._setup(self)97 97 98 98 def tearDown(self): 99 99 self.env.reset_db()
comment:12 by , 9 years ago
Latest proposed changes in log:rjollos.git:t12233_formatter_test_suite.3.
comment:14 by , 9 years ago
Issue described in comment:11 could be avoided by inserting the page directly to the database: [83c4d2b5/rjollos.git].
comment:15 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Committed to trunk in [14840].
Edit: Created #12487 for proposed changes.