• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pyta-uoft / pyta / 14025681769

24 Mar 2025 02:00AM UTC coverage: 92.555% (-0.5%) from 93.089%
14025681769

Pull #1156

github

web-flow
Merge 81db94e44 into 477f476ea
Pull Request #1156: Integrate Watchdog for Live Code Re-Checking

191 of 217 new or added lines in 5 files covered. (88.02%)

8 existing lines in 1 file now uncovered.

3344 of 3613 relevant lines covered (92.55%)

17.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.41
/python_ta/reporters/html_server.py
1
import os
20✔
2
import sys
20✔
3
import webbrowser
20✔
4
from http.server import BaseHTTPRequestHandler, HTTPServer
20✔
5

6

7
def open_html_in_browser(html: bytes, watch: bool, port: int) -> None:
20✔
8
    """
9
    Display html in a web browser without creating a temp file.
10
    Instantiates a trivial HTTP server on the specified port (or an available port if 0 is provided)
11
    and uses the webbrowser module to open a URL to retrieve the HTML from that server.
12

13
    If watch is False, the server responds to exactly one request and then shuts down.
14
    If watch is True, the server runs indefinitely, allowing multiple requests.
15
    Adapted from: https://github.com/plotly/plotly.py/blob/master/packages/python/plotly/plotly/io/_base_renderers.py#L655
16
    """
17

18
    class RequestHandler(BaseHTTPRequestHandler):
20✔
19
        def do_GET(self):
20✔
20
            self.send_response(200)
10✔
21
            self.send_header("Content-type", "text/html")
10✔
22
            self.end_headers()
10✔
23

24
            buffer_size = 1024 * 1024
10✔
25
            for i in range(0, len(html), buffer_size):
10✔
26
                self.wfile.write(html[i : i + buffer_size])
10✔
27

28
        def log_message(self, format, *args):
20✔
29
            """Overridden so that no server logging is printed."""
30
            pass
10✔
31

32
    if watch:
20✔
UNCOV
33
        print(
×
34
            "[INFO] Your PythonTA report is being opened in your web browser.\n"
35
            "       Press Ctrl + C or stop this program to exit.",
36
            file=sys.stderr,
37
        )
UNCOV
38
        server = HTTPServer(("127.0.0.1", port), RequestHandler)
×
UNCOV
39
        webbrowser.open(f"http://127.0.0.1:{server.server_port}", new=2)
×
UNCOV
40
        try:
×
UNCOV
41
            server.serve_forever()
×
UNCOV
42
        except KeyboardInterrupt:
×
UNCOV
43
            print("\nShutting down the PythonTA server.")
×
UNCOV
44
            server.shutdown()
×
45
    else:
46
        server = HTTPServer(("127.0.0.1", port), RequestHandler)
20✔
47
        webbrowser.open(f"http://127.0.0.1:{server.server_port}", new=2)
20✔
48
        server.handle_request()
20✔
49
        server.server_close()
20✔
50
        print(
20✔
51
            "[INFO] Your PythonTA report is being opened in your web browser.\n"
52
            "       If it doesn't open, please add an output argument to python_ta.check_all\n"
53
            "       as follows:\n\n"
54
            "         check_all(..., output='pyta_report.html')\n\n"
55
            "       This will cause PythonTA to save the report to a file, pyta_report.html,\n"
56
            "       that you can open manually in a web browser.",
57
            file=sys.stderr,
58
        )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc