style: format python files with isort and double-quote-string-fixer
This commit is contained in:
@@ -8,8 +8,8 @@
|
||||
try:
|
||||
from conf_common import * # noqa: F403,F401
|
||||
except ImportError:
|
||||
import sys
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath('../..'))
|
||||
from conf_common import * # noqa: F403,F401
|
||||
|
||||
@@ -27,7 +27,7 @@ html_logo = None
|
||||
latex_logo = None
|
||||
html_static_path = []
|
||||
|
||||
conditional_include_dict = {'esp32':["esp32_page.rst"],
|
||||
'esp32s2':["esp32s2_page.rst"],
|
||||
'SOC_BT_SUPPORTED':["bt_page.rst"],
|
||||
conditional_include_dict = {'esp32':['esp32_page.rst'],
|
||||
'esp32s2':['esp32s2_page.rst'],
|
||||
'SOC_BT_SUPPORTED':['bt_page.rst'],
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
import unittest
|
||||
|
||||
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
ESP32_DOC = "esp32_page"
|
||||
ESP32_S2_DOC = "esp32s2_page"
|
||||
BT_DOC = "bt_page"
|
||||
LINK_ROLES_DOC = "link_roles"
|
||||
IDF_FORMAT_DOC = "idf_target_format"
|
||||
ESP32_DOC = 'esp32_page'
|
||||
ESP32_S2_DOC = 'esp32s2_page'
|
||||
BT_DOC = 'bt_page'
|
||||
LINK_ROLES_DOC = 'link_roles'
|
||||
IDF_FORMAT_DOC = 'idf_target_format'
|
||||
|
||||
|
||||
class DocBuilder():
|
||||
@@ -24,7 +24,7 @@ class DocBuilder():
|
||||
self.html_out_dir = os.path.join(CURRENT_DIR, build_dir, language, target, 'html')
|
||||
|
||||
def build(self, opt_args=[]):
|
||||
args = [sys.executable, self.build_docs_py_path, "-b", self.build_dir, "-s", self.src_dir, "-t", self.target, "-l", self.language]
|
||||
args = [sys.executable, self.build_docs_py_path, '-b', self.build_dir, '-s', self.src_dir, '-t', self.target, '-l', self.language]
|
||||
args.extend(opt_args)
|
||||
return subprocess.call(args)
|
||||
|
||||
@@ -33,65 +33,65 @@ class TestDocs(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.builder = DocBuilder("test", "_build/test_docs", "esp32s2", "en")
|
||||
cls.builder = DocBuilder('test', '_build/test_docs', 'esp32s2', 'en')
|
||||
cls.build_ret_flag = cls.builder.build()
|
||||
|
||||
def setUp(self):
|
||||
if self.build_ret_flag:
|
||||
self.fail("Build docs failed with return: {}".format(self.build_ret_flag))
|
||||
self.fail('Build docs failed with return: {}'.format(self.build_ret_flag))
|
||||
|
||||
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()
|
||||
self.assertFalse(str_to_find in content, "Found {} in {}".format(str_to_find, doc_name))
|
||||
self.assertFalse(str_to_find in content, 'Found {} in {}'.format(str_to_find, doc_name))
|
||||
|
||||
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()
|
||||
self.assertTrue(str_to_find in content, "Did not find {} in {}".format(str_to_find, doc_name))
|
||||
self.assertTrue(str_to_find in content, 'Did not find {} in {}'.format(str_to_find, doc_name))
|
||||
|
||||
def test_only_dir(self):
|
||||
# Test that ESP32 content was excluded
|
||||
self.assert_str_not_in_doc(ESP32_S2_DOC + ".html", "!ESP32_CONTENT!")
|
||||
self.assert_str_not_in_doc(ESP32_S2_DOC + '.html', '!ESP32_CONTENT!')
|
||||
|
||||
# Test that ESP32 S2 content was included
|
||||
self.assert_str_in_doc(ESP32_S2_DOC + ".html", "!ESP32_S2_CONTENT!")
|
||||
self.assert_str_in_doc(ESP32_S2_DOC + '.html', '!ESP32_S2_CONTENT!')
|
||||
|
||||
# Test that BT content was excluded
|
||||
self.assert_str_not_in_doc(ESP32_S2_DOC + ".html", "!BT_CONTENT!")
|
||||
self.assert_str_not_in_doc(ESP32_S2_DOC + '.html', '!BT_CONTENT!')
|
||||
|
||||
def test_toctree_filter(self):
|
||||
# ESP32 page should NOT be built
|
||||
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!")
|
||||
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!')
|
||||
|
||||
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))
|
||||
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))
|
||||
|
||||
# Spot check a few other tags
|
||||
# No Bluetooth on ESP32 S2
|
||||
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!")
|
||||
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!')
|
||||
|
||||
def test_link_roles(self):
|
||||
print("test")
|
||||
print('test')
|
||||
|
||||
|
||||
class TestBuildSubset(unittest.TestCase):
|
||||
def test_build_subset(self):
|
||||
builder = DocBuilder("test", "_build/test_build_subset", "esp32", "en")
|
||||
builder = DocBuilder('test', '_build/test_build_subset', 'esp32', 'en')
|
||||
|
||||
docs_to_build = "esp32_page.rst"
|
||||
docs_to_build = 'esp32_page.rst'
|
||||
|
||||
self.assertFalse(builder.build(["-i", docs_to_build]))
|
||||
self.assertFalse(builder.build(['-i', docs_to_build]))
|
||||
|
||||
# Check that we only built the input docs
|
||||
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))
|
||||
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))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
from tempfile import TemporaryDirectory
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from sphinx.util import tags
|
||||
|
||||
@@ -14,9 +14,7 @@ except ImportError:
|
||||
sys.path.append('..')
|
||||
from idf_extensions import exclude_docs
|
||||
|
||||
from idf_extensions import format_idf_target
|
||||
from idf_extensions import gen_idf_tools_links
|
||||
from idf_extensions import link_roles
|
||||
from idf_extensions import format_idf_target, gen_idf_tools_links, link_roles
|
||||
|
||||
|
||||
class TestFormatIdfTarget(unittest.TestCase):
|
||||
@@ -30,14 +28,14 @@ class TestFormatIdfTarget(unittest.TestCase):
|
||||
|
||||
def test_add_subs(self):
|
||||
|
||||
self.assertEqual(self.str_sub.substitute_strings['{IDF_TARGET_NAME}'], "ESP32")
|
||||
self.assertEqual(self.str_sub.substitute_strings['{IDF_TARGET_PATH_NAME}'], "esp32")
|
||||
self.assertEqual(self.str_sub.substitute_strings['{IDF_TARGET_TOOLCHAIN_NAME}'], "esp32")
|
||||
self.assertEqual(self.str_sub.substitute_strings['{IDF_TARGET_CFG_PREFIX}'], "ESP32")
|
||||
self.assertEqual(self.str_sub.substitute_strings['{IDF_TARGET_NAME}'], 'ESP32')
|
||||
self.assertEqual(self.str_sub.substitute_strings['{IDF_TARGET_PATH_NAME}'], 'esp32')
|
||||
self.assertEqual(self.str_sub.substitute_strings['{IDF_TARGET_TOOLCHAIN_NAME}'], 'esp32')
|
||||
self.assertEqual(self.str_sub.substitute_strings['{IDF_TARGET_CFG_PREFIX}'], 'ESP32')
|
||||
self.assertEqual(self.str_sub.substitute_strings['{IDF_TARGET_TRM_EN_URL}'],
|
||||
"https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf")
|
||||
'https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf')
|
||||
self.assertEqual(self.str_sub.substitute_strings['{IDF_TARGET_TRM_CN_URL}'],
|
||||
"https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_cn.pdf")
|
||||
'https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_cn.pdf')
|
||||
|
||||
def test_sub(self):
|
||||
content = ('This is a {IDF_TARGET_NAME}, with {IDF_TARGET_PATH_NAME}/soc.c, compiled with '
|
||||
@@ -54,14 +52,14 @@ class TestFormatIdfTarget(unittest.TestCase):
|
||||
content = ('{IDF_TARGET_TX_PIN:default="IO3", esp32="IO4", esp32s2="IO5"}'
|
||||
'The {IDF_TARGET_NAME} UART {IDF_TARGET_TX_PIN} uses for TX')
|
||||
|
||||
expected = "The ESP32 UART IO4 uses for TX"
|
||||
expected = 'The ESP32 UART IO4 uses for TX'
|
||||
self.assertEqual(self.str_sub.substitute(content), expected)
|
||||
|
||||
def test_local_sub_default(self):
|
||||
content = ('{IDF_TARGET_TX_PIN:default="IO3", esp32s2="IO5"}'
|
||||
'The {IDF_TARGET_NAME} UART {IDF_TARGET_TX_PIN} uses for TX')
|
||||
|
||||
expected = "The ESP32 UART IO3 uses for TX"
|
||||
expected = 'The ESP32 UART IO3 uses for TX'
|
||||
self.assertEqual(self.str_sub.substitute(content), expected)
|
||||
|
||||
def test_local_sub_no_default(self):
|
||||
@@ -76,12 +74,12 @@ class TestExclude(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.app = MagicMock()
|
||||
self.app.tags = tags.Tags()
|
||||
self.app.config.conditional_include_dict = {"esp32":["esp32.rst", "bt.rst"], "esp32s2":["esp32s2.rst"]}
|
||||
self.app.config.conditional_include_dict = {'esp32':['esp32.rst', 'bt.rst'], 'esp32s2':['esp32s2.rst']}
|
||||
self.app.config.docs_to_build = None
|
||||
self.app.config.exclude_patterns = []
|
||||
|
||||
def test_update_exclude_pattern(self):
|
||||
self.app.tags.add("esp32")
|
||||
self.app.tags.add('esp32')
|
||||
exclude_docs.update_exclude_patterns(self.app, self.app.config)
|
||||
docs_to_build = set(self.app.config.conditional_include_dict['esp32'])
|
||||
|
||||
@@ -92,7 +90,7 @@ class TestExclude(unittest.TestCase):
|
||||
class TestGenIDFToolLinks(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.app = MagicMock()
|
||||
self.app.config.build_dir = "_build"
|
||||
self.app.config.build_dir = '_build'
|
||||
self.app.config.idf_path = os.environ['IDF_PATH']
|
||||
|
||||
def test_gen_idf_tool_links(self):
|
||||
|
||||
Reference in New Issue
Block a user