[svn r38077] Script to run "py.test --apigen" on the py lib (well, can be used on other
projects too) and rsync the results to some remote host/path (by default codespeak.net, currently to some dir in my home directory, when it's tested better in practice files will go to the website directory). --HG-- branch : trunk
This commit is contained in:
parent
5c7fb384bc
commit
d11aec0b42
|
@ -0,0 +1,65 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
""" run py.test with the --apigen option and rsync the results to a host
|
||||
|
||||
rsyncs the whole package (with all the ReST docs converted to HTML) as well
|
||||
as the apigen docs to a given remote host and path
|
||||
"""
|
||||
|
||||
import py
|
||||
import sys
|
||||
|
||||
def rsync(pkgpath, apidocspath, gateway, remotepath):
|
||||
""" copy the code and docs to the remote host """
|
||||
# copy to a temp dir first, even though both paths (normally) share the
|
||||
# same parent dir, that may contain other stuff that we don't want to
|
||||
# copy...
|
||||
tempdir = py.test.ensuretemp('update_website_rsync_temp')
|
||||
pkgpath.copy(tempdir.ensure(pkgpath.basename, dir=True))
|
||||
apidocspath.copy(tempdir.ensure(apidocspath.basename, dir=True))
|
||||
|
||||
rs = py.execnet.RSync(delete=True)
|
||||
rs.add_target(gateway, remotepath)
|
||||
rs.send(tempdir)
|
||||
|
||||
def run_tests(pkgpath, args=''):
|
||||
""" run the unit tests and build the docs """
|
||||
pypath = py.__package__.getpath()
|
||||
pytestpath = pypath.join('bin/py.test')
|
||||
# XXX this would need a Windows specific version if we want to allow
|
||||
# running this script on that platform, but currently --apigen doesn't
|
||||
# work there anyway...
|
||||
apigenpath = pkgpath.join('apigen/apigen.py') # XXX be more general here?
|
||||
if not apigenpath.check(file=True):
|
||||
apigenpath = pypath.join('apigen/apigen.py')
|
||||
cmd = 'PYTHONPATH="%s:%s" "%s" --apigen="%s" "%s" %s' % (pypath.dirpath(),
|
||||
pkgpath.dirpath(),
|
||||
pytestpath,
|
||||
apigenpath,
|
||||
pkgpath,
|
||||
args)
|
||||
status = py.std.os.system(cmd)
|
||||
return status
|
||||
|
||||
def main(pkgpath, apidocspath, rhost, rpath, args=''):
|
||||
print 'running tests'
|
||||
errors = run_tests(pkgpath, args)
|
||||
if errors:
|
||||
print >>sys.stderr, \
|
||||
'Errors while running the unit tests: %s' % (errors,)
|
||||
sys.exit(1)
|
||||
|
||||
print 'rsyncing'
|
||||
gateway = py.execnet.SshGateway(rhost)
|
||||
errors = rsync(pkgpath, apidocspath, gateway, rpath)
|
||||
if errors:
|
||||
print >>sys.stderr, 'Errors while rsyncing: %s'
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = ' '.join(sys.argv[1:])
|
||||
pkgpath = py.__package__.getpath()
|
||||
apidocspath = pkgpath.dirpath().join('apigen')
|
||||
main(pkgpath, apidocspath, 'codespeak.net',
|
||||
'/home/guido/rsynctests', args)
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
import py
|
||||
|
||||
here = py.magic.autopath().dirpath()
|
||||
update_website = here.join('../../bin/_update_website.py').pyimport()
|
||||
|
||||
def test_rsync():
|
||||
temp = py.test.ensuretemp('update_website_rsync')
|
||||
pkgpath = temp.join('pkg')
|
||||
apipath = temp.join('apigen')
|
||||
pkgpath.ensure('foo/bar.txt', file=True).write('baz')
|
||||
pkgpath.ensure('spam/eggs.txt', file=True).write('spam')
|
||||
apipath.ensure('api/foo.html', file=True).write('<html />')
|
||||
apipath.ensure('source/spam.html', file=True).write('<html />')
|
||||
|
||||
rsyncpath = temp.join('rsync')
|
||||
assert not rsyncpath.check()
|
||||
gateway = py.execnet.PopenGateway()
|
||||
update_website.rsync(pkgpath, apipath, gateway, rsyncpath.strpath)
|
||||
assert rsyncpath.check(dir=True)
|
||||
assert rsyncpath.join('pkg').check(dir=True)
|
||||
assert rsyncpath.join('pkg/spam/eggs.txt').read() == 'spam'
|
||||
assert rsyncpath.join('apigen').check(dir=True)
|
||||
assert rsyncpath.join('apigen/api/foo.html').read() == '<html />'
|
||||
|
||||
def setup_pkg(testname):
|
||||
temp = py.test.ensuretemp(testname)
|
||||
pkgpath = temp.ensure('pkg', dir=True)
|
||||
pyfile = pkgpath.ensure('mod.py').write(py.code.Source("""
|
||||
def foo(x):
|
||||
return x + 1
|
||||
"""))
|
||||
testfile = pkgpath.ensure('test/test_mod.py').write(py.code.Source("""
|
||||
from pkg.sub import foo
|
||||
def test_foo():
|
||||
assert foo(1) == 2
|
||||
"""))
|
||||
initfile = pkgpath.ensure('__init__.py').write(py.code.Source("""\
|
||||
import py
|
||||
from py.__.initpkg import initpkg
|
||||
initpkg(__name__, exportdefs={
|
||||
'sub.foo': ('./mod.py', 'foo'),
|
||||
})
|
||||
"""))
|
||||
return pkgpath
|
||||
|
||||
def test_run_tests():
|
||||
pkgpath = setup_pkg('update_website_run_tests')
|
||||
errors = update_website.run_tests(pkgpath)
|
||||
assert not errors
|
||||
assert pkgpath.join('../apigen').check(dir=True)
|
||||
assert pkgpath.join('../apigen/api/sub.foo.html').check(file=True)
|
||||
|
||||
def test_run_tests_failure():
|
||||
pkgpath = setup_pkg('update_website_run_tests_failure')
|
||||
assert not pkgpath.join('../apigen').check(dir=True)
|
||||
pkgpath.ensure('../apigen', file=True)
|
||||
errors = update_website.run_tests(pkgpath)
|
||||
assert errors # some error message
|
||||
|
Loading…
Reference in New Issue