2015-07-11 16:13:27 +08:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
pytest_plugins = "pytester",
|
|
|
|
|
|
|
|
class TestNewAPI:
|
|
|
|
def test_config_cache_makedir(self, testdir):
|
|
|
|
testdir.makeini("[pytest]")
|
|
|
|
config = testdir.parseconfigure()
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
config.cache.makedir("key/name")
|
|
|
|
|
|
|
|
p = config.cache.makedir("name")
|
|
|
|
assert p.check()
|
|
|
|
|
|
|
|
def test_config_cache_dataerror(self, testdir):
|
|
|
|
testdir.makeini("[pytest]")
|
|
|
|
config = testdir.parseconfigure()
|
|
|
|
cache = config.cache
|
|
|
|
pytest.raises(TypeError, lambda: cache.set("key/name", cache))
|
|
|
|
config.cache.set("key/name", 0)
|
|
|
|
config.cache._getvaluepath("key/name").write("123invalid")
|
|
|
|
val = config.cache.get("key/name", -2)
|
|
|
|
assert val == -2
|
|
|
|
|
|
|
|
def test_config_cache(self, testdir):
|
|
|
|
testdir.makeconftest("""
|
|
|
|
def pytest_configure(config):
|
|
|
|
# see that we get cache information early on
|
|
|
|
assert hasattr(config, "cache")
|
|
|
|
""")
|
|
|
|
testdir.makepyfile("""
|
|
|
|
def test_session(pytestconfig):
|
|
|
|
assert hasattr(pytestconfig, "cache")
|
|
|
|
""")
|
|
|
|
result = testdir.runpytest()
|
|
|
|
assert result.ret == 0
|
|
|
|
result.stdout.fnmatch_lines(["*1 passed*"])
|
|
|
|
|
|
|
|
def XXX_test_cachefuncarg(self, testdir):
|
|
|
|
testdir.makepyfile("""
|
|
|
|
import pytest
|
|
|
|
def test_cachefuncarg(cache):
|
|
|
|
val = cache.get("some/thing", None)
|
|
|
|
assert val is None
|
|
|
|
cache.set("some/thing", [1])
|
|
|
|
pytest.raises(TypeError, lambda: cache.get("some/thing"))
|
|
|
|
val = cache.get("some/thing", [])
|
|
|
|
assert val == [1]
|
|
|
|
""")
|
|
|
|
result = testdir.runpytest()
|
|
|
|
assert result.ret == 0
|
|
|
|
result.stdout.fnmatch_lines(["*1 passed*"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cache_reportheader(testdir):
|
2015-07-24 16:05:54 +08:00
|
|
|
testdir.makepyfile("""
|
2015-07-11 16:13:27 +08:00
|
|
|
def test_hello():
|
|
|
|
pass
|
|
|
|
""")
|
|
|
|
result = testdir.runpytest("-v")
|
|
|
|
result.stdout.fnmatch_lines([
|
|
|
|
"cachedir: .cache"
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_cache_show(testdir):
|
2015-07-24 15:59:59 +08:00
|
|
|
result = testdir.runpytest("--show-cache")
|
2015-07-11 16:13:27 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
result.stdout.fnmatch_lines([
|
|
|
|
"*cache is empty*"
|
|
|
|
])
|
2015-07-24 16:05:54 +08:00
|
|
|
testdir.makeconftest("""
|
2015-07-11 16:13:27 +08:00
|
|
|
def pytest_configure(config):
|
|
|
|
config.cache.set("my/name", [1,2,3])
|
|
|
|
config.cache.set("other/some", {1:2})
|
|
|
|
dp = config.cache.makedir("mydb")
|
|
|
|
dp.ensure("hello")
|
|
|
|
dp.ensure("world")
|
|
|
|
""")
|
|
|
|
result = testdir.runpytest()
|
|
|
|
assert result.ret == 0
|
2015-07-24 15:59:59 +08:00
|
|
|
result = testdir.runpytest("--show-cache")
|
2015-07-11 16:13:27 +08:00
|
|
|
result.stdout.fnmatch_lines_random([
|
|
|
|
"*cachedir:*",
|
|
|
|
"-*cache values*-",
|
|
|
|
"*my/name contains:",
|
|
|
|
" [1, 2, 3]",
|
|
|
|
"*other/some contains*",
|
|
|
|
" {*1*: 2}",
|
|
|
|
"-*cache directories*-",
|
|
|
|
"*mydb/hello*length 0*",
|
|
|
|
"*mydb/world*length 0*",
|
|
|
|
])
|