test_templates.py
55 lines
| 1.7 KiB
| text/x-python
|
PythonLexer
/ tests / test_templates.py
Matthias BUSSONNIER
|
r9586 | import io | ||
import nose.tools as nt | ||||
import os | ||||
from nose.tools import nottest | ||||
from converters.template import ConverterTemplate | ||||
Matthias BUSSONNIER
|
r9633 | from IPython.config.loader import PyFileConfigLoader | ||
Matthias BUSSONNIER
|
r9653 | from IPython.config.loader import load_pyconfig_files | ||
Matthias BUSSONNIER
|
r9633 | |||
Matthias BUSSONNIER
|
r9653 | @nottest | ||
def cleanfile(stn): | ||||
return filter(None, map(unicode.strip, stn.split('\n'))) | ||||
Matthias BUSSONNIER
|
r9586 | |||
Matthias BUSSONNIER
|
r9653 | @nottest | ||
def compfiles(stra, strb): | ||||
nt.assert_equal(cleanfile(stra), | ||||
cleanfile(strb)) | ||||
Matthias BUSSONNIER
|
r9586 | |||
def test_evens(): | ||||
reflist = [ | ||||
'tests/ipynbref/IntroNumPy.orig' | ||||
] | ||||
Matthias BUSSONNIER
|
r9633 | test_profiles = [prof for prof in os.listdir('profile/test/') if prof.endswith('.py')] | ||
### null template should return empty | ||||
Matthias BUSSONNIER
|
r9634 | for prof in test_profiles : | ||
yield check_null_profile,prof | ||||
Matthias BUSSONNIER
|
r9633 | ### end null test | ||
Matthias BUSSONNIER
|
r9586 | |||
Matthias BUSSONNIER
|
r9653 | for ipynb in [ | ||
'IntroNumPy.orig.ipynb', | ||||
'00_notebook_tour.orig.ipynb' | ||||
]: | ||||
for k,v in {'rst':'.rst','full_html':'.html','latex_base':'.tex'}.iteritems(): | ||||
yield test_profile,k,'tests/ipynbref/'+ipynb,'tests/template_ref/'+ipynb[:-6].replace('.','_')+v | ||||
@nottest | ||||
Matthias BUSSONNIER
|
r9634 | def check_null_profile(profile): | ||
loader = PyFileConfigLoader(profile, path=[os.path.join(os.getcwdu(),'profile/test')]) | ||||
config = loader.load_config() | ||||
C = ConverterTemplate(config=config) | ||||
Matthias BUSSONNIER
|
r9640 | result,_ = C.from_filename('tests/ipynbref/IntroNumPy.orig.ipynb') | ||
Matthias BUSSONNIER
|
r9653 | nt.assert_equal(result.strip('\n'),'') | ||
@nottest | ||||
def test_profile(profile_name,infile, reference_file): | ||||
loader = PyFileConfigLoader(profile_name+'.nbcv',path=[os.path.join(os.getcwdu(),'profile/')]) | ||||
config = loader.load_config() | ||||
C = ConverterTemplate(config=config) | ||||
output,resources = C.from_filename(infile) | ||||
with io.open(reference_file,'r') as f: | ||||
compfiles(output,f.read()) | ||||
Matthias BUSSONNIER
|
r9634 | |||