本文整理汇总了Python中djangorecipe.recipe.Recipe.command方法的典型用法代码示例。如果您正苦于以下问题:Python Recipe.command方法的具体用法?Python Recipe.command怎么用?Python Recipe.command使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类djangorecipe.recipe.Recipe
的用法示例。
在下文中一共展示了Recipe.command方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestRecipe
# 需要导入模块: from djangorecipe.recipe import Recipe [as 别名]
# 或者: from djangorecipe.recipe.Recipe import command [as 别名]
class TestRecipe(unittest.TestCase):
def setUp(self):
# Create a directory for our buildout files created by the recipe
self.buildout_dir = tempfile.mkdtemp('djangorecipe')
self.bin_dir = os.path.join(self.buildout_dir, 'bin')
self.develop_eggs_dir = os.path.join(self.buildout_dir,
'develop-eggs')
self.eggs_dir = os.path.join(self.buildout_dir, 'eggs')
self.parts_dir = os.path.join(self.buildout_dir, 'parts')
# We need to create the bin dir since the recipe should be able to expect it exists
os.mkdir(self.bin_dir)
self.recipe = Recipe({'buildout': {'eggs-directory': self.eggs_dir,
'develop-eggs-directory': self.develop_eggs_dir,
'python': 'python-version',
'bin-directory': self.bin_dir,
'parts-directory': self.parts_dir,
'directory': self.buildout_dir,
},
'python-version': {'executable': sys.executable}},
'django',
{'recipe': 'djangorecipe',
'version': 'trunk'})
def tearDown(self):
# Remove our test dir
shutil.rmtree(self.buildout_dir)
def test_consistent_options(self):
# Buildout is pretty clever in detecting changing options. If
# the recipe modifies it's options during initialisation it
# will store this to determine wheter it needs to update or do
# a uninstall & install. We need to make sure that we normally
# do not trigger this. That means running the recipe with the
# same options should give us the same results.
self.assertEqual(*[
Recipe({'buildout': {'eggs-directory': self.eggs_dir,
'develop-eggs-directory': self.develop_eggs_dir,
'python': 'python-version',
'bin-directory': self.bin_dir,
'parts-directory': self.parts_dir,
'directory': self.buildout_dir,
},
'python-version': {'executable': sys.executable}},
'django',
{'recipe': 'djangorecipe',
'version': 'trunk'}).options.copy() for i in range(2)])
def test_svn_url(self):
# Make sure that only a few specific type of url's are
# considered svn url's
# This is a plain release version so it should indicate it is
# not a svn url
self.failIf(self.recipe.is_svn_url('0.96.2'))
# The next line specifies a proper link with the trunk
self.assert_(self.recipe.is_svn_url('trunk'))
# A url looking like trunk should also fail
self.failIf(self.recipe.is_svn_url('trunka'))
# A full svn url including version should work
self.assert_(self.recipe.is_svn_url(
'http://code.djangoproject.com/svn/django/branches/[email protected]'))
# HTTPS should work too
self.assert_(self.recipe.is_svn_url(
'https://code.djangoproject.com/svn/django/branches/[email protected]'))
# Svn+ssh should work
self.assert_(self.recipe.is_svn_url(
'svn+ssh://myserver/[email protected]'))
# Svn protocol through any custom tunnel defined in ~/.subversion/config should work
self.assert_(self.recipe.is_svn_url(
'svn+MY_Custom-tunnel://myserver/[email protected]'))
# Using a non existent protocol should not be a svn url?
self.failIf(self.recipe.is_svn_url(
'unknown://myserver/[email protected]'))
def test_command(self):
# The command method is a wrapper for subprocess which excutes
# a command and return's it's status code. We will demonstrate
# this with a simple test of running `dir`.
self.failIf(self.recipe.command('echo'))
# Executing a non existing command should return an error code
self.assert_(self.recipe.command('spamspamspameggs'))
@mock.patch('subprocess', 'Popen')
def test_command_verbose_mode(self, popen):
# When buildout is put into verbose mode the command methode
# should stop capturing the ouput of it's commands.
popen.return_value = mock.Mock()
self.recipe.buildout['buildout']['verbosity'] = 'verbose'
self.recipe.command('silly-command')
self.assertEqual(
popen.call_args,
(('silly-command',), {'shell': True, 'stdout': None}))
def test_create_file(self):
# The create file helper should create a file at a certain
# location unless it already exists. We will need a
#.........这里部分代码省略.........