-
Notifications
You must be signed in to change notification settings - Fork 844
/
Copy pathtest_rmd_reader.py
162 lines (129 loc) · 5.82 KB
/
test_rmd_reader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
'''
Created on Jan 25, 2016
@author: Aaron Kitzmiller <[email protected]?
'''
import unittest, os, sys
import shutil
import logging
import glob
from pelican import Pelican
from pelican.settings import read_settings
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
class Test(unittest.TestCase):
def setUp(self):
try:
import rpy2
import rmd_reader
except Exception:
raise unittest.SkipTest("rpy not installed. Will not test rmd_reader.")
self.testtitle = 'rtest'
self.cwd = os.path.dirname(os.path.abspath(__file__))
logging.debug(self.cwd)
# Setup content dir and test rmd file
self.contentdir = os.path.join(self.cwd,'test-content')
logging.debug(self.contentdir)
try:
os.mkdir(self.contentdir)
except Exception:
pass
self.contentfile = os.path.join(self.contentdir,'test.rmd')
logging.debug(self.contentfile)
self.testrmd = '''Title: %s
Date: 2014-06-23
Let's make a simple plot about cars.
```{r}
cars <- c(1, 3, 6, 4, 9)
plot(cars)
```
''' % self.testtitle
with open(self.contentfile,'w') as f:
f.write(self.testrmd)
# Setup output dir
self.outputdir = os.path.join(self.cwd,'test-output')
logging.debug(self.outputdir)
try:
os.mkdir(self.outputdir)
except Exception:
pass
self.figpath = 'images'
def tearDown(self):
logging.debug('CLEAN')
if os.path.isdir(self.outputdir):
shutil.rmtree(self.outputdir)
if os.path.isdir(self.contentdir):
shutil.rmtree(self.contentdir)
def testKnitrSettings(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': 'disable',
'PLUGIN_PATHS': ['../'],
'PLUGINS': ['rmd_reader'],
'AUTHOR': 'Bob Anonymous',
})
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, 'unnamed-chunk') + '-1-1.png'
logging.debug(imagefile)
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))
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': 'chunklabel',
'PLUGIN_PATHS': ['../'],
'PLUGINS': ['rmd_reader'],
'AUTHOR': 'Bob Anonymous',
})
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))
def testKnitrSettings3(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': 'directory',
'PLUGIN_PATHS': ['../'],
'PLUGINS': ['rmd_reader'],
'AUTHOR': 'Bob Anonymous',
})
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]) + '-unnamed-chunk-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__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()