finally cleaning up the html coverage report such that it displays properly in the DevOps tab
@@ -3,6 +3,7 @@ import os
import bs4
import io
import sys
+import shutil
COVERAGE_REPORT_DIR = 'htmlcov/'
COVERAGE_REPORT = os.path.join(COVERAGE_REPORT_DIR, 'index.html')
@@ -38,9 +39,39 @@ def embed_css_in_html_file(html_file, css_dir):
with io.open(html_file, 'w', encoding='utf-8') as f:
f.write(__str_version_handler(soup))
+def clean_index(html_file):
+ with io.open(html_file, 'r', encoding='utf-8') as f:
+ soup = bs4.BeautifulSoup(f.read(), "html.parser")
+
+ # remove all links to the files that don't exist anymore
+ for a in soup.findAll('a'):
+ a.replaceWithChildren()
+
+ # embedded CSS corrupts the sort indicator image. Javascript doesn't work in the devops display anyway. Removing the class
+ module_title = soup.find('th', class_='headerSortDown')["class"].remove('headerSortDown')
+
+ # remove input filter
+ input_filter = soup.find(id= 'filter')
+ input_filter.decompose()
+
+ # remove keyboard icon
+ keyboard_icon = soup.find(id='keyboard_icon')
+ keyboard_icon.decompose()
+
+ # write final results
+ with io.open(html_file, 'w', encoding='utf-8') as f:
+ f.write(__str_version_handler(soup))
if __name__ == '__main__':
for file in os.listdir(COVERAGE_REPORT_DIR):
- if file.endswith(".html"):
+ name, ext = os.path.splitext(os.path.basename(file.lower()))
+ if ext == ".html":
+ if name == "index":
+ print("Cleaning index in {}".format(file))
+ clean_index(os.path.join(COVERAGE_REPORT_DIR, file))
print("Embedding CSS in {}".format(file))
embed_css_in_html_file(os.path.join(COVERAGE_REPORT_DIR, file), COVERAGE_REPORT_DIR)
+ else:
+ os.remove(os.path.join(COVERAGE_REPORT_DIR, file))
+
+
