2015-06-23 03:22:51 +00:00
|
|
|
import json
|
2015-05-29 21:29:56 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import unittest
|
|
|
|
|
2015-06-23 03:22:51 +00:00
|
|
|
from mock import patch
|
|
|
|
|
2015-06-23 02:22:27 +00:00
|
|
|
from sphinx.application import Sphinx
|
2015-06-06 20:20:11 +00:00
|
|
|
|
2015-05-29 21:29:56 +00:00
|
|
|
|
2015-06-10 18:48:15 +00:00
|
|
|
class LanguageIntegrationTests(unittest.TestCase):
|
2015-05-29 21:29:56 +00:00
|
|
|
|
2015-06-23 03:22:51 +00:00
|
|
|
def _run_test(self, test_dir, test_file, test_string):
|
|
|
|
os.chdir('tests/{0}'.format(test_dir))
|
|
|
|
try:
|
|
|
|
app = Sphinx(
|
|
|
|
srcdir='.',
|
|
|
|
confdir='.',
|
|
|
|
outdir='_build/text',
|
|
|
|
doctreedir='_build/.doctrees',
|
|
|
|
buildername='text',
|
|
|
|
)
|
|
|
|
app.build(force_all=True)
|
|
|
|
with open(test_file) as fin:
|
|
|
|
text = fin.read().strip()
|
|
|
|
self.assertIn(test_string, text)
|
|
|
|
finally:
|
|
|
|
shutil.rmtree('_build')
|
|
|
|
os.chdir('../..')
|
|
|
|
|
|
|
|
|
|
|
|
class JavaScriptTests(LanguageIntegrationTests):
|
|
|
|
|
|
|
|
def _js_read(self, path):
|
|
|
|
return json.load(open('../fixtures/javascript.json'))
|
|
|
|
|
|
|
|
@patch('autoapi.mappers.javascript.JavaScriptSphinxMapper.read_file', _js_read)
|
|
|
|
def test_integration(self):
|
|
|
|
self._run_test(
|
2015-06-23 02:22:27 +00:00
|
|
|
'jsexample',
|
|
|
|
'_build/text/autoapi/Circle/index.txt',
|
|
|
|
'Creates an instance of Circle'
|
2015-06-23 03:22:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class GoTests(LanguageIntegrationTests):
|
|
|
|
|
|
|
|
def _go_read(self, path):
|
|
|
|
return json.load(open('../fixtures/go.json'))
|
|
|
|
|
|
|
|
@patch('autoapi.mappers.go.GoSphinxMapper.read_file', _go_read)
|
|
|
|
def test_integration(self):
|
|
|
|
self._run_test(
|
2015-06-23 02:22:27 +00:00
|
|
|
'goexample',
|
|
|
|
'_build/text/autoapi/main/index.txt',
|
|
|
|
'CopyFuncs produces a json-annotated array of Func objects'
|
2015-06-23 03:22:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class PythonTests(LanguageIntegrationTests):
|
|
|
|
|
|
|
|
def test_integration(self):
|
|
|
|
self._run_test(
|
|
|
|
'pyexample',
|
|
|
|
'_build/text/autoapi/example/index.txt',
|
|
|
|
'Compute the square root of x and return it'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class DotNetTests(LanguageIntegrationTests):
|
|
|
|
|
|
|
|
def _dotnet_read(self, path):
|
|
|
|
return json.load(open('../fixtures/dotnet.json'))
|
|
|
|
|
|
|
|
# Mock this because it's slow otherwise
|
|
|
|
def _dotnet_load(self, pattern, dir, ignore=[]):
|
|
|
|
data = self.read_file(path='inmem')
|
|
|
|
self.paths['inmem'] = data
|
|
|
|
|
|
|
|
@patch('autoapi.mappers.dotnet.DotNetSphinxMapper.load', _dotnet_load)
|
|
|
|
@patch('autoapi.mappers.dotnet.DotNetSphinxMapper.read_file', _dotnet_read)
|
|
|
|
def test_integration(self):
|
|
|
|
self._run_test(
|
2015-06-23 02:22:27 +00:00
|
|
|
'dotnetexample',
|
2015-06-23 03:22:51 +00:00
|
|
|
'_build/text/autoapi/Microsoft/AspNet/JsonPatch/Adapters/IObjectAdapter<TModel>/index.txt',
|
|
|
|
'Defines the operations that can be performed on a JSON patch document.'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class IntegrationTests(LanguageIntegrationTests):
|
|
|
|
|
|
|
|
def test_template_overrides(self):
|
|
|
|
self._run_test(
|
2015-06-23 02:22:27 +00:00
|
|
|
'templateexample',
|
|
|
|
'_build/text/autoapi/example/index.txt',
|
|
|
|
'This is a fuction template override'
|
2015-06-23 03:22:51 +00:00
|
|
|
)
|
2015-07-07 22:43:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TOCTreeTests(LanguageIntegrationTests):
|
|
|
|
|
|
|
|
def test_toctree_overrides(self):
|
|
|
|
self._run_test(
|
|
|
|
'toctreeexample',
|
|
|
|
'_build/text/index.txt',
|
|
|
|
'AutoAPI Index'
|
|
|
|
)
|