这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions tests/conda_env/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
from os.path import dirname, join


def support_file(filename, remote=False):
# remote=True is only used in two places, in tests.conda_env.test_create


def support_file(filename, port=None, remote=False):
if remote:
return f"https://raw.githubusercontent.com/conda/conda/main/tests/conda_env/support/{filename}"
assert port is not None
return f"http://127.0.0.1:{port}/{filename}"
return join(dirname(__file__), "support", filename)
2 changes: 1 addition & 1 deletion tests/conda_env/support/example/environment_pinned.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: test
dependencies:
- flask==0.12.2
- flask==2.0.2
variables:
FIXED: fixed
CHANGES: original_value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: test
dependencies:
- flask==1.0.2
- flask==2.0.3
variables:
FIXED: fixed
CHANGES: updated_value
Expand Down
267 changes: 166 additions & 101 deletions tests/conda_env/test_create.py

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
from pathlib import Path
import subprocess
from pathlib import Path

import pytest

from . import http_test_server

pytest_plugins = (
# Add testing fixtures and internal pytest plugins here
"conda.testing.gateways.fixtures",
Expand Down Expand Up @@ -38,6 +40,24 @@ def clear_cache():
SubdirData._cache_.clear()


@pytest.fixture(scope="session")
def support_file_server():
"""
Open a local web server to test remote support files.
"""
base = Path(__file__).parents[0] / "conda_env" / "support"
http = http_test_server.run_test_server(str(base))
yield http
# shutdown is checked at a polling interval, or the daemon thread will shut
# down when the test suite exits.
http.shutdown()


@pytest.fixture
def support_file_server_port(support_file_server):
return support_file_server.socket.getsockname()[1]


@pytest.fixture
def clear_cuda_version():
from conda.plugins.virtual_packages import cuda
Expand Down
51 changes: 51 additions & 0 deletions tests/http_test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
"""
Local test server based on http.server
"""

import contextlib
import http.server
import queue
import socket
import threading


def run_test_server(directory: str) -> http.server.ThreadingHTTPServer:
"""
Run a test server on a random port. Inspect returned server to get port,
shutdown etc.
"""

class DualStackServer(http.server.ThreadingHTTPServer):
def server_bind(self):
# suppress exception when protocol is IPv4
with contextlib.suppress(Exception):
self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
return super().server_bind()

def finish_request(self, request, client_address):
self.RequestHandlerClass(request, client_address, self, directory=directory)

def start_server(queue):

with DualStackServer(("127.0.0.1", 0), http.server.SimpleHTTPRequestHandler) as httpd:
host, port = httpd.socket.getsockname()[:2]
queue.put(httpd)
url_host = f"[{host}]" if ":" in host else host
print(f"Serving HTTP on {host} port {port} " f"(http://{url_host}:{port}/) ...")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nKeyboard interrupt received, exiting.")

started = queue.Queue()

threading.Thread(target=start_server, args=(started,), daemon=True).start()

return started.get(timeout=1)


if __name__ == "__main__":
server = run_test_server(directory=".")
print(server)
6 changes: 3 additions & 3 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,10 +1115,10 @@ def test_clone_offline_multichannel_with_untracked(self):
"CONDA_DLL_SEARCH_MODIFICATION_ENABLE": "1",
}, stack_callback=conda_tests_ctxt_mgmt_def_pol):
# The flask install will use this version of Python. That is then used to compile flask's pycs.
flask_python = '3.6'
with make_temp_env("python=3.7", use_restricted_unicode=True) as prefix:
flask_python = '3.8' # oldest available for osx-arm64
with make_temp_env("python=3.9", use_restricted_unicode=True) as prefix:

run_command(Commands.CONFIG, prefix, "--add", "channels", "https://repo.anaconda.com/pkgs/free")
run_command(Commands.CONFIG, prefix, "--add", "channels", "https://repo.anaconda.com/pkgs/main")
run_command(Commands.CONFIG, prefix, "--remove", "channels", "defaults")

run_command(Commands.INSTALL, prefix, "-c", "conda-test", "flask", "python=" + flask_python)
Expand Down