def dumpsphinx(url): """Dumps all the objects given an sphinx catalog/inventory URL. This command is useful when you are struggling to do proper links from your documentation. """ intersphinx.inspect_main([url])
def test_inspect_main_file(capsys, tempdir): """inspect_main interface, with file argument""" inv_file = tempdir / 'inventory' inv_file.write_bytes(inventory_v2) inspect_main([str(inv_file)]) stdout, stderr = capsys.readouterr() assert stdout.startswith("c:function\n") assert stderr == ""
def test_inspect_main_noargs(capsys): """inspect_main interface, without arguments""" with pytest.raises(SystemExit): inspect_main([]) expected = ("Print out an inventory file.\n" "Error: must specify local path or URL to an inventory file.") stdout, stderr = capsys.readouterr() assert stdout == "" assert stderr == expected + "\n"
def test_inspect_main_file(capsys, tempdir): """inspect_main interface, with file argument""" inv_file = tempdir / 'inventory' inv_file.write_bytes(inventory_v2) inspect_main([str(inv_file)]) stdout, stderr = capsys.readouterr() assert stdout.startswith("c:function\n") assert stderr == ""
def test_inspect_main_noargs(capsys): """inspect_main interface, without arguments""" with pytest.raises(SystemExit): inspect_main([]) expected = ( "Print out an inventory file.\n" "Error: must specify local path or URL to an inventory file." ) stdout, stderr = capsys.readouterr() assert stdout == "" assert stderr == expected + "\n"
def main(*args): if not args: args = sys.argv[1:] if not args: args = ['--help'] parser = configure_parser() args = parser.parse_args(args) # either PyQt4 or PyQt5 package = u'PyQt4' if args.pyqt == 'pyqt4' else u'PyQt5' # the URI of the original objects.inv file pyqt_uri = u'http://pyqt.sourceforge.net/Docs/' + package + u'/' # the filename to use to save the original objects.inv file original_inv = package.lower() + u'-original-objects.inv' original_txt = package.lower() + u'-original-objects.txt' # the filename to use to save the Sphinx-compatible object.inv file modified_inv = package.lower() + u'-modified-objects.inv' modified_txt = package.lower() + u'-modified-objects.txt' create_modified_inv(package, original_inv, modified_inv, pyqt_uri, args.use_qt_uri) print('\nCreated:') print(' ' + original_inv) print(' ' + original_txt) print(' ' + modified_inv) print(' ' + modified_txt) # redirect the print() statements in the inspect_main() function to a file sys.stdout = codecs.open(original_txt, 'wb', encoding='utf-8') inspect_main([original_inv]) sys.stdout.close() # if the following succeeds without raising an exception then Sphinx is # able to read the pyqt#-modified-objects.inv file that was just created sys.stdout = codecs.open(modified_txt, 'wb', encoding='utf-8') inspect_main([modified_inv]) sys.stdout.close() sys.exit(0)
def test_sphinx_object_inventory_version(capsys): """ The Sphinx inventory is generated with the project version in the header. """ # The pydoctor own inventory. apidocs_inv = BASE_DIR / 'api' / 'objects.inv' with open(apidocs_inv, 'rb') as stream: page = stream.read() assert page.startswith(b'# Sphinx inventory version 2\n' b'# Project: pydoctor\n' b'# Version: ' + __version__.encode() + b'\n'), page # Check that inventory can be parsed by Sphinx own extension. inspect_main([str(apidocs_inv)]) out, err = capsys.readouterr() assert '' == err assert 'pydoctor.driver.main' in out, out
def test_inspect_main_url(capsys): """inspect_main interface, with url argument""" class InventoryHandler(http.server.BaseHTTPRequestHandler): def do_GET(self): self.send_response(200, "OK") self.end_headers() self.wfile.write(inventory_v2) def log_message(*args, **kwargs): # Silenced. pass url = 'http://localhost:7777/' + INVENTORY_FILENAME with http_server(InventoryHandler): inspect_main([url]) stdout, stderr = capsys.readouterr() assert stdout.startswith("c:function\n") assert stderr == ""
def main(): create_modified_inv() print('Created:') print(' ' + original_inv) print(' ' + original_txt) print(' ' + modified_inv) print(' ' + modified_txt) # redirect the print() statements in the inspect_main() function to a file sys.stdout = codecs.open(original_txt, 'wb', encoding='utf-8') inspect_main([original_inv]) sys.stdout.close() # if the following succeeds without raising an exception then Sphinx is # able to read the pyqt#-modified-objects.inv file that was just created sys.stdout = codecs.open(modified_txt, 'wb', encoding='utf-8') inspect_main([modified_inv]) sys.stdout.close() sys.exit(0)
def test_inspect_main_url(fake_get, capsys): """inspect_main interface, with url argument""" raw = BytesIO(inventory_v2) real_read = raw.read def fake_read(*args, **kwargs): return real_read() raw.read = fake_read url = 'http://hostname/' + INVENTORY_FILENAME resp = requests.Response() resp.status_code = 200 resp.url = url resp.raw = raw fake_get.return_value = resp inspect_main([url]) stdout, stderr = capsys.readouterr() assert stdout.startswith("c:function\n") assert stderr == ""
def test_inspect_main_url(fake_get, capsys): """inspect_main interface, with url argument""" raw = BytesIO(inventory_v2) real_read = raw.read def fake_read(*args, **kwargs): return real_read() raw.read = fake_read url = 'http://hostname/' + INVENTORY_FILENAME resp = requests.Response() resp.status_code = 200 resp.url = url resp.raw = raw fake_get.return_value = resp inspect_main([url]) stdout, stderr = capsys.readouterr() assert stdout.startswith("c:function\n") assert stderr == ""