parent
1b7b06255a
commit
57582c2501
@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import http.server
|
||||
import multiprocessing
|
||||
import os
|
||||
import posixpath
|
||||
import time
|
||||
import urllib
|
||||
import webbrowser
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
ROOT = Path(__file__).parent.parent.resolve()
|
||||
TEST_RESULT_PATH = ROOT / "tests" / "ui_tests" / "reporting" / "reports" / "test"
|
||||
|
||||
|
||||
class NoCacheRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||
def end_headers(self):
|
||||
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
self.send_header("Pragma", "no-cache")
|
||||
self.send_header("Expires", "0")
|
||||
return super().end_headers()
|
||||
|
||||
def log_message(self, format, *args):
|
||||
pass
|
||||
|
||||
def translate_path(self, path):
|
||||
# XXX
|
||||
# Copy-pasted from Python 3.8 BaseHTTPRequestHandler so that we can inject
|
||||
# the `directory` parameter.
|
||||
# Otherwise, to keep compatible with 3.6, we'd need to mess with CWD. Which is
|
||||
# unstable when we expect it to be erased and recreated under us.
|
||||
path = path.split("?", 1)[0]
|
||||
path = path.split("#", 1)[0]
|
||||
# Don't forget explicit trailing slash when normalizing. Issue17324
|
||||
trailing_slash = path.rstrip().endswith("/")
|
||||
try:
|
||||
path = urllib.parse.unquote(path, errors="surrogatepass")
|
||||
except UnicodeDecodeError:
|
||||
path = urllib.parse.unquote(path)
|
||||
path = posixpath.normpath(path)
|
||||
words = path.split("/")
|
||||
words = filter(None, words)
|
||||
path = str(TEST_RESULT_PATH) # XXX this is the only modified line
|
||||
for word in words:
|
||||
if os.path.dirname(word) or word in (os.curdir, os.pardir):
|
||||
# Ignore components that are not a simple file/directory name
|
||||
continue
|
||||
path = os.path.join(path, word)
|
||||
if trailing_slash:
|
||||
path += "/"
|
||||
return path
|
||||
|
||||
|
||||
def launch_http_server(port):
|
||||
http.server.test(HandlerClass=NoCacheRequestHandler, bind="localhost", port=port)
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.option("-p", "--port", type=int, default=8000)
|
||||
def main(port):
|
||||
httpd = multiprocessing.Process(target=launch_http_server, args=(port,))
|
||||
httpd.start()
|
||||
time.sleep(0.5)
|
||||
webbrowser.open(f"http://localhost:{port}/")
|
||||
httpd.join()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -0,0 +1,53 @@
|
||||
.novisit a:visited {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
tr.ok a, tr.ok a:visited {
|
||||
color: grey;
|
||||
}
|
||||
|
||||
tr.bad a, tr.bad a:visited {
|
||||
color: darkred;
|
||||
}
|
||||
|
||||
#markbox {
|
||||
position: fixed;
|
||||
top: 50px;
|
||||
right: 5px;
|
||||
width: 300px;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
#markbox #buttons {
|
||||
display: flex;
|
||||
justify-content: space-evenly;
|
||||
}
|
||||
|
||||
#markbox button {
|
||||
border: 3px solid;
|
||||
font-size: 20pt;
|
||||
padding: 1em;
|
||||
background: white;
|
||||
}
|
||||
|
||||
#markbox #mark-ok {
|
||||
color: green;
|
||||
border-color: darkgreen;
|
||||
}
|
||||
|
||||
#markbox #mark-ok:hover {
|
||||
border-color: lightgreen;
|
||||
}
|
||||
|
||||
#markbox #mark-bad {
|
||||
color: darkred;
|
||||
border-color: darkred;
|
||||
}
|
||||
|
||||
#markbox #mark-bad:hover {
|
||||
border-color: red;
|
||||
}
|
||||
|
||||
.script-hidden {
|
||||
display: none;
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
|
||||
|
||||
function refreshMarkStates() {
|
||||
for (let tr of document.body.querySelectorAll("tr[data-actual-hash]")) {
|
||||
let a = tr.querySelector("a")
|
||||
let mark = window.localStorage.getItem(a.href)
|
||||
tr.className = mark || ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function markState(state) {
|
||||
window.localStorage.setItem(window.location.href, state)
|
||||
if (window.nextHref) {
|
||||
window.location.assign(window.nextHref)
|
||||
} else {
|
||||
window.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function resetState(whichState) {
|
||||
function shouldReset(value) {
|
||||
if (value == whichState) return true
|
||||
if (whichState != "all") return false
|
||||
return (value == "bad" || value == "ok")
|
||||
}
|
||||
|
||||
let keysToReset = []
|
||||
|
||||
for (let i = 0; i < window.localStorage.length; ++i) {
|
||||
let key = window.localStorage.key(i)
|
||||
let value = window.localStorage.getItem(key)
|
||||
if (shouldReset(value)) keysToReset.push(key)
|
||||
}
|
||||
|
||||
for (let key of keysToReset) {
|
||||
window.localStorage.removeItem(key)
|
||||
}
|
||||
|
||||
refreshMarkStates()
|
||||
}
|
||||
|
||||
|
||||
function findNextForHref(doc, href) {
|
||||
let foundIt = false;
|
||||
for (let tr of doc.body.querySelectorAll("tr")) {
|
||||
if (!tr.dataset.actualHash) continue
|
||||
let a = tr.querySelector("a")
|
||||
if (!a) continue
|
||||
if (foundIt) return a.href
|
||||
else if (a.href == href) foundIt = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function openLink(ev) {
|
||||
if (ev.button == 2) {
|
||||
// let right click through
|
||||
return true;
|
||||
}
|
||||
|
||||
// capture other clicks
|
||||
ev.preventDefault()
|
||||
let href = ev.target.href
|
||||
let newWindow = window.open(href)
|
||||
newWindow
|
||||
}
|
||||
|
||||
|
||||
function onLoadIndex() {
|
||||
document.getElementById("file-hint").hidden = true
|
||||
|
||||
for (let a of document.body.querySelectorAll("a[href]")) {
|
||||
a.onclick = openLink
|
||||
a.onauxclick = openLink
|
||||
}
|
||||
|
||||
document.body.classList.add("novisit")
|
||||
|
||||
window.onstorage = refreshMarkStates
|
||||
refreshMarkStates()
|
||||
}
|
||||
|
||||
|
||||
function onLoadTestCase() {
|
||||
if (window.opener) {
|
||||
window.nextHref = findNextForHref(window.opener.document, window.location.href)
|
||||
if (window.nextHref) {
|
||||
markbox = document.getElementById("markbox")
|
||||
par = document.createElement("p")
|
||||
par.append("and proceed to ")
|
||||
a = document.createElement("a")
|
||||
a.append("next case")
|
||||
a.href = window.nextHref
|
||||
a.onclick = ev => {
|
||||
console.log("on click")
|
||||
ev.preventDefault()
|
||||
window.location.assign(window.nextHref)
|
||||
}
|
||||
|
||||
par.append(a)
|
||||
markbox.append(par)
|
||||
}
|
||||
} else {
|
||||
window.nextHref = null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function onLoad() {
|
||||
if (window.location.protocol == "file") return
|
||||
|
||||
for (let elem of document.getElementsByClassName("script-hidden")) {
|
||||
elem.classList.remove("script-hidden")
|
||||
}
|
||||
|
||||
if (document.body.dataset.index) {
|
||||
onLoadIndex()
|
||||
} else {
|
||||
onLoadTestCase()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
window.onload = onLoad
|
Loading…
Reference in new issue