mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00

* delete package ptk; rename ptk2 to ptk_shell.; leave ptk2 as alias for ptk_shell. * SHELL_TYPE "prompt_toolkit" only; remove ptk1 specific behavior. * Doc updates: eliminate reference to prompt-toolkit < 2.0 * update requirements files ptk>=2; test shell_style="none" * fix ptk2 stub per code review * Add ptk2 to list of packages to install.
80 lines
1.6 KiB
Python
80 lines
1.6 KiB
Python
"""xontrib tests, such as they are"""
|
|
import sys
|
|
import pytest
|
|
from xonsh.xontribs import xontrib_metadata, xontrib_context
|
|
|
|
|
|
def test_load_xontrib_metadata():
|
|
# Simply tests that the xontribs JSON files isn't malformed.
|
|
xontrib_metadata()
|
|
|
|
|
|
@pytest.fixture
|
|
def tmpmod(tmpdir):
|
|
"""
|
|
Same as tmpdir but also adds/removes it to the front of sys.path.
|
|
|
|
Also cleans out any modules loaded as part of the test.
|
|
"""
|
|
sys.path.insert(0, str(tmpdir))
|
|
loadedmods = set(sys.modules.keys())
|
|
try:
|
|
yield tmpdir
|
|
finally:
|
|
del sys.path[0]
|
|
newmods = set(sys.modules.keys()) - loadedmods
|
|
for m in newmods:
|
|
del sys.modules[m]
|
|
|
|
|
|
def test_noall(tmpmod):
|
|
"""
|
|
Tests what get's exported from a module without __all__
|
|
"""
|
|
|
|
with tmpmod.mkdir("xontrib").join("spameggs.py").open("w") as x:
|
|
x.write(
|
|
"""
|
|
spam = 1
|
|
eggs = 2
|
|
_foobar = 3
|
|
"""
|
|
)
|
|
|
|
ctx = xontrib_context("spameggs")
|
|
assert ctx == {"spam": 1, "eggs": 2}
|
|
|
|
|
|
def test_withall(tmpmod):
|
|
"""
|
|
Tests what get's exported from a module with __all__
|
|
"""
|
|
|
|
with tmpmod.mkdir("xontrib").join("spameggs.py").open("w") as x:
|
|
x.write(
|
|
"""
|
|
__all__ = 'spam', '_foobar'
|
|
spam = 1
|
|
eggs = 2
|
|
_foobar = 3
|
|
"""
|
|
)
|
|
|
|
ctx = xontrib_context("spameggs")
|
|
assert ctx == {"spam": 1, "_foobar": 3}
|
|
|
|
|
|
def test_xshxontrib(tmpmod):
|
|
"""
|
|
Test that .xsh xontribs are loadable
|
|
"""
|
|
with tmpmod.mkdir("xontrib").join("script.xsh").open("w") as x:
|
|
x.write(
|
|
"""
|
|
hello = 'world'
|
|
"""
|
|
)
|
|
|
|
ctx = xontrib_context("script")
|
|
assert ctx == {"hello": "world"}
|
|
|