import unittest
import os
import imp
import sys
import tempfile
FODDER = '''
This, that, and the other thing
This, that, and the other thing
This, that, and the other thing
This, that, and the other thing
This, that, and the other thing
This, that, and the other thing
This, that, and the other thing
This, that, and the other thing
This, that, and the other thing
This, that, and the other thing
'''
class TestPager( unittest.TestCase ):
@classmethod
def setUpClass( TestPager ):
pythonpaths = os.environ[ 'PYTHONPATH' ].split( os.pathsep )
projectpath = pythonpaths[ 0 ]
pageresultspath = projectpath + os.sep + 'code.webapp.searchui.controllers.pageresults'.replace( '.', os.sep ) + '.py'
TestPager.pageresults = loadPageResultsModule( pageresultspath )
( TestPager.fd, TestPager.path ) = tempfile.mkstemp()
os.write( TestPager.fd, FODDER )
os.close( TestPager.fd )
@classmethod
def tearDownClass( TestPager ):
os.remove( TestPager.path )
def test( self ):
pageXmlResults = self.pageresults.pageXmlResults
actual = pageXmlResults( self.path, start=2, limit=4 )
print actual
assert '02' in actual
assert '03' in actual
assert '04' in actual
assert '05' in actual
assert '01' not in actual
assert '06' not in actual
def loadPageResultsModule( path ):
module, extension = os.path.splitext( os.path.split( path ) [ -1 ] )
pageresults = imp.load_source( module, path )
return pageresults