tests: more changes to testsFolder and friends
authorrgbecker
Mon, 15 Sep 2008 13:21:33 +0000
changeset 2987 711910106e3a
parent 2986 89edcdd280a7
child 2988 1540a4be3b99
tests: more changes to testsFolder and friends
tests/runAll.py
tests/test_docs_build.py
tests/test_images.py
tests/test_invariant.py
tests/test_lib_utils.py
tests/test_pdfgen_general.py
tests/test_pdfgen_pycanvas.py
tests/test_platypus_general.py
tests/test_platypus_paragraphs.py
tests/test_platypus_tables.py
tests/test_source_chars.py
tests/test_tools_pythonpoint.py
--- a/tests/runAll.py	Mon Sep 15 11:16:32 2008 +0000
+++ b/tests/runAll.py	Mon Sep 15 13:21:33 2008 +0000
@@ -9,21 +9,39 @@
 #we need to ensure 'tests' is on the path.  It will be if you
 #run 'setup.py tests', but won't be if you CD into the tests
 #directory and run this directly
-try:
-    from reportlab.lib.testutils import setOutDir,GlobDirectoryWalker, outputfile, printLocation
-except ImportError:
-    if __name__=='__main__':
-        topDir = os.path.dirname(sys.argv[0])
-        if not topDir: topDir = os.getcwd()
-    else:
-        topDir = os.path.dirname(__file__)
-    topDir = os.path.dirname(os.path.abspath(topDir))
-    sys.path.insert(0, topDir)
-    pp=os.environ.get('PYTHONPATH','')
-    pp = pp and os.sep.join(topDir,pp) or topDir
-    os.environ['PYTHONPATH'] = pp
-    from reportlab.lib.testutils import setOutDir,GlobDirectoryWalker, outputfile, printLocation
-setOutDir(__name__)
+if __name__=='__main__':
+    P=[]
+    try:
+        from reportlab.lib.testutils import setOutDir
+    except ImportError:
+        if __name__=='__main__':
+            topDir = os.path.dirname(sys.argv[0])
+            if not topDir: topDir = os.getcwd()
+        else:
+            topDir = os.path.dirname(__file__)
+        topDir = os.path.dirname(os.path.abspath(topDir))
+        if not os.path.isdir(os.path.join(topDir,'reportlab')):
+            topDir=os.path.normpath(os.path.join(topDir,'src','..','reportlab'))
+            assert os.path.isdir(topDir), "Cannot find reportlab"
+        sys.path.insert(0, topDir)
+        P.append(topDir)
+        del topDir
+        from reportlab.lib.testutils import setOutDir
+
+    setOutDir(__name__)
+    from reportlab.lib.testutils import testsFolder as topDir
+    if topDir:
+        topDir = os.path.dirname(topDir)
+        if topDir not in sys.path:
+            sys.path.insert(0,topDir)
+            P.append(topDir)
+    del topDir
+    from reportlab.lib.testutils import GlobDirectoryWalker, outputfile, printLocation
+    pp = os.environ.get('PYTHONPATH','')
+    if pp: P.append(pp)
+    del pp
+    os.environ['PYTHONPATH']=os.pathsep.join(P)
+    del P
 
 def makeSuite(folder, exclude=[],nonImportable=[],pattern='test_*.py'):
     "Build a test suite of all available test files."
--- a/tests/test_docs_build.py	Mon Sep 15 11:16:32 2008 +0000
+++ b/tests/test_docs_build.py	Mon Sep 15 13:21:33 2008 +0000
@@ -1,7 +1,7 @@
 __version__=''' $Id$ '''
 """Tests that all manuals can be built.
 """
-from reportlab.lib.testutils import setOutDir,SecureTestCase, printLocation, testsFolder
+from reportlab.lib.testutils import setOutDir,SecureTestCase, printLocation
 setOutDir(__name__)
 import os, sys, unittest
 
@@ -10,6 +10,7 @@
 
     def test0(self):
         "Test if all manuals buildable from source."
+        from reportlab.lib.testutils import testsFolder
         docsFolder = os.path.join(testsFolder,'..','docs')
         cwd = os.getcwd()
         os.chdir(docsFolder)
--- a/tests/test_images.py	Mon Sep 15 11:16:32 2008 +0000
+++ b/tests/test_images.py	Mon Sep 15 13:21:33 2008 +0000
@@ -5,7 +5,7 @@
 __doc__="""Tests to do with image handling.
 
 Most of them make use of test\pythonpowereed.gif."""
-from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, printLocation, testsFolder
+from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, printLocation
 setOutDir(__name__)
 import os,md5
 import unittest
@@ -29,6 +29,7 @@
     "Simplest tests to import images, work under Jython or PIL"
 
     def test(self):
+        from reportlab.lib.testutils import testsFolder
         from reportlab.lib.utils import rl_isfile
         imageFileName = os.path.join(testsFolder,'pythonpowered.gif')
         assert rl_isfile(imageFileName), "%s not found!" % imageFileName
--- a/tests/test_invariant.py	Mon Sep 15 11:16:32 2008 +0000
+++ b/tests/test_invariant.py	Mon Sep 15 13:21:33 2008 +0000
@@ -5,7 +5,7 @@
 make identical file.  This does NOT test across platforms
 or python versions, only a user can do that :-)"""
 __version__='''$Id$'''
-from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation, testsFolder
+from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
 setOutDir(__name__)
 
 import unittest
@@ -15,8 +15,8 @@
 class InvarTestCase(unittest.TestCase):
     "Simplest test that makes PDF"
     def test(self):
-
         import os
+        from reportlab.lib.testutils import testsFolder
         c = Canvas(filename, invariant=1, pageCompression=0)
         c.setFont('Helvetica-Bold', 36)
         c.drawString(100,700, 'Hello World')
--- a/tests/test_lib_utils.py	Mon Sep 15 11:16:32 2008 +0000
+++ b/tests/test_lib_utils.py	Mon Sep 15 13:21:33 2008 +0000
@@ -3,7 +3,7 @@
 """Tests for reportlab.lib.utils
 """
 __version__=''' $Id$ '''
-from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, printLocation, testsFolder
+from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, printLocation
 setOutDir(__name__)
 import os
 import reportlab
@@ -14,6 +14,7 @@
 
 def _rel_open_and_read(fn):
     from reportlab.lib.utils import open_and_read
+    from reportlab.lib.testutils import testsFolder
     cwd = os.getcwd()
     os.chdir(testsFolder)
     try:
@@ -49,6 +50,7 @@
 
     def test2(self):
         "try under a well known directory NOT on the path"
+        from reportlab.lib.testutils import testsFolder
         D = os.path.join(testsFolder,'..','tools','pythonpoint')
         fn = os.path.join(D,'stdparser.py')
         if rl_isfile(fn) or rl_isfile(fn+'c') or rl_isfile(fn+'o'):
--- a/tests/test_pdfgen_general.py	Mon Sep 15 11:16:32 2008 +0000
+++ b/tests/test_pdfgen_general.py	Mon Sep 15 13:21:33 2008 +0000
@@ -4,7 +4,7 @@
 __doc__='testscript for reportlab.pdfgen'
 __version__=''' $Id$ '''
 #tests and documents new low-level canvas
-from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation, testsFolder
+from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
 setOutDir(__name__)
 import os, string
 import unittest
@@ -666,6 +666,7 @@
     c.drawText(t)
 
     if haveImages:
+        from reportlab.lib.testutils import testsFolder
         gif = os.path.join(testsFolder,'pythonpowered.gif')
         c.drawInlineImage(gif,2*inch, 7*inch)
     else:
@@ -724,6 +725,7 @@
     c.rect(1*inch, 6+14.4*inch, w, h)
     c.rect(3*inch, 6+14.4*inch, w, h)
     if haveImages:
+        from reportlab.lib.testutils import testsFolder
         png = os.path.join(testsFolder,'solid_red_alpha.png')
         c.drawImage(png, 1*inch, 8*inch+14.4, w, h, mask=None)
         c.drawImage(png, 3*inch, 8*inch+14.4, w, h, mask='auto')
--- a/tests/test_pdfgen_pycanvas.py	Mon Sep 15 11:16:32 2008 +0000
+++ b/tests/test_pdfgen_pycanvas.py	Mon Sep 15 13:21:33 2008 +0000
@@ -4,7 +4,7 @@
 __version__=''' $Id$ '''
 __doc__='testscript for reportlab.pdfgen'
 #tests and documents new low-level canvas and the pycanvas module to output Python source code.
-from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation, testsFolder
+from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
 setOutDir(__name__)
 import string, os, unittest
 from reportlab.pdfgen import pycanvas   # gmcm 2000/10/13, pdfgen now a package
@@ -637,6 +637,7 @@
 
     c.drawText(t)
     import tests
+    from reportlab.lib.testutils import testsFolder
     gif = os.path.join(testsFolder,'pythonpowered.gif')
     if haveImages and rl_isfile(gif):
         c.drawInlineImage(gif,2*inch, 7*inch)
--- a/tests/test_platypus_general.py	Mon Sep 15 11:16:32 2008 +0000
+++ b/tests/test_platypus_general.py	Mon Sep 15 13:21:33 2008 +0000
@@ -11,7 +11,7 @@
 builds a special "document model" in which the frames are added to each page
 and drawn into.
 """
-from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation, testsFolder
+from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
 setOutDir(__name__)
 import string, copy, sys, os
 from reportlab.pdfgen import canvas
@@ -24,7 +24,7 @@
 from reportlab.rl_config import defaultPageSize
 from reportlab.lib.utils import haveImages, _RL_DIR, rl_isfile, open_for_read, fileName2Utf8
 import unittest
-import tests
+from reportlab.lib.testutils import testsFolder
 if haveImages:
     _GIF = os.path.join(testsFolder,'pythonpowered.gif')
     if not rl_isfile(_GIF): _GIF = None
--- a/tests/test_platypus_paragraphs.py	Mon Sep 15 11:16:32 2008 +0000
+++ b/tests/test_platypus_paragraphs.py	Mon Sep 15 13:21:33 2008 +0000
@@ -3,7 +3,7 @@
 """Tests for the reportlab.platypus.paragraphs module.
 """
 __version__=''' $Id$ '''
-from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation, testsFolder
+from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
 setOutDir(__name__)
 import sys, os, unittest
 from string import split, strip, join, whitespace
@@ -120,7 +120,7 @@
 it's actually easy to do using platypus.
 '''
         from reportlab.platypus.flowables import ParagraphAndImage, Image
-        import tests
+        from reportlab.lib.testutils import testsFolder
         gif = os.path.join(testsFolder,'pythonpowered.gif')
         story.append(ParagraphAndImage(Paragraph(text,bt),Image(gif)))
         phrase = 'This should be a paragraph spanning at least three pages. '
@@ -157,7 +157,7 @@
 your browser. If an internal link begins with something that looks like a scheme, precede with "document:". <strike>This text should have a strike through it.</strike>
 '''
         from reportlab.platypus.flowables import ImageAndFlowables, Image
-        import tests
+        from reportlab.lib.testutils import testsFolder
         gif = os.path.join(testsFolder,'pythonpowered.gif')
         heading = Paragraph('This is a heading',h3)
         story.append(ImageAndFlowables(Image(gif),[heading,Paragraph(text,bt)]))
@@ -383,6 +383,7 @@
                                 ),
                         ])
 
+        from reportlab.lib.testutils import testsFolder
         styleSheet = getSampleStyleSheet()
         normal = ParagraphStyle(name='normal',fontName='Times-Roman',fontSize=12,leading=1.2*12,parent=styleSheet['Normal'])
         normal_sp = ParagraphStyle(name='normal_sp',parent=normal,alignment=TA_JUSTIFY,spaceBefore=12)
--- a/tests/test_platypus_tables.py	Mon Sep 15 11:16:32 2008 +0000
+++ b/tests/test_platypus_tables.py	Mon Sep 15 13:21:33 2008 +0000
@@ -3,7 +3,7 @@
 #see license.txt for license details
 __version__=''' $Id$ '''
 __doc__='Test script for reportlab.tables'
-from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation, testsFolder
+from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
 setOutDir(__name__)
 import os,unittest
 from reportlab.platypus import Spacer, SimpleDocTemplate, Table, TableStyle
@@ -507,6 +507,7 @@
         lst.append(Spacer(0,6))
 
     lst.append(PageBreak())
+    from reportlab.lib.testutils import testsFolder
     I = Image(os.path.join(os.path.dirname(testsFolder),'tools','pythonpoint','demos','leftlogo.gif'))
     I.drawHeight = 1.25*inch*I.drawHeight / I.drawWidth
     I.drawWidth = 1.25*inch
--- a/tests/test_source_chars.py	Mon Sep 15 11:16:32 2008 +0000
+++ b/tests/test_source_chars.py	Mon Sep 15 13:21:33 2008 +0000
@@ -3,8 +3,9 @@
 #see license.txt for license details
 """This tests for things in source files.  Initially, absence of tabs :-)
 """
-from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, SecureTestCase, GlobDirectoryWalker, printLocation, testsFolder, RL_HOME
+from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, SecureTestCase, GlobDirectoryWalker, printLocation
 setOutDir(__name__)
+from reportlab.lib.testutils import RL_HOME,testsFolder
 __version__=''' $Id$ '''
 import os, sys, glob, string, re
 from types import ModuleType, ClassType, MethodType, FunctionType
--- a/tests/test_tools_pythonpoint.py	Mon Sep 15 11:16:32 2008 +0000
+++ b/tests/test_tools_pythonpoint.py	Mon Sep 15 13:21:33 2008 +0000
@@ -1,6 +1,6 @@
 """Tests for the PythonPoint tool.
 """
-from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation, testsFolder
+from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
 setOutDir(__name__)
 import os, sys, string
 import unittest