diff --git a/.gitignore b/.gitignore index bd58829e..ce14d2cd 100644 --- a/.gitignore +++ b/.gitignore @@ -134,6 +134,8 @@ dmypy.json **/temp/ **/tmp_result/ +.stestr/ + # Some people build submodule because of not understanding git basics doc-exports diff --git a/.stestr.conf b/.stestr.conf new file mode 100644 index 00000000..7c6f6ed2 --- /dev/null +++ b/.stestr.conf @@ -0,0 +1,3 @@ +[DEFAULT] +test_path=./otc_doc_convertor/tests/unit +top_dir=./ diff --git a/otc_doc_convertor/convertor.py b/otc_doc_convertor/convertor.py index 3a94d7ec..11aa39d3 100644 --- a/otc_doc_convertor/convertor.py +++ b/otc_doc_convertor/convertor.py @@ -109,7 +109,7 @@ class OTCDocConvertor: "Cannot find string for rawization anymore" ) - def streamline_html(self, soup, file_name): + def streamline_html(self, soup, file_name, args=None): # Drop eventual header duplicated anchors fname = file_name.replace(".html", "").lower() page_anchors = set() @@ -227,7 +227,7 @@ class OTCDocConvertor: if th.p.strong: th.p.strong.unwrap() - if self.args.improve_table_headers: + if args and args.improve_table_headers: # Add spaces around "/" for th in soup.body.find_all("th"): if hasattr(th, "p") and th.p.string: @@ -562,7 +562,7 @@ class OTCDocConvertor: content = re.sub(r"≤", "<=", content) content = re.sub(r"≥", ">=", content) soup = bs4.BeautifulSoup(content, "lxml") - proc = self.streamline_html(soup, f.name) + proc = self.streamline_html(soup, f.name, self.args) for lnk in proc.find_all("a"): href = lnk.get("href") diff --git a/otc_doc_convertor/tests/unit/__init__.py b/otc_doc_convertor/tests/unit/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/otc_doc_convertor/tests/unit/test_convertor.py b/otc_doc_convertor/tests/unit/test_convertor.py new file mode 100644 index 00000000..9304d6e5 --- /dev/null +++ b/otc_doc_convertor/tests/unit/test_convertor.py @@ -0,0 +1,165 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +from unittest import TestCase +import bs4 + +from otc_doc_convertor import convertor + + +class TestConvertor(TestCase): + def setUp(self): + self.convertor = convertor.OTCDocConvertor() + + def test_streamline_html_escape_1(self): + test_data = """ +
s3:*
s3:*
If the VPC, subnet, and security group are displayed in the DB + instance list, you need to configure vpc:*:get and + vpc:*:list.
If the VPC, subnet, and security group are displayed in the DB + instance list, you need to configure vpc:``*``:get and + vpc:``*``:list.
cce:kubernetes:*
+ """ + expected = """ +cce:kubernetes:*
+ """ + soup = bs4.BeautifulSoup(test_data, 'lxml') + res = self.convertor.streamline_html(soup, "dummy") + self.assertEqual(str(res.find('p')), expected.strip()) + + def test_streamline_html_escape_9(self): + test_data = """ +/:*?"<>|\\;&,\'`!{}[]$%+
ipFilterRules=allow:ip:127.*, allow:name:localhost, deny:ip:*
+ """ # noqa + expected = """ +ipFilterRules=allow:ip:127.*, allow:name:localhost, deny:ip:*
+ """ # noqa + soup = bs4.BeautifulSoup(test_data, 'lxml') + res = self.convertor.streamline_html(soup, "dummy") + self.assertEqual( + str(res.find('p')), + expected.strip(), + ) + + def test_streamline_html_escape_11(self): + test_data = """ +If the VPC, subnet, and security group are displayed in the DB instance list, you need to configure vpc:*:get and vpc:*:list.
If the VPC, subnet, and security group are displayed in the DB instance list, you need to configure vpc:``*``:get and vpc:``*``:list.