| 1 |
# Copyright (c) 2013 New Dream Network, LLC (DreamHost) |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 12 |
# implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
# |
| 16 |
# Copyright (C) 2013 Association of Universities for Research in Astronomy |
| 17 |
# (AURA) |
| 18 |
# |
| 19 |
# Redistribution and use in source and binary forms, with or without |
| 20 |
# modification, are permitted provided that the following conditions are met: |
| 21 |
# |
| 22 |
# 1. Redistributions of source code must retain the above copyright |
| 23 |
# notice, this list of conditions and the following disclaimer. |
| 24 |
# |
| 25 |
# 2. Redistributions in binary form must reproduce the above |
| 26 |
# copyright notice, this list of conditions and the following |
| 27 |
# disclaimer in the documentation and/or other materials provided |
| 28 |
# with the distribution. |
| 29 |
# |
| 30 |
# 3. The name of AURA and its representatives may not be used to |
| 31 |
# endorse or promote products derived from this software without |
| 32 |
# specific prior written permission. |
| 33 |
# |
| 34 |
# THIS SOFTWARE IS PROVIDED BY AURA ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 35 |
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 36 |
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 37 |
# DISCLAIMED. IN NO EVENT SHALL AURA BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 38 |
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 39 |
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 40 |
|
| 41 |
import testtools |
| 42 |
|
| 43 |
from pbr._compat import easy_install |
| 44 |
from pbr._compat import metadata |
| 45 |
|
| 46 |
|
| 47 |
class TestPackagingHelpers(testtools.TestCase): |
| 48 |
|
| 49 |
def test_generate_script(self): |
| 50 |
group = 'console_scripts' |
| 51 |
entry_point = metadata.entrypoint( |
| 52 |
module_name='pbr.packaging', |
| 53 |
attrs=('LocalInstallScripts',), |
| 54 |
) |
| 55 |
header = '#!/usr/bin/env fake-header\n' |
| 56 |
template = ( |
| 57 |
'%(group)s %(module_name)s %(import_target)s %(invoke_target)s' |
| 58 |
) |
| 59 |
|
| 60 |
generated_script = easy_install.generate_script( |
| 61 |
group, entry_point, header, template |
| 62 |
) |
| 63 |
|
| 64 |
expected_script = ( |
| 65 |
'#!/usr/bin/env fake-header\nconsole_scripts pbr.packaging ' |
| 66 |
'LocalInstallScripts LocalInstallScripts' |
| 67 |
) |
| 68 |
self.assertEqual(expected_script, generated_script) |
| 69 |
|
| 70 |
def test_generate_script_validates_expectations(self): |
| 71 |
group = 'console_scripts' |
| 72 |
entry_point = metadata.entrypoint( |
| 73 |
module_name='pbr.packaging', |
| 74 |
attrs=None, |
| 75 |
) |
| 76 |
header = '#!/usr/bin/env fake-header\n' |
| 77 |
template = ( |
| 78 |
'%(group)s %(module_name)s %(import_target)s %(invoke_target)s' |
| 79 |
) |
| 80 |
self.assertRaises( |
| 81 |
ValueError, |
| 82 |
easy_install.generate_script, |
| 83 |
group, |
| 84 |
entry_point, |
| 85 |
header, |
| 86 |
template, |
| 87 |
) |
| 88 |
|
| 89 |
entry_point = metadata.entrypoint( |
| 90 |
module_name='pbr.packaging', |
| 91 |
attrs=('attr1', 'attr2', 'attr3'), |
| 92 |
) |
| 93 |
self.assertRaises( |
| 94 |
ValueError, |
| 95 |
easy_install.generate_script, |
| 96 |
group, |
| 97 |
entry_point, |
| 98 |
header, |
| 99 |
template, |
| 100 |
) |