Initial import

This commit is contained in:
Gaetan Delannay 2009-06-29 14:06:01 +02:00
commit 4043163fc4
427 changed files with 18387 additions and 0 deletions

16
pod/test/Readme.txt Executable file
View file

@ -0,0 +1,16 @@
Here you will find some ODT documents that are POD templates.
A POD template is a standard ODT file, where:
- notes are used to insert Python-based code for telling POD to render
a portion of the document zero, one or more times ("if" and "for" statements);
- text insertions in "track changes" mode are interpreted as Python expressions.
When you invoke the tester.py program with one of those ODT files as unique parameter
(ie "python tester.py ForCellOnlyOne.odt"), you get a result.odt file which is the
result of executing the template with a bunch of Python objects. The "tests" dictionary
defined in tester.py contains the objects that are given to each POD ODT template
contained in this folder.
Opening the templates with OpenOffice (2.0 or higher), running tester.py on it and
checking the result in result.odt is probably the quickest way to have a good idea
of what appy.pod can make for you !

223
pod/test/Tester.py Executable file
View file

@ -0,0 +1,223 @@
# ------------------------------------------------------------------------------
# Appy is a framework for building applications in the Python language.
# Copyright (C) 2007 Gaetan Delannay
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA.
# ------------------------------------------------------------------------------
import os, os.path, sys, zipfile, re, shutil
import appy.shared.test
from appy.shared.test import TesterError
from appy.shared.utils import FolderDeleter
from appy.pod.odf_parser import OdfEnvironment, OdfParser
from appy.pod.renderer import Renderer
from appy.pod import XML_SPECIAL_CHARS
# TesterError-related constants ------------------------------------------------
TEMPLATE_NOT_FOUND = 'Template file "%s" was not found.'
CONTEXT_NOT_FOUND = 'Context file "%s" was not found.'
EXPECTED_RESULT_NOT_FOUND = 'Expected result "%s" was not found.'
# ------------------------------------------------------------------------------
class AnnotationsRemover(OdfParser):
'''This parser is used to remove from content.xml and styles.xml the
Python tracebacks that may be dumped into OpenDocument annotations by
pod when generating errors. Indeed, those tracebacks contain lot of
machine-specific info, like absolute paths to the python files, etc.'''
def __init__(self, env, caller):
OdfParser.__init__(self, env, caller)
self.res = u''
self.inAnnotation = False # Are we parsing an annotation ?
self.textEncountered = False # Within an annotation, have we already
# met a text ?
self.ignore = False # Must we avoid dumping the current tag/content
# into the result ?
def startElement(self, elem, attrs):
e = OdfParser.startElement(self, elem, attrs)
# Do we enter into an annotation ?
if elem == '%s:annotation' % e.ns(e.NS_OFFICE):
self.inAnnotation = True
self.textEncountered = False
elif elem == '%s:p' % e.ns(e.NS_TEXT):
if self.inAnnotation:
if not self.textEncountered:
self.textEncountered = True
else:
self.ignore = True
if not self.ignore:
self.res += '<%s' % elem
for attrName, attrValue in attrs.items():
self.res += ' %s="%s"' % (attrName, attrValue)
self.res += '>'
def endElement(self, elem):
e = OdfParser.endElement(self, elem)
if elem == '%s:annotation' % e.ns(e.NS_OFFICE):
self.inAnnotation = False
self.ignore = False
if not self.ignore:
self.res += '</%s>' % elem
def characters(self, content):
e = OdfParser.characters(self, content)
if not self.ignore:
for c in content:
if XML_SPECIAL_CHARS.has_key(c):
self.res += XML_SPECIAL_CHARS[c]
else:
self.res += c
def getResult(self):
return self.res
# ------------------------------------------------------------------------------
class Test(appy.shared.test.Test):
'''Abstract test class.'''
interestingOdtContent = ('content.xml', 'styles.xml')
def __init__(self, testData, testDescription, testFolder, config, flavour):
appy.shared.test.Test.__init__(self, testData, testDescription,
testFolder, config, flavour)
self.templatesFolder = os.path.join(self.testFolder, 'templates')
self.contextsFolder = os.path.join(self.testFolder, 'contexts')
self.resultsFolder = os.path.join(self.testFolder, 'results')
self.result = None
def getContext(self, contextName):
'''Gets the objects that are in the context.'''
contextPy = os.path.join(self.contextsFolder, contextName + '.py')
if not os.path.exists(contextPy):
raise TesterError(CONTEXT_NOT_FOUND % contextPy)
contextPkg = 'appy.pod.test.contexts.%s' % contextName
exec 'import %s' % contextPkg
exec 'context = dir(%s)' % contextPkg
res = {}
for elem in context:
if not elem.startswith('__'):
exec 'res[elem] = %s.%s' % (contextPkg, elem)
return res
def do(self):
self.result = os.path.join(
self.tempFolder, '%s.%s' % (
self.data['Name'], self.data['Result']))
# Get the path to the template to use for this test
template = os.path.join(self.templatesFolder,
self.data['Template'] + '.odt')
if not os.path.exists(template):
raise TesterError(TEMPLATE_NOT_FOUND % template)
# Get the context
context = self.getContext(self.data['Context'])
# Get the OpenOffice port
ooPort = self.data['OpenOfficePort']
pythonWithUno = self.config['pythonWithUnoPath']
# Get the styles mapping
stylesMapping = eval('{' + self.data['StylesMapping'] + '}')
# Mmh, dicts are not yet managed by RtfTablesParser
# Call the renderer.
Renderer(template, context, self.result, ooPort=ooPort,
pythonWithUnoPath=pythonWithUno,
stylesMapping=stylesMapping).run()
# Store all result files
# I should allow to do this from an option given to Tester.py: this code
# keeps in a separate folder the odt results of all ran tests.
#tempFolder2 = '%s/sevResults' % self.testFolder
#if not os.path.exists(tempFolder2):
# os.mkdir(tempFolder2)
#print 'Result is', self.result, 'temp folder 2 is', tempFolder2
#shutil.copy(self.result, tempFolder2)
def getOdtContent(self, odtFile):
'''Creates in the temp folder content.xml and styles.xml extracted
from p_odtFile.'''
contentXml = None
stylesXml = None
if odtFile == self.result:
filePrefix = 'actual'
else:
filePrefix = 'expected'
zipFile = zipfile.ZipFile(odtFile)
for zippedFile in zipFile.namelist():
if zippedFile in self.interestingOdtContent:
f = file(os.path.join(self.tempFolder,
'%s.%s' % (filePrefix, zippedFile)), 'wb')
fileContent = zipFile.read(zippedFile)
if zippedFile == 'content.xml':
# Sometimes, in annotations, there are Python tracebacks.
# Those tracebacks include the full path to the Python
# files, which of course may be different from one machine
# to the other. So we remove those paths.
annotationsRemover = AnnotationsRemover(
OdfEnvironment(), self)
annotationsRemover.parse(fileContent)
fileContent = annotationsRemover.getResult()
f.write(fileContent.encode('utf-8'))
f.close()
zipFile.close()
def checkResult(self):
'''r_ is False if the test succeeded.'''
# Get styles.xml and content.xml from the actual result
res = False
self.getOdtContent(self.result)
# Get styles.xml and content.xml from the expected result
expectedResult = os.path.join(self.resultsFolder,
self.data['Name'] + '.odt')
if not os.path.exists(expectedResult):
raise TesterError(EXPECTED_RESULT_NOT_FOUND % expectedResult)
self.getOdtContent(expectedResult)
for fileName in self.interestingOdtContent:
diffOccurred = self.compareFiles(
os.path.join(self.tempFolder, 'actual.%s' % fileName),
os.path.join(self.tempFolder, 'expected.%s' % fileName),
areXml=True, xmlTagsToIgnore=(
(OdfEnvironment.NS_DC, 'date'),
(OdfEnvironment.NS_STYLE, 'style')),
xmlAttrsToIgnore=('draw:name','text:name'), encoding='utf-8')
if diffOccurred:
res = True
break
return res
# Concrete test classes --------------------------------------------------------
class NominalTest(Test):
'''Tests an application model.'''
def __init__(self, testData, testDescription, testFolder, config, flavour):
Test.__init__(self, testData, testDescription, testFolder, config,
flavour)
class ErrorTest(Test):
'''Tests an application model.'''
def __init__(self, testData, testDescription, testFolder, config, flavour):
Test.__init__(self, testData, testDescription, testFolder, config,
flavour)
def onError(self):
'''Compares the error that occurred with the expected error.'''
Test.onError(self)
return not self.isExpectedError(self.data['Message'])
# ------------------------------------------------------------------------------
class PodTestFactory(appy.shared.test.TestFactory):
def createTest(testData, testDescription, testFolder, config, flavour):
if testData.table.instanceOf('ErrorTest'):
test = ErrorTest(testData, testDescription, testFolder, config,
flavour)
else:
test = NominalTest(testData, testDescription, testFolder, config,
flavour)
return test
createTest = staticmethod(createTest)
# ------------------------------------------------------------------------------
class PodTester(appy.shared.test.Tester):
def __init__(self, testPlan):
appy.shared.test.Tester.__init__(self, testPlan, [], PodTestFactory)
# ------------------------------------------------------------------------------
if __name__ == '__main__':
PodTester('Tests.rtf').run()
# ------------------------------------------------------------------------------

1688
pod/test/Tests.rtf Executable file

File diff suppressed because it is too large Load diff

1
pod/test/__init__.py Executable file
View file

@ -0,0 +1 @@

View file

@ -0,0 +1,10 @@
trueCondition = True
falseCondition = False
class O:
def __init__(self, v):
self.v = v
self.vv = v+v
oooo = [O('a'), O('b'), O('c'), O('d')]

1
pod/test/contexts/Empty.py Executable file
View file

@ -0,0 +1 @@
# This file is really empty.

View file

@ -0,0 +1,6 @@
import os.path
import appy
def getFileHandler():
return file('%s/pod/test/templates/NoPython.odt' % os.path.dirname(appy.__file__))

View file

@ -0,0 +1,3 @@
from appy.pod.test.contexts import Group
groups = [Group('group1'), Group('group2'), Group('toto')]

View file

@ -0,0 +1,6 @@
import os.path
import appy
def getAppyPath():
return os.path.dirname(appy.__file__)

View file

@ -0,0 +1,3 @@
expr1 = 'hello'
i1 = 45
f1 = 78.05

View file

@ -0,0 +1,6 @@
import os.path
import appy
def getAppyPath():
return os.path.dirname(appy.__file__)

View file

@ -0,0 +1,4 @@
from appy.pod.test.contexts import Person
persons = [Person('P1'), Person('P2'), Person('P3'), Person('P4'),
Person('P5'), Person('P6'), Person('P7'), Person('P8')]

View file

@ -0,0 +1,3 @@
from appy.pod.test.contexts import Person
persons = [Person('P1'), Person('P2'), Person('P3'), Person('P4')]

View file

@ -0,0 +1,3 @@
from appy.pod.test.contexts import Person
persons = [Person('P1'), Person('P2'), Person('P3')]

View file

@ -0,0 +1,3 @@
from appy.pod.test.contexts import Person
persons = [Person('P1'), Person('P2')]

View file

@ -0,0 +1 @@
list1 = []

View file

@ -0,0 +1 @@
list1 = ['Hello', 'World', 45, True]

View file

@ -0,0 +1,3 @@
from appy.pod.test.contexts import Person
persons = [Person('Mr 1'), Person('Ms One'), Person('Misss two')]

View file

@ -0,0 +1 @@
c1 = False

View file

@ -0,0 +1 @@
c1 = True

View file

@ -0,0 +1,2 @@
IWillTellYouWhatInAMoment = 'return'
beingPaidForIt = True

View file

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
xhtmlInput = '''
<p>Te<b>s</b>t1 : <b>bold</b>, i<i>tal</i>ics, exponent<sup>34</sup>, sub<sub>45</sub>.</p>
<p>An <a href="http://www.google.com">hyperlink</a> to Google.</p>
<ol><li>Number list, item 1</li>
<ol><li>Sub-item 1</li><li>Sub-Item 2</li>
<ol><li>Sub-sub-item A</li><li>Sub-sub-item B <i>italic</i>.</li></ol>
</ol>
</ol>
<ul><li>A bullet</li>
<ul><li>A sub-bullet</li>
<ul><li>A sub-sub-bullet</li></ul>
<ol><li>A sub-sub number</li><li>Another.<br /></li></ol>
</ul>
</ul>
<h2>Heading<br /></h2>
Heading Blabla.<br />
<h3>SubHeading</h3>
Subheading blabla.<br />
'''
# I need a class.
class D:
def getAt1(self):
return xhtmlInput
dummy = D()

View file

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
xhtmlInput = '''
<div><strong>Programmes FSE Convergence et Compétitivité
régionale et emploi.</strong></div>'''
xhtmlInput2 = '''<b>Walloon entreprises, welcome !</b><br/>
<br/>
This site will allow you to get simple answers to those questions:<br/>
- am I an SME or not ?<br/>
- to which incentives may I postulate for, in Wallonia, according to my size?
<br/>The little test which you will find on this site is based on the European
Recommendation of May 6th, 2003. It was enforced on January 1st, 2005.
Most of the incentives that are available for SMEs in Wallonia are based
on the SME definition proposed by this recommandation.<br/><br/>
Incentives descriptions come from the
<a href="http://economie.wallonie.be/" target="_blank">MIDAS</a>
database and represent all incentives that are available on the Walloon
territory, whatever public institution is proposing it.<br/><br/>
<b>Big enterprises, do not leave !</b><br/><br/>
If this sites classifies you as a big enterprise, you will be able to consult
all incentives that are targeted to you.'''
xhtmlInput3 = '''
<div><strong>Programmes A</strong></div>
<div>Programmes B</div>
<div><strong>Programmes C</strong></div>
<ul><li>a</li><li>b</li></ul>'''

View file

@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
xhtmlInput = '''
<p>
<table class="plain">
<thead>
<tr>
<th class="align-right" align="right">Title column one<br /></th>
<th>title column two</th>
</tr>
</thead>
<tbody>
<tr>
<td class="align-right" align="right">Hi with a <a class="generated" href="http://easi.wallonie.be">http://easi.wallonie.be</a> <br /></td>
<td>fdff</td>
</tr>
<tr>
<td class="align-right" align="right"><br /></td>
<td><br /></td>
</tr>
<tr>
<td class="align-right" align="left">Some text here<br />
<ul><li>Bullet One</li><li>Bullet Two</li>
<ul><li>Sub-bullet A</li><li>Sub-bullet B</li>
<ul><li>Subsubboulette<br /></li></ul>
</ul>
</ul>
</td>
<td>
<table>
<tbody>
<tr>
<td>SubTable</td>
<td>Columns 2<br /></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<br /></p>
'''
xhtmlInput2 = '''
<ul><li>
<p>a</p>
</li><li>
<p>b</p>
</li><li>
<p>c</p>
</li>
<ul>
<li><p>SUB</p>
</li>
</ul>
</ul>
'''

View file

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
xhtmlInput = '''
<p>Some HTML entities: é: &eacute;, è: &egrave;, Atilde: &Atilde;.</p>
<p>XML entities: amp: &amp;, quote: &quot;, apos: &apos;, lt: &lt;, gt: &gt;.</p>'''

View file

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
# I need a class.
class D:
def getAt1(self):
return '''
<p>Notifia</p>
<ol>
<li>Een</li>
<li>Een</li>
<li>Een</li>
<li class="podItemKeepWithNext">Keep with next, without style mapping.</li>
<li>Een</li>
<li>Een</li>
<li>Een</li>
<li>Een</li>
<li>Een</li>
<li>Een</li>
<li>Een</li>
<ul><li class="pmItemKeepWithNext">This one has 'keep with next'</li>
<li>Hello</li>
<ol><li>aaaaaaaaaa aaaaaaaaaaaaaa</li>
<li>aaaaaaaaaa aaaaaaaaaaaaaa</li>
<li>aaaaaaaaaa aaaaaaaaaaaaaa</li>
<li class="pmItemKeepWithNext">This one has 'keep with next'</li>
</ol>
</ul>
<li>Een</li>
<li>Een</li>
<li>Een</li>
<li>Een</li>
<li>Een</li>
<li>Een</li>
<li class="pmItemKeepWithNext">This one has 'keep with next'</li>
</ol>
<ul>
<li>Un</li>
<li>Deux</li>
<li>Trois</li>
<li>Quatre</li>
<li class="pmItemKeepWithNext">VCinq (this one has 'keep with next')</li>
<li class="pmItemKeepWithNext">Six (this one has 'keep with next')</li>
<li class="pmItemKeepWithNext">Sept (this one has 'keep with next')</li>
</ul>'''
dummy = D()

View file

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# I need a class.
class D:
def getAt1(self):
return '\n<p>Test1<br /></p>\n'
dummy = D()

View file

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
xhtmlInput = '''
<p>Hello.</p>
<h2>Heading One</h2>
Blabla.<br />
<h3>SubHeading then.</h3>
Another blabla.<br /><br /><br /> '''
# I need a class.
class D:
def getAt1(self):
return xhtmlInput
dummy = D()

View file

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
xhtmlInput = '''
<p>Hello.</p>
<h2>Heading One</h2>
Blabla.<br />
<h3>SubHeading then.</h3>
Another blabla.<br /><br /><br /> '''
# I need a class.
class D:
def getAt1(self):
return xhtmlInput
dummy = D()

View file

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
xhtmlInput = '''
<p>Table test.</p>
<p>
<table class="plain">
<tbody>
<tr>
<td>Table 1 <br /></td>
<td colspan="2">aaaaa<br /></td>
</tr>
<tr>
<td>zzz <br /></td>
<td>
<table>
<tr>
<td>SubTableA</td>
<td>SubTableB</td>
</tr>
<tr>
<td>SubTableC</td>
<td>SubTableD</td>
</tr>
</table>
</td>
<td><b>Hello</b> blabla<table><tr><td>SubTableOneRowOneColumn</td></tr></table></td>
</tr>
<tr>
<td><p>Within a <b>para</b>graph</p></td>
<td><b>Hello</b> non bold</td>
<td>Hello <b>bold</b> not bold</td>
</tr>
</tbody>
</table>
</p>
<br />'''

18
pod/test/contexts/__init__.py Executable file
View file

@ -0,0 +1,18 @@
# Here I define some classes that will be used for defining objects in several
# contexts.
class Person:
def __init__(self, name):
self.name = name
self.lastName = '%s last name' % name
self.firstName = '%s first name' % name
self.address = '%s address' % name
class Group:
def __init__(self, name):
self.name = name
if name == 'group1':
self.persons = [Person('P1'), Person('P2'), Person('P3')]
elif name == 'group2':
self.persons = [Person('RA'), Person('RB')]
else:
self.persons = []

BIN
pod/test/images/linux.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
pod/test/images/plone.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
pod/test/images/python.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Binary file not shown.

BIN
pod/test/results/errorFooter.odt Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
pod/test/results/errorIf.odt Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
pod/test/results/forTable.odt Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
pod/test/results/headerFooter.odt Executable file

Binary file not shown.

BIN
pod/test/results/ifAndFors1.odt Executable file

Binary file not shown.

BIN
pod/test/results/ifElseErrors.odt Executable file

Binary file not shown.

BIN
pod/test/results/imagesImport.odt Executable file

Binary file not shown.

BIN
pod/test/results/noPython.odt Executable file

Binary file not shown.

Binary file not shown.

BIN
pod/test/results/pathImport.odt Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
pod/test/results/simpleForRow.odt Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
pod/test/results/simpleTest.odt Executable file

Binary file not shown.

BIN
pod/test/results/withAnImage.odt Executable file

Binary file not shown.

BIN
pod/test/results/xhtmlComplex.odt Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
pod/test/results/xhtmlNominal.odt Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
pod/test/templates/ErrorIf.odt Executable file

Binary file not shown.

Binary file not shown.

BIN
pod/test/templates/ForCell.odt Executable file

Binary file not shown.

BIN
pod/test/templates/ForCell2.odt Executable file

Binary file not shown.

BIN
pod/test/templates/ForCell3.odt Executable file

Binary file not shown.

BIN
pod/test/templates/ForCell4.odt Executable file

Binary file not shown.

BIN
pod/test/templates/ForCell5.odt Executable file

Binary file not shown.

BIN
pod/test/templates/ForTable.odt Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
pod/test/templates/IfAndFors1.odt Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show more