Skip to content

Commit

Permalink
Quick 'python -m pygame.docs', more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankith committed Dec 26, 2021
1 parent 6936e17 commit 7e1a6d9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 42 deletions.
41 changes: 36 additions & 5 deletions docs/__main__.py
@@ -1,7 +1,38 @@
# python -m pygame.docs

try:
import util
except ModuleNotFoundError:
import docs.util as util
util.open_docs()
import os
import webbrowser
from urllib.parse import quote, urlunparse


def _iterpath(path):
path, last = os.path.split(path)
if last:
for p in _iterpath(path):
yield p
yield last


# for test suite to confirm pygame built with local docs
def has_local_docs():
pkg_dir = os.path.dirname(os.path.abspath(__file__))
main_page = os.path.join(pkg_dir, "generated", "index.html")
return os.path.exists(main_page)


def open_docs():
pkg_dir = os.path.dirname(os.path.abspath(__file__))
main_page = os.path.join(pkg_dir, "generated", "index.html")
if os.path.exists(main_page):
url_path = quote("/".join(_iterpath(main_page)))
drive, rest = os.path.splitdrive(__file__)
if drive:
url_path = "%s/%s" % (drive, url_path)
url = urlunparse(("file", "", url_path, "", "", ""))
else:
url = "https://www.pygame.org/docs/"
webbrowser.open(url)


if __name__ == "__main__":
open_docs()
31 changes: 0 additions & 31 deletions docs/util.py

This file was deleted.

30 changes: 24 additions & 6 deletions test/docs_test.py
@@ -1,16 +1,34 @@
import unittest
import pygame

import os
import subprocess
import sys
import unittest


class DocsIncludedTest(unittest.TestCase):
def test_doc_import_works(self):
from pygame.docs.__main__ import has_local_docs, open_docs

@unittest.skipIf("CI" not in os.environ, "Docs not required for local builds")
def test_docs_included(self):
from pygame import docs
from pygame.docs import util
from pygame.docs.__main__ import has_local_docs

self.assertTrue(has_local_docs())

self.assertTrue(util.has_local_docs())
@unittest.skipIf("CI" not in os.environ, "Docs not required for local builds")
def test_docs_command(self):
try:
subprocess.run(
[sys.executable, "-m", "pygame.docs"],
timeout=5,
# check ensures an exception is raised when the process fails
check=True,
# pipe stdout/stderr so that they don't clutter main stdout
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
except subprocess.TimeoutExpired:
# timeout errors are not an issue
pass


if __name__ == "__main__":
Expand Down

0 comments on commit 7e1a6d9

Please sign in to comment.