1
# Copyright (C) 2014 Canonical Ltd.
2
# Author: Michael Vogt <michael.vogt@ubuntu.com>
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 3 of the License.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
"""Integration tests helper for the click CLI interface."""
29
@contextlib.contextmanager
39
class TestCase(unittest.TestCase):
43
cls.click_binary = os.environ.get("CLICK_BINARY", "/usr/bin/click")
45
def _create_manifest(self, target, name, version, framework):
46
with open(target, "w") as f:
50
"maintainer": "Foo Bar <foo@example.org>",
51
"title": "test title",
53
}""" % (name, version, framework))
55
def _make_click(self, name=None, version=1.0, framework="ubuntu-sdk-13.10"):
57
name = "com.ubuntu.%s" % "".join(
58
random.choice(string.ascii_lowercase) for i in range(10))
59
tmpdir = tempfile.mkdtemp()
60
self.addCleanup(lambda: shutil.rmtree(tmpdir))
61
clickdir = os.path.join(tmpdir, name)
63
self._create_manifest(os.path.join(clickdir, "manifest.json"),
64
name, version, framework)
65
with open(os.path.join(clickdir, "README"), "w") as f:
66
f.write("hello world!")
67
with chdir(tmpdir), open(os.devnull, "w") as devnull:
69
[self.click_binary, "build", clickdir], stdout=devnull)
70
generated_clicks = glob.glob(os.path.join(tmpdir, "*.click"))
71
self.assertEqual(len(generated_clicks), 1)
72
return generated_clicks[0]