2009-12-30 05:26:03 +08:00
|
|
|
import sys, py
|
2008-08-21 22:25:24 +08:00
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
pytest_plugins = "pytest_pytester"
|
|
|
|
|
2009-12-30 05:26:03 +08:00
|
|
|
@py.test.mark.multi(name=[x for x in dir(py.cmdline) if x[0] != "_"])
|
2010-01-02 04:03:33 +08:00
|
|
|
def test_cmdmain(name, pytestconfig):
|
2009-12-30 05:26:03 +08:00
|
|
|
main = getattr(py.cmdline, name)
|
|
|
|
assert py.builtin.callable(main)
|
|
|
|
assert name[:2] == "py"
|
2010-01-02 04:03:33 +08:00
|
|
|
if pytestconfig.getvalue("toolsonpath"):
|
|
|
|
scriptname = "py." + name[2:]
|
|
|
|
assert py.path.local.sysfind(scriptname), scriptname
|
2009-12-30 05:26:03 +08:00
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
class TestPyLookup:
|
|
|
|
def test_basic(self, testdir):
|
|
|
|
p = testdir.makepyfile(hello="def x(): pass")
|
|
|
|
result = testdir.runpybin("py.lookup", "pass")
|
|
|
|
result.stdout.fnmatch_lines(
|
2008-08-21 22:25:24 +08:00
|
|
|
['%s:*def x(): pass' %(p.basename)]
|
|
|
|
)
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_search_in_filename(self, testdir):
|
|
|
|
p = testdir.makepyfile(hello="def x(): pass")
|
|
|
|
result = testdir.runpybin("py.lookup", "hello")
|
|
|
|
result.stdout.fnmatch_lines(
|
2008-08-21 22:25:24 +08:00
|
|
|
['*%s:*' %(p.basename)]
|
|
|
|
)
|
2009-09-23 10:04:25 +08:00
|
|
|
|
2009-09-30 23:59:03 +08:00
|
|
|
def test_with_explicit_path(self, testdir):
|
2009-09-23 10:04:25 +08:00
|
|
|
sub1 = testdir.mkdir("things")
|
|
|
|
sub2 = testdir.mkdir("foo")
|
|
|
|
sub1.join("pyfile.py").write("def stuff(): pass")
|
|
|
|
searched = sub2.join("other.py")
|
|
|
|
searched.write("stuff = x")
|
|
|
|
result = testdir.runpybin("py.lookup", sub2.basename, "stuff")
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
["%s:1: stuff = x" % (searched.basename,)]
|
|
|
|
)
|
2009-10-12 17:24:41 +08:00
|
|
|
|
|
|
|
class TestPyCleanup:
|
|
|
|
def test_basic(self, testdir, tmpdir):
|
|
|
|
p = tmpdir.ensure("hello.py")
|
|
|
|
result = testdir.runpybin("py.cleanup", tmpdir)
|
|
|
|
assert result.ret == 0
|
|
|
|
assert p.check()
|
|
|
|
pyc = p.new(ext='pyc')
|
|
|
|
pyc.ensure()
|
2010-02-06 05:50:41 +08:00
|
|
|
pyclass = p.new(basename=p.basename + '$py.class')
|
2009-10-12 17:24:41 +08:00
|
|
|
result = testdir.runpybin("py.cleanup", tmpdir)
|
|
|
|
assert not pyc.check()
|
2010-02-06 05:50:41 +08:00
|
|
|
assert not pyclass.check()
|
2009-10-12 17:24:41 +08:00
|
|
|
|
2009-10-27 23:03:14 +08:00
|
|
|
def test_dir_remove_simple(self, testdir, tmpdir):
|
|
|
|
subdir = tmpdir.mkdir("subdir")
|
|
|
|
p = subdir.ensure("file")
|
|
|
|
result = testdir.runpybin("py.cleanup", "-d", tmpdir)
|
2009-10-12 17:24:41 +08:00
|
|
|
assert result.ret == 0
|
2009-10-27 23:03:14 +08:00
|
|
|
assert subdir.check()
|
|
|
|
p.remove()
|
|
|
|
p = tmpdir.mkdir("hello")
|
2009-10-12 17:24:41 +08:00
|
|
|
result = testdir.runpybin("py.cleanup", tmpdir, '-d')
|
|
|
|
assert result.ret == 0
|
2009-10-27 23:03:14 +08:00
|
|
|
assert not subdir.check()
|
2010-02-06 05:50:41 +08:00
|
|
|
|
|
|
|
@py.test.mark.multi(opt=["-s"])
|
|
|
|
def test_remove_setup_simple(self, testdir, tmpdir, opt):
|
|
|
|
subdir = tmpdir.mkdir("subdir")
|
|
|
|
p = subdir.ensure("setup.py")
|
|
|
|
subdir.mkdir("build").ensure("hello", "world.py")
|
|
|
|
egg1 = subdir.mkdir("something.egg-info")
|
|
|
|
egg1.mkdir("whatever")
|
|
|
|
okbuild = subdir.mkdir("preserved1").mkdir("build")
|
|
|
|
egg2 = subdir.mkdir("preserved2").mkdir("other.egg-info")
|
|
|
|
subdir.mkdir("dist")
|
|
|
|
result = testdir.runpybin("py.cleanup", opt, subdir)
|
|
|
|
assert result.ret == 0
|
|
|
|
assert okbuild.check()
|
|
|
|
assert egg1.check()
|
|
|
|
assert egg2.check()
|
|
|
|
assert subdir.join("preserved1").check()
|
|
|
|
assert subdir.join("preserved2").check()
|
|
|
|
assert not subdir.join("build").check()
|
|
|
|
assert not subdir.join("dist").check()
|
|
|
|
|
|
|
|
def test_remove_all(self, testdir, tmpdir):
|
|
|
|
tmpdir.ensure("setup.py")
|
|
|
|
tmpdir.ensure("build", "xyz.py")
|
|
|
|
tmpdir.ensure("dist", "abc.py")
|
|
|
|
piplog = tmpdir.ensure("preserved2", "pip-log.txt")
|
|
|
|
tmpdir.ensure("hello.egg-info")
|
|
|
|
setup = tmpdir.ensure("setup.py")
|
|
|
|
tmpdir.ensure("src/a/b")
|
|
|
|
x = tmpdir.ensure("src/x.py")
|
|
|
|
x2 = tmpdir.ensure("src/x.pyc")
|
|
|
|
x3 = tmpdir.ensure("src/x$py.class")
|
|
|
|
result = testdir.runpybin("py.cleanup", "-a", tmpdir)
|
|
|
|
assert result.ret == 0
|
|
|
|
assert len(tmpdir.listdir()) == 3
|
|
|
|
assert setup.check()
|
|
|
|
assert x.check()
|
|
|
|
assert not x2.check()
|
|
|
|
assert not x3.check()
|
|
|
|
assert not piplog.check()
|