summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/sniffio/_tests
diff options
context:
space:
mode:
authorcyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
committercyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
commit6d7ba58f880be618ade07f8ea080fe8c4bf8a896 (patch)
treeb1c931051ffcebd2bd9d61d98d6233ffa289bbce /venv/lib/python3.11/site-packages/sniffio/_tests
parent4f884c9abc32990b4061a1bb6997b4b37e58ea0b (diff)
venv
Diffstat (limited to 'venv/lib/python3.11/site-packages/sniffio/_tests')
-rw-r--r--venv/lib/python3.11/site-packages/sniffio/_tests/__init__.py0
-rw-r--r--venv/lib/python3.11/site-packages/sniffio/_tests/__pycache__/__init__.cpython-311.pycbin0 -> 198 bytes
-rw-r--r--venv/lib/python3.11/site-packages/sniffio/_tests/__pycache__/test_sniffio.cpython-311.pycbin0 -> 5070 bytes
-rw-r--r--venv/lib/python3.11/site-packages/sniffio/_tests/test_sniffio.py84
4 files changed, 84 insertions, 0 deletions
diff --git a/venv/lib/python3.11/site-packages/sniffio/_tests/__init__.py b/venv/lib/python3.11/site-packages/sniffio/_tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/sniffio/_tests/__init__.py
diff --git a/venv/lib/python3.11/site-packages/sniffio/_tests/__pycache__/__init__.cpython-311.pyc b/venv/lib/python3.11/site-packages/sniffio/_tests/__pycache__/__init__.cpython-311.pyc
new file mode 100644
index 0000000..4a8da2e
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/sniffio/_tests/__pycache__/__init__.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/sniffio/_tests/__pycache__/test_sniffio.cpython-311.pyc b/venv/lib/python3.11/site-packages/sniffio/_tests/__pycache__/test_sniffio.cpython-311.pyc
new file mode 100644
index 0000000..ea43664
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/sniffio/_tests/__pycache__/test_sniffio.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/sniffio/_tests/test_sniffio.py b/venv/lib/python3.11/site-packages/sniffio/_tests/test_sniffio.py
new file mode 100644
index 0000000..02945a9
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/sniffio/_tests/test_sniffio.py
@@ -0,0 +1,84 @@
+import os
+import sys
+
+import pytest
+
+from .. import (
+ current_async_library, AsyncLibraryNotFoundError,
+ current_async_library_cvar, thread_local
+)
+
+
+def test_basics_cvar():
+ with pytest.raises(AsyncLibraryNotFoundError):
+ current_async_library()
+
+ token = current_async_library_cvar.set("generic-lib")
+ try:
+ assert current_async_library() == "generic-lib"
+ finally:
+ current_async_library_cvar.reset(token)
+
+ with pytest.raises(AsyncLibraryNotFoundError):
+ current_async_library()
+
+
+def test_basics_tlocal():
+ with pytest.raises(AsyncLibraryNotFoundError):
+ current_async_library()
+
+ old_name, thread_local.name = thread_local.name, "generic-lib"
+ try:
+ assert current_async_library() == "generic-lib"
+ finally:
+ thread_local.name = old_name
+
+ with pytest.raises(AsyncLibraryNotFoundError):
+ current_async_library()
+
+
+def test_asyncio():
+ import asyncio
+
+ with pytest.raises(AsyncLibraryNotFoundError):
+ current_async_library()
+
+ ran = []
+
+ async def this_is_asyncio():
+ assert current_async_library() == "asyncio"
+ # Call it a second time to exercise the caching logic
+ assert current_async_library() == "asyncio"
+ ran.append(True)
+
+ asyncio.run(this_is_asyncio())
+ assert ran == [True]
+
+ with pytest.raises(AsyncLibraryNotFoundError):
+ current_async_library()
+
+
+@pytest.mark.skipif(
+ sys.version_info >= (3, 12),
+ reason=
+ "curio broken on 3.12 (https://github.com/python-trio/sniffio/pull/42)",
+)
+def test_curio():
+ import curio
+
+ with pytest.raises(AsyncLibraryNotFoundError):
+ current_async_library()
+
+ ran = []
+
+ async def this_is_curio():
+ assert current_async_library() == "curio"
+ # Call it a second time to exercise the caching logic
+ assert current_async_library() == "curio"
+ ran.append(True)
+
+ curio.run(this_is_curio)
+ assert ran == [True]
+
+ with pytest.raises(AsyncLibraryNotFoundError):
+ current_async_library()