2016-05-24 01:54:18 -04:00
|
|
|
"""xontrib tests, such as they are"""
|
2016-08-03 00:33:39 -04:00
|
|
|
import pytest
|
|
|
|
from xonsh.xontribs import xontrib_metadata, xontrib_context
|
|
|
|
import sys
|
2016-05-24 01:54:18 -04:00
|
|
|
|
|
|
|
def test_load_xontrib_metadata():
|
|
|
|
# Simply tests that the xontribs JSON files isn't malformed.
|
2016-08-03 00:33:39 -04:00
|
|
|
xontrib_metadata()
|
|
|
|
|
|
|
|
@pytest.yield_fixture
|
|
|
|
def tmpmod(tmpdir):
|
|
|
|
"""
|
2016-08-03 00:42:36 -04:00
|
|
|
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.
|
2016-08-03 00:33:39 -04:00
|
|
|
"""
|
|
|
|
sys.path.insert(0, str(tmpdir))
|
2016-08-03 00:42:36 -04:00
|
|
|
loadedmods = set(sys.modules.keys())
|
2016-08-03 00:33:39 -04:00
|
|
|
try:
|
|
|
|
yield tmpdir
|
|
|
|
finally:
|
|
|
|
del sys.path[0]
|
2016-08-03 00:42:36 -04:00
|
|
|
newmods = set(sys.modules.keys()) - loadedmods
|
|
|
|
for m in newmods:
|
|
|
|
del sys.modules[m]
|
2016-08-03 00:33:39 -04:00
|
|
|
|
|
|
|
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}
|