Skip to content

Commit

Permalink
✨ supper local style #57
Browse files Browse the repository at this point in the history
  • Loading branch information
defnngj committed Jan 15, 2025
1 parent 213ef54 commit d99285c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
37 changes: 37 additions & 0 deletions XTestRunner/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os.path
import time
import shutil


class Config:
Expand Down Expand Up @@ -42,3 +44,38 @@ def inner(cls):
return cls

return inner


def static_file(is_local_style=False, report_path: str = None) -> dict:
"""
static file path
:param is_local_style:
:param report_path:
:return:
"""
if is_local_style is True:
if report_path is None:
raise FileNotFoundError("report path is null")

report_dir = os.path.dirname(report_path)
dst_static_dir = os.path.join(report_dir, "static")
root_dir = os.path.dirname(os.path.abspath(__file__))
src_static_dir = os.path.join(root_dir, "html", "static")
# copy static file
shutil.copytree(src_static_dir, dst_static_dir, dirs_exist_ok=True)
# local static file
jquery_url = echarts_url = "static/js/"
css_url = "static/css/"
png_url = "static/images/"
else:
jquery_url = "https://libs.baidu.com/jquery/2.0.0/"
echarts_url = "https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.2/"
css_url = png_url = "https://telegraph-image-cq2.pages.dev/"

static_dir = {
"jquery_url": jquery_url,
"echarts_url": echarts_url,
"css_url": css_url,
"png_url": png_url
}
return static_dir
10 changes: 5 additions & 5 deletions XTestRunner/html/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<title>{{ title }}</title>
<meta name="generator" content="XTestRunner {{ version }}"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script src="https://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.2/echarts.min.js"></script>
<link rel="stylesheet" href="https://telegraph-image-cq2.pages.dev/seldom-main.css"/>
<link rel="stylesheet" href="https://telegraph-image-cq2.pages.dev/seldom-utilities.css"/>
<link rel="icon" href="https://telegraph-image-cq2.pages.dev/XTestRunnerIcon.png" type="image/x-icon"/>
<script src="{{jquery_url}}jquery.min.js"></script>
<script src="{{echarts_url}}echarts.min.js"></script>
<link rel="stylesheet" href="{{css_url}}seldom-main.css"/>
<link rel="stylesheet" href="{{css_url}}seldom-utilities.css"/>
<link rel="icon" href="{{png_url}}XTestRunnerIcon.png" type="image/x-icon"/>
{{ stylesheet }}
</head>

Expand Down
9 changes: 8 additions & 1 deletion XTestRunner/htmlrunner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from jinja2 import Environment, FileSystemLoader
from XTestRunner.htmlrunner.result import _TestResult
from XTestRunner.htmlrunner.multi_language import language_tag
from XTestRunner.config import RunResult, Config
from XTestRunner.config import RunResult, Config, static_file
from XTestRunner.version import get_version
from XTestRunner._email import SMTP
from XTestRunner._dingtalk import DingTalk
Expand Down Expand Up @@ -154,12 +154,14 @@ def __init__(self,
rerun=0,
language="en",
logger=None,
local_style=False,
**kwargs):
self.stream = stream
self.verbosity = verbosity
self.rerun = rerun
self.run_times = 0
self.logger = logger
self.local_style = local_style
Config.language = language
if title is None:
self.title = DEFAULT_TITLE
Expand Down Expand Up @@ -322,8 +324,13 @@ def generate_report(self, test, result):
version = get_version()
heading = self._generate_heading(base, statistics)
report = self._generate_report(result)
static = static_file(self.local_style, self.stream.name)

html_content = template.render(
jquery_url=static["jquery_url"],
echarts_url=static["echarts_url"],
css_url=static["css_url"],
png_url=static["png_url"],
title=saxutils.escape(self.title),
version=version,
stylesheet=stylesheet,
Expand Down

0 comments on commit d99285c

Please sign in to comment.