|
@@ -10,7 +10,7 @@ import glob
|
|
from pelican import Pelican
|
|
from pelican import Pelican
|
|
from pelican.settings import read_settings
|
|
from pelican.settings import read_settings
|
|
|
|
|
|
-logging.basicConfig(stream=sys.stderr, level=logging.CRITICAL)
|
|
|
|
|
|
+logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
class Test(unittest.TestCase):
|
|
|
|
|
|
@@ -19,19 +19,23 @@ class Test(unittest.TestCase):
|
|
try:
|
|
try:
|
|
import rpy2
|
|
import rpy2
|
|
import rmd_reader
|
|
import rmd_reader
|
|
- except Exception, e:
|
|
|
|
|
|
+ except Exception:
|
|
raise unittest.SkipTest("rpy not installed. Will not test rmd_reader.")
|
|
raise unittest.SkipTest("rpy not installed. Will not test rmd_reader.")
|
|
|
|
|
|
self.testtitle = 'rtest'
|
|
self.testtitle = 'rtest'
|
|
self.cwd = os.path.dirname(os.path.abspath(__file__))
|
|
self.cwd = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
+ logging.debug(self.cwd)
|
|
|
|
|
|
# Setup content dir and test rmd file
|
|
# Setup content dir and test rmd file
|
|
self.contentdir = os.path.join(self.cwd,'test-content')
|
|
self.contentdir = os.path.join(self.cwd,'test-content')
|
|
|
|
+ logging.debug(self.contentdir)
|
|
try:
|
|
try:
|
|
os.mkdir(self.contentdir)
|
|
os.mkdir(self.contentdir)
|
|
except Exception:
|
|
except Exception:
|
|
pass
|
|
pass
|
|
self.contentfile = os.path.join(self.contentdir,'test.rmd')
|
|
self.contentfile = os.path.join(self.contentdir,'test.rmd')
|
|
|
|
+ logging.debug(self.contentfile)
|
|
|
|
+
|
|
self.testrmd = '''Title: %s
|
|
self.testrmd = '''Title: %s
|
|
Date: 2014-06-23
|
|
Date: 2014-06-23
|
|
|
|
|
|
@@ -46,6 +50,8 @@ plot(cars)
|
|
|
|
|
|
# Setup output dir
|
|
# Setup output dir
|
|
self.outputdir = os.path.join(self.cwd,'test-output')
|
|
self.outputdir = os.path.join(self.cwd,'test-output')
|
|
|
|
+ logging.debug(self.outputdir)
|
|
|
|
+
|
|
try:
|
|
try:
|
|
os.mkdir(self.outputdir)
|
|
os.mkdir(self.outputdir)
|
|
except Exception:
|
|
except Exception:
|
|
@@ -56,17 +62,20 @@ plot(cars)
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
def tearDown(self):
|
|
|
|
+ logging.debug('CLEAN')
|
|
if os.path.isdir(self.outputdir):
|
|
if os.path.isdir(self.outputdir):
|
|
shutil.rmtree(self.outputdir)
|
|
shutil.rmtree(self.outputdir)
|
|
if os.path.isdir(self.contentdir):
|
|
if os.path.isdir(self.contentdir):
|
|
shutil.rmtree(self.contentdir)
|
|
shutil.rmtree(self.contentdir)
|
|
|
|
|
|
-
|
|
|
|
def testKnitrSettings(self):
|
|
def testKnitrSettings(self):
|
|
settings = read_settings(path=None, override={
|
|
settings = read_settings(path=None, override={
|
|
|
|
+ 'LOAD_CONTENT_CACHE': False,
|
|
'PATH': self.contentdir,
|
|
'PATH': self.contentdir,
|
|
'OUTPUT_PATH': self.outputdir,
|
|
'OUTPUT_PATH': self.outputdir,
|
|
- 'KNITR_OPTS_CHUNK': {'fig.path' : '%s/' % self.figpath},
|
|
|
|
|
|
+ 'RMD_READER_KNITR_OPTS_CHUNK': {'fig.path' : '%s/' % self.figpath},
|
|
|
|
+ 'RMD_READER_KNITR_OPTS_KNIT': {'progress' : True, 'verbose': True},
|
|
|
|
+ 'RMD_READER_RENAME_PLOT': False,
|
|
'PLUGIN_PATHS': ['../'],
|
|
'PLUGIN_PATHS': ['../'],
|
|
'PLUGINS': ['rmd_reader'],
|
|
'PLUGINS': ['rmd_reader'],
|
|
})
|
|
})
|
|
@@ -75,12 +84,48 @@ plot(cars)
|
|
|
|
|
|
outputfilename = os.path.join(self.outputdir,'%s.html' % self.testtitle)
|
|
outputfilename = os.path.join(self.outputdir,'%s.html' % self.testtitle)
|
|
self.assertTrue(os.path.exists(outputfilename),'File %s was not created.' % outputfilename)
|
|
self.assertTrue(os.path.exists(outputfilename),'File %s was not created.' % outputfilename)
|
|
- imagesdir = os.path.join(self.outputdir,self.figpath)
|
|
|
|
|
|
+
|
|
|
|
+ imagesdir = os.path.join(self.outputdir, self.figpath)
|
|
self.assertTrue(os.path.exists(imagesdir), 'figpath not created.')
|
|
self.assertTrue(os.path.exists(imagesdir), 'figpath not created.')
|
|
|
|
+
|
|
|
|
+ imagefile = os.path.join(imagesdir, 'unnamed-chunk') + '-1-1.png'
|
|
|
|
+ logging.debug(imagefile)
|
|
images = glob.glob('%s/*' % imagesdir)
|
|
images = glob.glob('%s/*' % imagesdir)
|
|
|
|
+ logging.debug(images)
|
|
|
|
+ self.assertTrue(os.path.exists(imagefile), 'image correctly named.')
|
|
|
|
+
|
|
self.assertTrue(len(images) == 1,'Contents of images dir is not correct: %s' % ','.join(images))
|
|
self.assertTrue(len(images) == 1,'Contents of images dir is not correct: %s' % ','.join(images))
|
|
|
|
|
|
|
|
|
|
|
|
+ def testKnitrSettings2(self):
|
|
|
|
+ settings = read_settings(path=None, override={
|
|
|
|
+ 'LOAD_CONTENT_CACHE': False,
|
|
|
|
+ 'PATH': self.contentdir,
|
|
|
|
+ 'OUTPUT_PATH': self.outputdir,
|
|
|
|
+ 'RMD_READER_KNITR_OPTS_CHUNK': {'fig.path' : '%s/' % self.figpath},
|
|
|
|
+ 'RMD_READER_KNITR_OPTS_KNIT': {'progress' : True, 'verbose': True},
|
|
|
|
+ 'RMD_READER_RENAME_PLOT': True,
|
|
|
|
+ 'PLUGIN_PATHS': ['../'],
|
|
|
|
+ 'PLUGINS': ['rmd_reader'],
|
|
|
|
+ })
|
|
|
|
+ pelican = Pelican(settings=settings)
|
|
|
|
+ pelican.run()
|
|
|
|
+
|
|
|
|
+ outputfilename = os.path.join(self.outputdir,'%s.html' % self.testtitle)
|
|
|
|
+ self.assertTrue(os.path.exists(outputfilename),'File %s was not created.' % outputfilename)
|
|
|
|
+
|
|
|
|
+ imagesdir = os.path.join(self.outputdir, self.figpath)
|
|
|
|
+ self.assertTrue(os.path.exists(imagesdir), 'figpath not created.')
|
|
|
|
+
|
|
|
|
+ imagefile = os.path.join(imagesdir, os.path.splitext(os.path.split(self.contentfile)[1])[0]) + '-1-1.png'
|
|
|
|
+ logging.debug(imagefile)
|
|
|
|
+ self.assertTrue(os.path.exists(imagefile), 'image correctly named.')
|
|
|
|
+
|
|
|
|
+ images = glob.glob('%s/*' % imagesdir)
|
|
|
|
+ logging.debug(images)
|
|
|
|
+ self.assertTrue(len(images) == 1,'Contents of images dir is not correct: %s' % ','.join(images))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
#import sys;sys.argv = ['', 'Test.testName']
|
|
#import sys;sys.argv = ['', 'Test.testName']
|