[py-svn] r57401 - in py/release/0.9.x/py/rest/testing: . data

hpk at codespeak.net hpk at codespeak.net
Mon Aug 18 12:52:06 CEST 2008


Author: hpk
Date: Mon Aug 18 12:52:02 2008
New Revision: 57401

Added:
   py/release/0.9.x/py/rest/testing/setup.py
Modified:
   py/release/0.9.x/py/rest/testing/data/   (props changed)
   py/release/0.9.x/py/rest/testing/test_convert.py
   py/release/0.9.x/py/rest/testing/test_directive.py
   py/release/0.9.x/py/rest/testing/test_htmlrest.py
   py/release/0.9.x/py/rest/testing/test_rst2pdf.py
Log:
refactoring tests to not create files inline 


Added: py/release/0.9.x/py/rest/testing/setup.py
==============================================================================
--- (empty file)
+++ py/release/0.9.x/py/rest/testing/setup.py	Mon Aug 18 12:52:02 2008
@@ -0,0 +1,10 @@
+import py
+
+pydir = py.path.local(py.__file__).dirpath()
+mydatadir = py.magic.autopath().dirpath().join("data")
+
+def getdata():
+    rel = mydatadir.relto(pydir)
+    tmpdir = py.test.ensuretemp(rel.replace(pydir.sep, '_'))
+    mydatadir.copy(tmpdir)
+    return tmpdir

Modified: py/release/0.9.x/py/rest/testing/test_convert.py
==============================================================================
--- py/release/0.9.x/py/rest/testing/test_convert.py	(original)
+++ py/release/0.9.x/py/rest/testing/test_convert.py	Mon Aug 18 12:52:02 2008
@@ -1,13 +1,14 @@
 import py
 from py.__.rest.convert import convert_dot, latexformula2png
-
-datadir = py.magic.autopath().dirpath().join("data")
+from py.__.rest.testing.setup import getdata
 
 def setup_module(mod):
     required = 'gs', 'dot', 'latex', 'epstopdf', 
     for exe in required:
         if not py.path.local.sysfind(exe):
             py.test.skip("%r not found, required: %r" %(exe, required))
+    mod.datadir = getdata()
+    
 
 def test_convert_dot():
     # XXX not really clear that the result is valid pdf/eps

Modified: py/release/0.9.x/py/rest/testing/test_directive.py
==============================================================================
--- py/release/0.9.x/py/rest/testing/test_directive.py	(original)
+++ py/release/0.9.x/py/rest/testing/test_directive.py	Mon Aug 18 12:52:02 2008
@@ -7,9 +7,11 @@
 from py.__.rest import directive
 from py.__.misc import rest
 from py.__.rest.latex import process_rest_file
+from py.__.rest.testing.setup import getdata
 
-datadir = py.magic.autopath().dirpath().join("data")
-testdir = py.test.ensuretemp("rest")
+def setup_module(mod):
+    mod.datadir = getdata()
+    mod.testdir = py.test.ensuretemp("rest")
 
 class TestGraphviz(object):
     def _graphviz_html(self):

Modified: py/release/0.9.x/py/rest/testing/test_htmlrest.py
==============================================================================
--- py/release/0.9.x/py/rest/testing/test_htmlrest.py	(original)
+++ py/release/0.9.x/py/rest/testing/test_htmlrest.py	Mon Aug 18 12:52:02 2008
@@ -2,6 +2,7 @@
 
 import py
 from py.__.misc import rest
+from py.__.rest.testing.setup import getdata
 
 def setup_module(mod):
     if not py.path.local.sysfind("gs") or \
@@ -13,12 +14,12 @@
     except ImportError:
         py.test.skip("docutils not present")
 
-data = py.magic.autopath().dirpath().join("data")
+    mod.datadir = getdata()
 
 def test_process_simple():
     # fallback test: only checks that no exception is raised
     def rec(p):
         return p.check(dotfile=0)
-    for x in data.visit("*.txt", rec=rec):
+    for x in datadir.visit("*.txt", rec=rec):
         yield rest.process, x
 

Modified: py/release/0.9.x/py/rest/testing/test_rst2pdf.py
==============================================================================
--- py/release/0.9.x/py/rest/testing/test_rst2pdf.py	(original)
+++ py/release/0.9.x/py/rest/testing/test_rst2pdf.py	Mon Aug 18 12:52:02 2008
@@ -2,6 +2,8 @@
 
 import py
 from py.__.rest.latex import process_configfile, process_rest_file
+from py.__.rest.testing.setup import getdata
+
 try:
     import docutils
 except ImportError:
@@ -13,22 +15,20 @@
            not py.path.local.sysfind("dot") or \
            not py.path.local.sysfind("latex"):
         py.test.skip("ghostscript, graphviz and latex needed")
-    mod.data = py.magic.autopath().dirpath().join("data")
+    mod.datadir = getdata()
 
 class TestRst2Pdf(object):
     def _process_rest_file(self):
-        data = py.magic.autopath().dirpath().join("data")
-        part2 = data.join("part1.txt")
+        part2 = datadir.join("part1.txt")
         pdf = part2.new(ext="pdf")
         process_rest_file(part2)
         assert pdf.check()
         pdf.remove()
 
     def _process_configfile(self):
-        data = py.magic.autopath().dirpath().join("data")
-        config = data.join("example.rst2pdfconfig")
+        config = datadir.join("example.rst2pdfconfig")
         pdf = config.new(ext="pdf")
-        tex = data.join('example.tex')
+        tex = datadir.join('example.tex')
         process_configfile(config, debug=True)
         assert pdf.check()
         assert tex.check()
@@ -45,9 +45,9 @@
         def rec(p):
             return p.check(dotfile=0)
 
-        for x in data.visit("*.rst2pdfconfig", rec=rec):
+        for x in datadir.visit("*.rst2pdfconfig", rec=rec):
             process_configfile(x)
-        for x in data.visit("*.txt", rec=rec):
+        for x in datadir.visit("*.txt", rec=rec):
             process_rest_file(x)
 
     def test_rst2pdf(self):



More information about the pytest-commit mailing list