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

pyta-uoft / pyta / 13618144272

02 Mar 2025 06:25PM UTC coverage: 92.07% (-0.8%) from 92.914%
13618144272

Pull #1156

github

web-flow
Merge 22378039d into 89ce63ced
Pull Request #1156: Integrate Watchdog for Live Code Re-Checking

52 of 83 new or added lines in 1 file covered. (62.65%)

8 existing lines in 1 file now uncovered.

3274 of 3556 relevant lines covered (92.07%)

17.52 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