2020-05-29 03:56:48 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
import os
|
2020-05-29 03:56:48 -04:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2021-01-25 21:49:01 -05:00
|
|
|
import unittest
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
|
2021-01-25 21:49:01 -05:00
|
|
|
ESP32_DOC = 'esp32_page'
|
|
|
|
ESP32_S2_DOC = 'esp32s2_page'
|
|
|
|
BT_DOC = 'bt_page'
|
|
|
|
LINK_ROLES_DOC = 'link_roles'
|
|
|
|
IDF_FORMAT_DOC = 'idf_target_format'
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
class DocBuilder():
|
|
|
|
build_docs_py_path = os.path.join(CURRENT_DIR, '..', 'build_docs.py')
|
|
|
|
|
|
|
|
def __init__(self, src_dir, build_dir, target, language):
|
|
|
|
self.language = language
|
|
|
|
self.target = target
|
|
|
|
self.src_dir = src_dir
|
|
|
|
self.build_dir = build_dir
|
|
|
|
self.html_out_dir = os.path.join(CURRENT_DIR, build_dir, language, target, 'html')
|
|
|
|
|
|
|
|
def build(self, opt_args=[]):
|
2021-01-25 21:49:01 -05:00
|
|
|
args = [sys.executable, self.build_docs_py_path, '-b', self.build_dir, '-s', self.src_dir, '-t', self.target, '-l', self.language]
|
2020-05-29 03:56:48 -04:00
|
|
|
args.extend(opt_args)
|
|
|
|
return subprocess.call(args)
|
|
|
|
|
|
|
|
|
|
|
|
class TestDocs(unittest.TestCase):
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2021-01-25 21:49:01 -05:00
|
|
|
cls.builder = DocBuilder('test', '_build/test_docs', 'esp32s2', 'en')
|
2020-05-29 03:56:48 -04:00
|
|
|
cls.build_ret_flag = cls.builder.build()
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
if self.build_ret_flag:
|
2021-01-25 21:49:01 -05:00
|
|
|
self.fail('Build docs failed with return: {}'.format(self.build_ret_flag))
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
def assert_str_not_in_doc(self, doc_name, str_to_find):
|
|
|
|
with open(os.path.join(self.builder.html_out_dir, doc_name)) as f:
|
|
|
|
content = f.read()
|
2021-01-25 21:49:01 -05:00
|
|
|
self.assertFalse(str_to_find in content, 'Found {} in {}'.format(str_to_find, doc_name))
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
def assert_str_in_doc(self, doc_name, str_to_find):
|
|
|
|
with open(os.path.join(self.builder.html_out_dir, doc_name)) as f:
|
|
|
|
content = f.read()
|
2021-01-25 21:49:01 -05:00
|
|
|
self.assertTrue(str_to_find in content, 'Did not find {} in {}'.format(str_to_find, doc_name))
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
def test_only_dir(self):
|
|
|
|
# Test that ESP32 content was excluded
|
2021-01-25 21:49:01 -05:00
|
|
|
self.assert_str_not_in_doc(ESP32_S2_DOC + '.html', '!ESP32_CONTENT!')
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
# Test that ESP32 S2 content was included
|
2021-01-25 21:49:01 -05:00
|
|
|
self.assert_str_in_doc(ESP32_S2_DOC + '.html', '!ESP32_S2_CONTENT!')
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
# Test that BT content was excluded
|
2021-01-25 21:49:01 -05:00
|
|
|
self.assert_str_not_in_doc(ESP32_S2_DOC + '.html', '!BT_CONTENT!')
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
def test_toctree_filter(self):
|
|
|
|
# ESP32 page should NOT be built
|
2021-01-25 21:49:01 -05:00
|
|
|
esp32_doc = os.path.join(self.builder.html_out_dir, ESP32_DOC + '.html')
|
|
|
|
self.assertFalse(os.path.isfile(esp32_doc), 'Found {}'.format(esp32_doc))
|
|
|
|
self.assert_str_not_in_doc('index.html', '!ESP32_CONTENT!')
|
2020-05-29 03:56:48 -04:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
esp32s2_doc = os.path.join(self.builder.html_out_dir, ESP32_S2_DOC + '.html')
|
|
|
|
self.assertTrue(os.path.isfile(esp32s2_doc), '{} not found'.format(esp32s2_doc))
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
# Spot check a few other tags
|
|
|
|
# No Bluetooth on ESP32 S2
|
2021-01-25 21:49:01 -05:00
|
|
|
bt_doc = os.path.join(self.builder.html_out_dir, BT_DOC + '.html')
|
|
|
|
self.assertFalse(os.path.isfile(bt_doc), 'Found {}'.format(bt_doc))
|
|
|
|
self.assert_str_not_in_doc('index.html', '!BT_CONTENT!')
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
def test_link_roles(self):
|
2021-01-25 21:49:01 -05:00
|
|
|
print('test')
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
class TestBuildSubset(unittest.TestCase):
|
|
|
|
def test_build_subset(self):
|
2021-01-25 21:49:01 -05:00
|
|
|
builder = DocBuilder('test', '_build/test_build_subset', 'esp32', 'en')
|
2020-05-29 03:56:48 -04:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
docs_to_build = 'esp32_page.rst'
|
2020-05-29 03:56:48 -04:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
self.assertFalse(builder.build(['-i', docs_to_build]))
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
# Check that we only built the input docs
|
2021-01-25 21:49:01 -05:00
|
|
|
bt_doc = os.path.join(builder.html_out_dir, BT_DOC + '.html')
|
|
|
|
esp32_doc = os.path.join(builder.html_out_dir, ESP32_DOC + '.html')
|
|
|
|
self.assertFalse(os.path.isfile(bt_doc), 'Found {}'.format(bt_doc))
|
|
|
|
self.assertTrue(os.path.isfile(esp32_doc), 'Found {}'.format(esp32_doc))
|
2020-05-29 03:56:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|