test_references.py
79 lines
| 2.0 KiB
| text/x-python
|
PythonLexer
Matthias BUSSONNIER
|
r8649 | import io | ||
import nose.tools as nt | ||||
Matthias BUSSONNIER
|
r9577 | import os | ||
David Warde-Farley
|
r8749 | from nose.tools import nottest | ||
David Warde-Farley
|
r8760 | from converters import ( | ||
damianavila
|
r8925 | ConverterLaTeX, ConverterMarkdown, ConverterPy, ConverterHTML, | ||
ConverterReveal | ||||
David Warde-Farley
|
r8718 | ) | ||
Matthias BUSSONNIER
|
r8649 | |||
Bussonnier Matthias
|
r8946 | @nottest | ||
def cleanfile(stn): | ||||
return filter(None, map(unicode.strip, stn.split('\n'))) | ||||
Matthias BUSSONNIER
|
r9577 | @nottest | ||
def skipiftravis(func): | ||||
if os.getenv('TRAVIS') == True: | ||||
func.__test__ = False | ||||
return func | ||||
@nottest | ||||
def is_travis(): | ||||
return os.getenv('TRAVIS') == 'true' | ||||
@nottest | ||||
def is_not_travis(): | ||||
return not is_travis() | ||||
Matthias BUSSONNIER
|
r8649 | |||
def test_evens(): | ||||
David Warde-Farley
|
r8718 | ###### | ||
# for now, we don't need to really run inkscape to extract svg | ||||
Matthias BUSSONNIER
|
r8649 | # from file, on unix, for test, we monkeypathc it to 'true' | ||
# which does not fail as doing anything. | ||||
#### | ||||
ConverterLaTeX.inkscape = 'true' | ||||
David Warde-Farley
|
r8718 | # commenting rst for now as travis build | ||
Matthias BUSSONNIER
|
r8687 | # fail because of pandoc version. | ||
converters = [ | ||||
David Warde-Farley
|
r8749 | #(ConverterRST, 'rst'), | ||
David Warde-Farley
|
r8718 | (ConverterMarkdown, 'md'), | ||
(ConverterLaTeX, 'tex'), | ||||
(ConverterPy, 'py'), | ||||
Matthias BUSSONNIER
|
r8649 | ] | ||
Matthias BUSSONNIER
|
r9577 | if is_not_travis() : | ||
converters.append((ConverterHTML, 'html')) | ||||
Matthias BUSSONNIER
|
r8649 | reflist = [ | ||
Matthias BUSSONNIER
|
r9594 | 'tests/ipynbref/data_geeks_team_calendar.orig', | ||
'tests/ipynbref/00_notebook_tour.orig', | ||||
'tests/ipynbref/IntroNumPy.orig', | ||||
'tests/ipynbref/XKCD_plots.orig', | ||||
'tests/ipynbref/Gun_Data.orig', | ||||
Matthias BUSSONNIER
|
r8649 | ] | ||
David Warde-Farley
|
r8718 | for root in reflist: | ||
for conv, ext in converters: | ||||
yield test_conversion, conv, root + '.ipynb', root + '.' + ext | ||||
Matthias BUSSONNIER
|
r8649 | |||
damianavila
|
r8925 | def test_reveal(): | ||
conv = ConverterReveal | ||||
root = 'tests/ipynbref/reveal.orig' | ||||
return test_conversion, conv, root + '.ipynb', root + '_slides.' + 'html' | ||||
Matthias BUSSONNIER
|
r8649 | @nottest | ||
Matthias BUSSONNIER
|
r8657 | def compfiles(stra, strb): | ||
Bussonnier Matthias
|
r8946 | nt.assert_equal(cleanfile(stra), | ||
cleanfile(strb)) | ||||
David Warde-Farley
|
r8718 | |||
Matthias BUSSONNIER
|
r8657 | |||
@nottest | ||||
Matthias BUSSONNIER
|
r8649 | def test_conversion(ConverterClass, ipynb, ref_file): | ||
Matthias BUSSONNIER
|
r9572 | converter = ConverterClass(infile=ipynb) | ||
Matthias BUSSONNIER
|
r8649 | converter.read() | ||
David Warde-Farley
|
r8718 | cv = converter.convert() | ||
Matthias BUSSONNIER
|
r8649 | with io.open(ref_file) as ref: | ||
value = ref.read() | ||||
David Warde-Farley
|
r8718 | compfiles(cv, value) | ||