def test_serve_threads(monkeypatch, tmpdir): def check_threads(app, host, port, threads, max_request_body_size): assert threads == 100 monkeypatch.setattr("waitress.serve", check_threads) from devpi_server.main import main main(["devpi-server", "--threads", "100"])
def test_serve_max_body(monkeypatch, tmpdir): def check_max_body(app, host, port, threads, max_request_body_size): assert max_request_body_size == 42 monkeypatch.setattr("waitress.serve", check_max_body) from devpi_server.main import main main(["devpi-server", "--max-request-body-size", "42"])
def test_export_import(tmpdir, capfd, monkeypatch, use_option): from devpi_server.importexport import import_ from devpi_server.init import init from devpi_server.main import main monkeypatch.setattr("devpi_server.main.configure_logging", lambda a: None) clean = tmpdir.join("clean").ensure(dir=True) if use_option: ret = main( argv=["devpi-server", "--init", "--serverdir", clean.strpath]) else: ret = init(argv=["devpi-init", "--serverdir", clean.strpath]) assert ret == 0 export = tmpdir.join("export") ret = main([ "devpi-server", "--serverdir", clean.strpath, "--export", export.strpath ]) assert ret == 0 import_dir = tmpdir.join("import") if use_option: ret = main(argv=[ "devpi-server", "--serverdir", import_dir.strpath, "--no-events", "--import", export.strpath ]) else: ret = import_(argv=[ "devpi-import", "--serverdir", import_dir.strpath, "--no-events", export.strpath ]) assert ret == 0 out, err = capfd.readouterr() assert os.listdir(clean.strpath) == os.listdir(import_dir.strpath) assert 'import_all: importing finished' in out assert err == ''
def test_server_commands(tmpdir, monkeypatch): monkeypatch.setenv("DEVPI_SERVERDIR", tmpdir) main(["devpi-server", "--start", "--port=3499"]) try: main(["devpi-server", "--status"]) main(["devpi-server", "--log"]) finally: main(["devpi-server", "--stop"])
def test_server_commands(tmpdir, monkeypatch): monkeypatch.setenv("DEVPI_SERVERDIR", tmpdir) monkeypatch.setattr(sys, "argv", [str(py.path.local.sysfind("devpi-server"))]) main(["devpi-server", "--start", "--port=3499"]) try: main(["devpi-server", "--status"]) main(["devpi-server", "--log"]) finally: main(["devpi-server", "--stop"])
def devpi(server_dir, args): from devpi_server.main import main from _pytest.monkeypatch import MonkeyPatch from _pytest.pytester import RunResult m = MonkeyPatch() m.setenv("DEVPI_SERVERDIR", server_dir) m.setattr("sys.argv", [devpiserver]) cap = py.io.StdCaptureFD() cap.startall() now = py.std.time.time() try: main(args) finally: m.undo() out, err = cap.reset() del cap return RunResult( 0, out.split("\n"), err.split("\n"), py.std.time.time() - now)
def test_export_empty_serverdir(tmpdir, capfd, monkeypatch): from devpi_server.main import main empty = tmpdir.join("empty").ensure(dir=True) export = tmpdir.join("export") monkeypatch.setattr("devpi_server.main.configure_logging", lambda a: None) ret = main([ "devpi-server", "--serverdir", empty.strpath, "--export", export.strpath ]) out, err = capfd.readouterr() assert empty.listdir() == [] assert ret == 1 assert out == '' assert ("The path '%s' contains no devpi-server data" % empty) in err
def test_server_commands(tmpdir, monkeypatch): monkeypatch.setenv("DEVPISERVER_SERVERDIR", tmpdir.strpath) monkeypatch.setattr(sys, "argv", [str(py.path.local.sysfind("devpi-server"))]) if sys.platform == "win32": # Windows strips the "exe" from the first argument of sys.argv # The first entry in sys.path contains the executable path monkeypatch.setattr(sys, "path", [sys.argv[0]] + sys.path) monkeypatch.setattr(sys, "argv", [sys.argv[0][:-4]]) port = get_open_port('localhost') portopt = "--port=" + str(port) main(["devpi-server", "--init", "--start", portopt]) try: main(["devpi-server", "--status"]) main(["devpi-server", "--log"]) # make sure we can't start a server if one is already running with pytest.raises(SystemExit): main(["devpi-server", "--start", portopt]) finally: main(["devpi-server", "--stop"])
def test_export_import_no_root_pypi(tmpdir, capfd, monkeypatch): from devpi_server.main import main monkeypatch.setattr("devpi_server.main.configure_logging", lambda a: None) clean = tmpdir.join("clean").ensure(dir=True) ret = main([ "devpi-server", "--serverdir", clean.strpath, "--no-root-pypi", "--init" ]) assert ret == 0 export = tmpdir.join("export") ret = main([ "devpi-server", "--serverdir", clean.strpath, "--export", export.strpath ]) assert ret == 0 # first we test regular import import_ = tmpdir.join("import") ret = main([ "devpi-server", "--serverdir", import_.strpath, "--no-events", "--import", export.strpath ]) assert ret == 0 out, err = capfd.readouterr() assert os.listdir(clean.strpath) == os.listdir(import_.strpath) assert 'import_all: importing finished' in out assert err == '' # now we add --no-root-pypi import_.remove() ret = main([ "devpi-server", "--serverdir", import_.strpath, "--no-events", "--no-root-pypi", "--import", export.strpath ]) assert ret == 0 out, err = capfd.readouterr() assert os.listdir(clean.strpath) == os.listdir(import_.strpath) assert 'import_all: importing finished' in out assert err == ''
MAIN_FILE = app.__file__ fin = open(MAIN_FILE, "rt") data = fin.read() data = data.replace(f"{COED_MIRROR_URL}", f"{MIRROR_URL}") fin.close() fin = open(MAIN_FILE, "wt") fin.write(data) fin.close() # Soft Patch app._pypi_ixconfig_default["mirror_url"] = f"{MIRROR_URL}" CACHE_DIR = environ.get("CACHE_DIR", "/cache") if not path.exists(CACHE_DIR) or not listdir(CACHE_DIR): init_command = f"--init " \ f"--serverdir={CACHE_DIR}" split_print(f"[Run init] command: {init_command}") init_app(argv=init_command.split(" ")) runtime_command = f"--include-mirrored-files " \ f"--serverdir={CACHE_DIR} " \ f"--proxy-timeout=10 " \ f"--host=0.0.0.0" runtime_command = environ.get("COMMAND", runtime_command) split_print(f"[*] Run devpi command: {runtime_command}") app.main(runtime_command.split(" "))
import sys import yappi from devpi_server.main import main yappi.start() try: sys.exit(main()) finally: stats = yappi.get_func_stats() stats.print_all() import pdb ; pdb.set_trace()
def test_version(capfd): main(["devpi-server", "--version"]) out, err = capfd.readouterr() assert not err # not logging output assert devpi_server.__version__ in out.strip()