Skip to content

Commit

Permalink
move 'view' tests from grok to grokcore.view
Browse files Browse the repository at this point in the history
  • Loading branch information
gotcha committed Jul 18, 2008
1 parent 8001e27 commit 276d709
Show file tree
Hide file tree
Showing 45 changed files with 155 additions and 112 deletions.
1 change: 1 addition & 0 deletions devel/grokcore.view/src/grokcore/view/tests/grok.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from grokcore.view.tests.components import Model, View
from grokcore.view import testing
from grokcore.component import name
2 changes: 1 addition & 1 deletion devel/grokcore.view/src/grokcore/view/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def suiteFromPackage(name):

def test_suite():
suite = unittest.TestSuite()
for name in ['template', 'static']:
for name in ['template', 'static', 'view']:
suite.addTest(suiteFromPackage(name))
return suite

Expand Down
1 change: 1 addition & 0 deletions devel/grokcore.view/src/grokcore/view/tests/view/TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* move namemultiple, nameunicode, nomodulename from tests/view to grokcore.component
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
Traceback (most recent call last):
...
GrokError: Multiple possible contexts for
<class 'grok.tests.view.ambiguouscontext.Club'>, please use the
<class 'grokcore.view.tests.view.ambiguouscontext.Club'>, please use the
'context' directive.
"""
from grokcore.view.tests import grok

import grok

class Cave(grok.Model):
pass


class Mammoth(grok.Model):
pass


class Club(grok.View):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
Traceback (most recent call last):
...
ConfigurationExecutionError: martian.error.GrokError: Conflicting templates found for name 'cavepainting' in module
<module 'grok.tests.view.dirandinlinetemplate' from ...
<module 'grokcore.view.tests.view.dirandinlinetemplate' from ...
"""
import grok
from grokcore.view.tests import grok
import grokcore.view

class Mammoth(grok.Model):
pass

class CavePainting(grok.View):
pass

cavepainting = grok.PageTemplate("nothing")
cavepainting = grokcore.view.PageTemplate("nothing")
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Templates can also be found in a directory with the same name as the module:
>>> grok.testing.grok(__name__)
>>> manfred = Mammoth()
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
Expand All @@ -24,13 +24,16 @@
</html>
"""
import grok
from grokcore.view.tests import grok


class Mammoth(grok.Model):
pass


class CavePainting(grok.View):
pass


class Food(grok.View):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
Traceback (most recent call last):
...
ConfigurationExecutionError: martian.error.GrokError: Multiple possible ways to render view
<class 'grok.tests.view.dirtemplateandrender.CavePainting'>.
<class 'grokcore.view.tests.view.dirtemplateandrender.CavePainting'>.
It has both a 'render' method as well as an associated template.
in:
"""
import grok
from grokcore.view.tests import grok


class Mammoth(grok.Model):
pass


class CavePainting(grok.View):

def render(self):
pass
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""
A template directory may only contain recognized template files::
>>> from grok.testing import warn
>>> import warnings
>>> saved_warn = warnings.warn
>>> warnings.warn = warn
>>> warnings.warn = grok.testing.warn
>>> grok.testing.grok(__name__)
From grok.testing's warn():
Expand All @@ -14,10 +13,12 @@
>>> warnings.warn = saved_warn
"""
import grok
from grokcore.view.tests import grok


class Mammoth(grok.Model):
pass


class Index(grok.View):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
Traceback (most recent call last):
...
ConfigurationExecutionError: martian.error.GrokError: Multiple possible ways to render view
<class 'grok.tests.view.eithertemplateorrender.CavePainting'>.
<class 'grokcore.view.tests.view.eithertemplateorrender.CavePainting'>.
It has both a 'render' method as well as an associated template.
in:
"""
import grok
from grokcore.view.tests import grok
import grokcore.view


class Mammoth(grok.Model):
pass


class CavePainting(grok.View):

def render(self):
pass

cavepainting = grok.PageTemplate("nothing")
cavepainting = grokcore.view.PageTemplate("nothing")
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
"""
It is too confusing to have a template that would be implicitly
associated with a view while that view already refers to another
template using grok.template. Therefore there is an error:
template using grokcore.view.template. Therefore there is an error:
>>> grok.testing.grok(__name__)
Traceback (most recent call last):
...
ConfigurationExecutionError: martian.error.GrokError: Multiple possible templates for view
<class 'grok.tests.view.explicitimplicittemplate.Painting'>.
<class 'grokcore.view.tests.view.explicitimplicittemplate.Painting'>.
It uses grok.template('cavepainting'), but there is also a template
called 'painting'.
in:
"""
import grok
from grokcore.view.tests import grok
import grokcore.view


class Mammoth(grok.Model):
pass


class Painting(grok.View):
grok.template('cavepainting')
grokcore.view.template('cavepainting')


cavepainting = grokcore.view.PageTemplate("GROK CAVEPAINT MAMMOTH!")

cavepainting = grok.PageTemplate("GROK CAVEPAINT MAMMOTH!")
painting = grok.PageTemplate("GROK PAINT MAMMOTH!")
painting = grokcore.view.PageTemplate("GROK PAINT MAMMOTH!")
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using a variable named `viewname_pt`:
>>> grok.testing.grok(__name__)
>>> manfred = Mammoth()
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
Expand All @@ -15,8 +15,8 @@
<h1>Mammoth Cave Painting</h1>
<ul>
<li><zope.publisher.browser.TestRequest instance URL=http://127.0.0.1></li>
<li><grok.tests.view.inline.CavePainting object at 0x...></li>
<li><grok.tests.view.inline.Mammoth object at 0x...></li>
<li><grokcore.view.tests.view.inline.CavePainting object at 0x...></li>
<li><grokcore.view.tests.view.inline.Mammoth object at 0x...></li>
<li><zope.app.pagetemplate.engine.TraversableModuleImporter object at 0x...></li>
</ul>
</body>
Expand All @@ -34,15 +34,19 @@
<html><body><h1>GROK HUNT MAMMOTH!</h1></body></html>
"""
import grok
from grokcore.view.tests import grok
import grokcore.view


class Mammoth(grok.Model):
pass


class CavePainting(grok.View):
pass

cavepainting = grok.PageTemplate("""\

cavepainting = grokcore.view.PageTemplate("""\
<html>
<body>
<h1 tal:content="string:Mammoth Cave Painting"/>
Expand All @@ -56,10 +60,11 @@ class CavePainting(grok.View):
</html>
""")


class Hunt(grok.View):
grok.name('hunting')

hunt = grok.PageTemplate("""\

hunt = grokcore.view.PageTemplate("""\
<html><body><h1>GROK HUNT MAMMOTH!</h1></body></html>
""")

Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
>>> grok.testing.grok(__name__)
From grok.testing's warn():
...UserWarning: Found the following unassociated template(s) when grokking
'grok.tests.view.inline_unassociated': club. Define view classes inheriting
'grokcore.view.tests.view.inline_unassociated': club. Define view classes inheriting
from grok.View to enable the template(s)...
>>> warnings.warn = saved_warn
"""
import grok
from grokcore.view.tests import grok
import grokcore.view


class Mammoth(grok.Model):
pass

club = grok.PageTemplate("""\

club = grokcore.view.PageTemplate("""\
<html><body><h1>GROK CLUB MAMMOTH!</h1></body></html>
""")
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
We do not accept bogus inline template such as ones that contain
encoded strings:
>>> import grok
>>> grok.PageTemplate('''
>>> import grokcore.view
>>> grokcore.view.PageTemplate('''
... <html>
... <body><h1 tal:content="string:Mammoth Cave Painting"/>
... <p>ööö</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
Traceback (most recent call last):
...
GrokError: No module-level context for
<class 'grok.tests.view.missingcontext.Club'>, please use the
<class 'grokcore.view.tests.view.missingcontext.Club'>, please use the
'context' directive.
"""
from grokcore.view.tests import grok

import grok

class Club(grok.View):
pass
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
You can't call grok.name multiple times for a view
>>> import grok.tests.view.namemultiple_fixture
>>> import grokcore.view.tests.view.namemultiple_fixture
Traceback (most recent call last):
...
GrokImportError: The 'name' directive can only be called once per class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
This should fail:
"""
import grok
from grokcore.view.tests import grok

class MultipleNames(grok.View):
grok.name('mammoth')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@
unicode or ASCII.
"""
import grok
from grokcore.view.tests import grok


def pass_unicode():

class View(object):
grok.name(u'name')


def pass_encodedstring():

class View(object):
grok.name("ölkj")


def pass_object():

class View(object):
grok.name(object())
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
You can't call grok.name on a module:
>>> import grok.tests.view.nomodulename_fixture
>>> import grokcore.view.tests.view.nomodulename_fixture
Traceback (most recent call last):
...
GrokImportError: The 'name' directive can only be used on class level.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
This should fail:
"""
import grok
from grokcore.view.tests import grok

grok.name('viewname')
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
>>> grok.testing.grok(__name__)
Traceback (most recent call last):
...
ConfigurationExecutionError: martian.error.GrokError: View <class 'grok.tests.view.notemplateorrender.CavePainting'>
ConfigurationExecutionError: martian.error.GrokError: View <class 'grokcore.view.tests.view.notemplateorrender.CavePainting'>
has no associated template or 'render' method.
in:
"""
from grokcore.view.tests import grok

import grok

class Mammoth(grok.Model):
pass


class CavePainting(grok.View):
pass
Loading

0 comments on commit 276d709

Please sign in to comment.