2007-02-07 23:36:02 +08:00
|
|
|
import py
|
2007-02-08 21:51:38 +08:00
|
|
|
import sys
|
2007-02-07 23:36:02 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
"""))
|
2007-02-09 01:28:55 +08:00
|
|
|
initfile = pkgpath.ensure('__init__.py').write(py.code.Source("""
|
2007-02-07 23:36:02 +08:00
|
|
|
import py
|
|
|
|
from py.__.initpkg import initpkg
|
|
|
|
initpkg(__name__, exportdefs={
|
|
|
|
'sub.foo': ('./mod.py', 'foo'),
|
|
|
|
})
|
|
|
|
"""))
|
2007-02-09 01:28:55 +08:00
|
|
|
initfile = pkgpath.ensure('apigen/apigen.py').write(py.code.Source("""
|
|
|
|
from py.__.apigen.apigen import build, \
|
|
|
|
get_documentable_items_pkgdir as get_documentable_items
|
|
|
|
"""))
|
2007-02-07 23:36:02 +08:00
|
|
|
return pkgpath
|
|
|
|
|
|
|
|
def test_run_tests():
|
2007-02-07 23:54:50 +08:00
|
|
|
if py.std.sys.platform == "win32":
|
|
|
|
py.test.skip("update_website is not supposed to be run from win32")
|
2007-02-07 23:36:02 +08:00
|
|
|
pkgpath = setup_pkg('update_website_run_tests')
|
2007-02-10 23:41:31 +08:00
|
|
|
errors = update_website.run_tests(pkgpath, captureouterr=True)
|
2007-02-07 23:36:02 +08:00
|
|
|
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():
|
2007-02-08 21:51:38 +08:00
|
|
|
if py.std.sys.platform == "win32":
|
|
|
|
py.test.skip("update_website is not supposed to be run from win32")
|
2007-02-07 23:36:02 +08:00
|
|
|
pkgpath = setup_pkg('update_website_run_tests_failure')
|
|
|
|
assert not pkgpath.join('../apigen').check(dir=True)
|
|
|
|
pkgpath.ensure('../apigen', file=True)
|
2007-02-10 23:41:31 +08:00
|
|
|
errors = update_website.run_tests(pkgpath, captureouterr=True)
|
2007-02-07 23:36:02 +08:00
|
|
|
assert errors # some error message
|
|
|
|
|