Imported from SVN by Bitbucket

This commit is contained in:
2015-03-31 20:26:20 +00:00
committed by bitbucket
commit ceb7984dec
212 changed files with 49537 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import sys
import os
import shutil
import pkg_resources
here = os.path.dirname(__file__)
base = os.path.dirname(here)
fake_packages = os.path.join(here, 'fake_packages')
sys.path.append(fake_packages)
sys.path.append(here)
sys.path.insert(0, base)
here = os.path.dirname(__file__)
egg_info_dir = os.path.join(here, 'fake_packages', 'FakePlugin.egg',
'EGG-INFO')
info_dir = os.path.join(here, 'fake_packages', 'FakePlugin.egg',
'FakePlugin.egg-info')
if not os.path.exists(egg_info_dir):
try:
os.symlink(info_dir, egg_info_dir)
except:
shutil.copytree(info_dir, egg_info_dir)
pkg_resources.working_set.add_entry(fake_packages)
pkg_resources.working_set.add_entry(base)
if not os.environ.get('PASTE_TESTING'):
output_dir = os.path.join(here, 'appsetup', 'output')
if os.path.exists(output_dir):
shutil.rmtree(output_dir)
pkg_resources.require('FakePlugin')

View File

@@ -0,0 +1,139 @@
import urllib
import os
from nose import SkipTest
from paste.fixture import *
import pkg_resources
for spec in ['PasteScript', 'Paste', 'PasteDeploy', 'PasteWebKit',
'ZPTKit']:
try:
pkg_resources.require(spec)
except pkg_resources.DistributionNotFound, dnf:
raise SkipTest(repr(dnf))
template_path = os.path.join(
os.path.dirname(__file__), 'testfiles')
test_environ = os.environ.copy()
test_environ['PASTE_TESTING'] = 'true'
testenv = TestFileEnvironment(
os.path.join(os.path.dirname(__file__), 'output'),
template_path=template_path,
environ=test_environ)
def svn_repos_setup():
res = testenv.run('svnadmin', 'create', 'REPOS',
printresult=False)
testenv.svn_url = 'file://' + testenv.base_path + '/REPOS'
assert 'REPOS' in res.files_created
testenv.ignore_paths.append('REPOS')
def paster_create():
global projenv
res = testenv.run('paster', 'create', '--verbose',
'--svn-repository=' + testenv.svn_url,
'--template=paste_deploy',
'--template=webkit',
'--template=zpt',
'--no-interactive',
'ProjectName',
'version=0.1',
'author=Test Author',
'author_email=test@example.com')
expect_fn = ['tests', 'docs', 'projectname', 'docs',
'setup.py', 'ProjectName.egg-info',
]
for fn in expect_fn:
fn = os.path.join('ProjectName', fn)
assert fn in res.files_created
assert fn in res.stdout
setup = res.files_created['ProjectName/setup.py']
setup.mustcontain('test@example.com')
setup.mustcontain('Test Author')
setup.mustcontain('0.1')
setup.mustcontain('projectname.wsgiapp:make_app')
# ZPTKit should add this:
setup.mustcontain("include_package_data")
assert '0.1' in setup
sitepage = res.files_created['ProjectName/projectname/sitepage.py']
proj_dir = os.path.join(testenv.cwd, 'ProjectName')
testenv.run('svn commit -m "new project"',
cwd=proj_dir)
testenv.run('python setup.py egg_info',
cwd=proj_dir,
expect_stderr=True)
testenv.run('svn', 'commit', '-m', 'Created project', 'ProjectName')
# A new environment with a new
projenv = TestFileEnvironment(
os.path.join(testenv.base_path, 'ProjectName'),
start_clear=False,
template_path=template_path,
environ=test_environ)
projenv.environ['PYTHONPATH'] = (
projenv.environ.get('PYTHONPATH', '') + ':'
+ projenv.base_path)
projenv.proj_dir = proj_dir
def make_servlet():
res = projenv.run(
'paster servlet --verbose --simulate test1',
cwd=projenv.proj_dir)
assert not res.files_created and not res.files_updated
res = projenv.run('paster servlet -vvv test1')
assert 'projectname/web/test1.py' in res.files_created
assert 'projectname/templates/test1.pt' in res.files_created
res = projenv.run('paster servlet -vvv ack.test2')
assert 'projectname/web/ack/test2.py' in res.files_created
assert 'projectname/templates/ack/test2.pt' in res.files_created
res = projenv.run('paster servlet --no-servlet -vvv test3')
assert 'projectname/web/test3.py' not in res.files_created
assert 'projectname/templates/test3.pt' in res.files_created
res = projenv.run('svn status')
# Make sure all files are added to the repository:
assert '?' not in res.stdout
def do_pytest():
res = projenv.run('py.test tests/',
cwd=os.path.join(testenv.cwd, 'ProjectName'),
expect_stderr=True)
assert len(res.stderr.splitlines()) <= 1, (
"Too much info on stderr: %s" % res.stderr)
def config_permissions():
projenv.writefile('ProjectName.egg-info/iscape.txt',
frompath='iscape.txt')
projenv.writefile('projectname/web/admin/index.py',
frompath='admin_index.py')
projenv.writefile('tests/test_forbidden.py',
frompath='test_forbidden.py')
res = projenv.run('py.test tests/test_forbidden.py',
expect_stderr=True)
assert len(res.stderr.splitlines()) <= 1, (
"Too much info on stderr: %s" % res.stderr)
def make_tag():
global tagenv
res = projenv.run('svn commit -m "updates"')
res = projenv.run('python setup.py svntag --version=0.5')
assert 'Tagging 0.5 version' in res.stdout
assert 'Auto-update of version strings' in res.stdout
res = testenv.run('svn co %s/ProjectName/tags/0.5 Proj-05'
% testenv.svn_url)
setup = res.files_created['Proj-05/setup.py']
setup.mustcontain('0.5')
assert 'Proj-05/setup.cfg' not in res.files_created
tagenv = TestFileEnvironment(
os.path.join(testenv.base_path, 'Proj-05'),
start_clear=False,
template_path=template_path)
def test_project():
global projenv
projenv = None
yield svn_repos_setup
yield paster_create
yield make_servlet
yield do_pytest
yield config_permissions
yield make_tag

View File

@@ -0,0 +1,25 @@
import os
from paste.script import pluginlib
def test_egg_info():
egg_dir = os.path.join(os.path.dirname(__file__),
'fake_packages', 'FakePlugin.egg')
found = pluginlib.find_egg_info_dir(os.path.join(egg_dir, 'fakeplugin'))
assert found == os.path.join(egg_dir, 'FakePlugin.egg-info')
found = pluginlib.find_egg_info_dir(os.path.dirname(__file__))
assert found == os.path.join(
os.path.dirname(os.path.dirname(__file__)),
'PasteScript.egg-info')
def test_resolve_plugins():
plugins = ['FakePlugin']
all = pluginlib.resolve_plugins(plugins)
assert all
assert len(all) == 2
def test_find_commands():
all = pluginlib.resolve_plugins(['PasteScript', 'FakePlugin'])
commands = pluginlib.load_commands_from_plugins(all)
print commands
assert 'testcom' in commands

View File

@@ -0,0 +1,232 @@
#!/usr/bin/env python
#
# Copyright 2001-2004 by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Vinay Sajip
# not be used in advertising or publicity pertaining to distribution
# of the software without specific, written prior permission.
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# This file is part of the Python logging distribution. See
# http://www.red-dove.com/python_logging.html
#
"""Test harness for the logging module. Run all tests.
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
"""
import os, sys, string
import tempfile
import logging
from paste.script.util import logging_config
def message(s):
sys.stdout.write("%s\n" % s)
#----------------------------------------------------------------------------
# Test 4
#----------------------------------------------------------------------------
# config0 is a standard configuration.
config0 = """
[loggers]
keys=root
[handlers]
keys=hand1
[formatters]
keys=form1
[logger_root]
level=NOTSET
handlers=hand1
[handler_hand1]
class=StreamHandler
level=NOTSET
formatter=form1
args=(sys.stdout,)
[formatter_form1]
format=%(levelname)s:%(name)s:%(message)s
datefmt=
"""
# config1 adds a little to the standard configuration.
config1 = """
[loggers]
keys=root,parser
[handlers]
keys=hand1, hand2
[formatters]
keys=form1, form2
[logger_root]
level=NOTSET
handlers=hand1,hand2
[logger_parser]
level=DEBUG
handlers=hand1
propagate=1
qualname=compiler.parser
[handler_hand1]
class=StreamHandler
level=NOTSET
formatter=form1
args=(sys.stdout,)
[handler_hand2]
class=StreamHandler
level=NOTSET
formatter=form2
args=(sys.stderr,)
[formatter_form1]
format=%(levelname)s:%(name)s:%(message)s
datefmt=
[formatter_form2]
format=:%(message)s
datefmt=
"""
# config2 has a subtle configuration error that should be reported
config2 = string.replace(config1, "sys.stdout", "sys.stbout")
# config3 has a less subtle configuration error
config3 = string.replace(
config1, "formatter=form1", "formatter=misspelled_name")
# config4: support custom Handler classes
config4 = string.replace(
config1, "class=StreamHandler", "class=logging.StreamHandler")
def test4():
for i in range(5):
conf = globals()['config%d' % i]
sys.stdout.write('config%d: ' % i)
loggerDict = logging.getLogger().manager.loggerDict
logging._acquireLock()
try:
saved_handlers = logging._handlers.copy()
if hasattr(logging, '_handlerList'):
saved_handler_list = logging._handlerList[:]
saved_loggers = loggerDict.copy()
finally:
logging._releaseLock()
try:
fn = tempfile.mktemp(".ini")
f = open(fn, "w")
f.write(conf)
f.close()
try:
logging_config.fileConfig(fn)
#call again to make sure cleanup is correct
logging_config.fileConfig(fn)
except:
if i not in (2, 3):
raise
t = sys.exc_info()[0]
message(str(t) + ' (expected)')
else:
message('ok.')
os.remove(fn)
finally:
logging._acquireLock()
try:
logging._handlers.clear()
logging._handlers.update(saved_handlers)
if hasattr(logging, '_handlerList'):
logging._handlerList[:] = saved_handler_list
loggerDict = logging.getLogger().manager.loggerDict
loggerDict.clear()
loggerDict.update(saved_loggers)
finally:
logging._releaseLock()
#----------------------------------------------------------------------------
# Test 5
#----------------------------------------------------------------------------
test5_config = """
[loggers]
keys=root
[handlers]
keys=hand1
[formatters]
keys=form1
[logger_root]
level=NOTSET
handlers=hand1
[handler_hand1]
class=StreamHandler
level=NOTSET
formatter=form1
args=(sys.stdout,)
[formatter_form1]
#class=test.test_logging.FriendlyFormatter
class=test_logging_config.FriendlyFormatter
format=%(levelname)s:%(name)s:%(message)s
datefmt=
"""
class FriendlyFormatter (logging.Formatter):
def formatException(self, ei):
return "%s... Don't panic!" % str(ei[0])
def test5():
loggerDict = logging.getLogger().manager.loggerDict
logging._acquireLock()
try:
saved_handlers = logging._handlers.copy()
if hasattr(logging, '_handlerList'):
saved_handler_list = logging._handlerList[:]
saved_loggers = loggerDict.copy()
finally:
logging._releaseLock()
try:
fn = tempfile.mktemp(".ini")
f = open(fn, "w")
f.write(test5_config)
f.close()
logging_config.fileConfig(fn)
try:
raise KeyError
except KeyError:
logging.exception("just testing")
os.remove(fn)
hdlr = logging.getLogger().handlers[0]
logging.getLogger().handlers.remove(hdlr)
finally:
logging._acquireLock()
try:
logging._handlers.clear()
logging._handlers.update(saved_handlers)
if hasattr(logging, '_handlerList'):
logging._handlerList[:] = saved_handler_list
loggerDict = logging.getLogger().manager.loggerDict
loggerDict.clear()
loggerDict.update(saved_loggers)
finally:
logging._releaseLock()

View File

@@ -0,0 +1,25 @@
import os
from paste.script import pluginlib
egg_dir = os.path.join(os.path.dirname(__file__),
'fake_packages', 'FakePlugin.egg')
plugin_file = os.path.join(egg_dir, 'paster_plugins.txt')
def plugin_lines():
if not os.path.exists(plugin_file):
return []
f = open(plugin_file)
lines = f.readlines()
f.close()
return [l.strip() for l in lines if l.strip()]
def test_add_remove():
prev = plugin_lines()
pluginlib.add_plugin(egg_dir, 'Test')
assert 'Test' in plugin_lines()
pluginlib.remove_plugin(egg_dir, 'Test')
assert 'Test' not in plugin_lines()
assert prev == plugin_lines()
if not prev and os.path.exists(plugin_file):
os.unlink(plugin_file)

View File

@@ -0,0 +1,13 @@
import os
from paste.script import templates
tmpl_dir = os.path.join(os.path.dirname(__file__), 'sample_templates')
def test_find():
vars = templates.find_args_in_dir(tmpl_dir, True)
assert 'a' in vars
assert vars['a'].default is templates.NoDefault
assert 'b' in vars
assert vars['b'].default == 1
assert len(vars) == 2