Skip to content

Commit

Permalink
Merge 5b07527 into 56894e8
Browse files Browse the repository at this point in the history
  • Loading branch information
jocave committed Mar 24, 2016
2 parents 56894e8 + 5b07527 commit 10e2732
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/plainbox-test-tool/2016.com.example:simple/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python3
from plainbox.provider_manager import setup, N_


setup(
name='plainbox-provider-simple',
namespace='2016.com.example',
version="1.0",
description=N_("A really simple Plainbox provider"),
gettext_domain="2016_com_example_simple",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

unit: category
id: simple
_name: Simple

unit: job
id: always-pass
category_id: simple
_summary: A test that always passes
_description:
A test that always passes
.
This simple test will always succeed, assuming your
platform has a 'true' command that returns 0.
plugin: shell
estimated_duration: 0.01
command: true
flags: preserve-locale

unit: job
id: always-fail
category_id: simple
_summary: A test that always fails
_description:
A test that always fails
.
This simple test will always fail, assuming your
platform has a 'false' command that returns 1.
plugin: shell
estimated_duration: 0.01
command: false
flags: preserve-locale
7 changes: 7 additions & 0 deletions examples/plainbox-test-tool/launchers/plainbox-wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
# Set a PROVIDERPATH so that plainbox can find bundled providers:
# each provider is installed to /providers/$name, they are listed
# in a typical :-separated PATH-like variable.
export PROVIDERPATH="$SNAP_APP_PATH/providers/simple-plainbox-provider"
export PATH="$PATH:$SNAP_APP_PATH/usr/sbin"
exec python3 $(which plainbox) "$@"
32 changes: 32 additions & 0 deletions examples/plainbox-test-tool/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: plainbox-test-tool
summary: A Plainbox Test Tool
description: >
The Plainbox tool itself coupled with a Provider which contains the test
definitions
version: 0.1

apps:
plainbox:
command: bin/plainbox-wrapper
plugs: [dont-confine]

plugs:
dont-confine:
interface: old-security
security-template: unconfined

parts:
# The testing framework
plainbox:
plugin: nil
stage-packages:
- plainbox
# The test definitions
simple-plainbox-provider:
plugin: plainbox-provider
source: ./2016.com.example:simple
# A wrapper script
launchers:
plugin: copy
files:
launchers/plainbox-wrapper: bin/plainbox-wrapper
39 changes: 39 additions & 0 deletions examples_tests/test_plainbox_test_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright (C) 2016 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import examples_tests


class PlainboxTestCase(examples_tests.ExampleTestCase):

example_dir = 'plainbox-test-tool'

def test_plainbox(self):
# build and install the example
self.build_snap(self.example_dir)
self.install_snap(self.example_dir, 'plainbox-test-tool', '0.1')
# check that can run plainbox and list the tests available
expected = """2013.com.canonical.plainbox::collect-manifest
2013.com.canonical.plainbox::manifest
2016.com.example::always-fail
2016.com.example::always-pass
"""
self.assert_command_in_snappy_testbed(
'/snaps/bin/plainbox-test-tool.plainbox dev special -j',
expected)
# check can run the tests in the example provider
self.run_command_in_snappy_testbed(
'/snaps/bin/plainbox-test-tool.plainbox run -i 2016.com.example::.*')
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python3
from plainbox.provider_manager import setup, N_


setup(
name='plainbox-provider-simple',
namespace='2016.com.example',
version="1.0",
description=N_("A really simple Plainbox provider"),
gettext_domain="2016_com_example_simple",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

unit: category
id: simple
_name: Simple

unit: job
id: always-pass
category_id: simple
_summary: A test that always passes
_description:
A test that always passes
.
This simple test will always succeed, assuming your
platform has a 'true' command that returns 0.
plugin: shell
estimated_duration: 0.01
command: true
flags: preserve-locale

unit: job
id: always-fail
category_id: simple
_summary: A test that always fails
_description:
A test that always fails
.
This simple test will always fail, assuming your
platform has a 'false' command that returns 1.
plugin: shell
estimated_duration: 0.01
command: false
flags: preserve-locale
11 changes: 11 additions & 0 deletions integration_tests/snaps/simple-plainbox-provider/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: test-package
version: 0.1
summary: Create a snap of a plainbox provider
description: |
Create a snap of a very simple plainbox that could
then be used by a checkbox application
parts:
simple-plainbox-provider:
plugin: plainbox-provider
source: ./2016.com.example:simple
1 change: 1 addition & 0 deletions integration_tests/test_list_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_list_plugins(self):
'maven\n'
'nil\n'
'nodejs\n'
'plainbox-provider\n'
'python2\n'
'python3\n'
'qml\n'
Expand Down
1 change: 1 addition & 0 deletions integration_tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_main(self):
'maven',
'nil',
'nodejs',
'plainbox-provider',
'python2',
'python3',
'qml',
Expand Down
34 changes: 34 additions & 0 deletions integration_tests/test_plainbox_provider_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright (C) 2016 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os

from testtools.matchers import FileExists

import integration_tests


class PlainboxProviderPluginTestCase(integration_tests.TestCase):

def test_snap_simple_provider(self):
project_dir = 'simple-plainbox-provider'
self.run_snapcraft('snap', project_dir)

self.assertThat(
os.path.join(
project_dir, 'snap', 'providers', 'simple-plainbox-provider',
'plainbox-provider-simple.provider'),
FileExists())
80 changes: 80 additions & 0 deletions snapcraft/plugins/plainbox_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright (C) 2016 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

""" Create parts containing a Plainbox test collection known as a provider.
Plainbox is a toolkit consisting of python3 library, development tools,
documentation and examples. It is targeted at developers working on testing or
certification applications and authors creating tests for such applications.
More information: http://plainbox.readthedocs.org/en/latest/
To find out more about authoring a plainbox provider, see the following
documentation: http://plainbox.readthedocs.org/en/latest/author/providers.html
This plugin uses the common plugin keywords as well as those for "sources".
For more information check the 'plugins' topic for the former and the
'sources' topic for the latter.
Plugin specific keywords:
- checkbox-dev-ppa:
(boolean)
Whether to extend the source list to include the Checkbox Development
PPA https://launchpad.net/~checkbox-dev/+archive/ubuntu/ppa. Defaults to
true as features to support Snappy Ubuntu Core have yet to land in the
distro repositories.
"""

import snapcraft


class PlainboxProviderPlugin(snapcraft.BasePlugin):

_DEV_PPA_PLUGIN_STAGE_SOURCES = '''
deb http://${prefix}.ubuntu.com/${suffix}/ ${release} main restricted
deb http://${prefix}.ubuntu.com/${suffix}/ ${release}-updates main restricted
deb http://${prefix}.ubuntu.com/${suffix}/ ${release} universe
deb http://${prefix}.ubuntu.com/${suffix}/ ${release}-updates universe
deb http://${prefix}.ubuntu.com/${suffix}/ ${release} multiverse
deb http://${prefix}.ubuntu.com/${suffix}/ ${release}-updates multiverse
deb http://${security}.ubuntu.com/${suffix} ${release}-security main restricted
deb http://${security}.ubuntu.com/${suffix} ${release}-security universe
deb http://${security}.ubuntu.com/${suffix} ${release}-security multiverse
deb http://ppa.launchpad.net/checkbox-dev/ppa/ubuntu ${release} main
'''

@classmethod
def schema(cls):
schema = super().schema()
schema['properties']['checkbox-dev-ppa'] = {
'type': 'boolean',
'default': 'true',
}
return schema

def __init__(self, name, options):
super().__init__(name, options)
self.build_packages.extend(['python3-plainbox', 'intltool'])
if self.options.checkbox_dev_ppa:
self._PLUGIN_STAGE_SOURCES = self._DEV_PPA_PLUGIN_STAGE_SOURCES

def build(self):
super().build()
self.run(["python3", "manage.py", "build"])
self.run(["python3", "manage.py", "i18n"])
self.run([
"python3", "manage.py", "install", "--layout=relocatable",
"--prefix=/providers/{}".format(self.name),
"--root={}".format(self.installdir)])
1 change: 1 addition & 0 deletions snapcraft/tests/test_commands_list_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_list_plugins(self, mock_stdout):
maven
nil
nodejs
plainbox-provider
python2
python3
qml
Expand Down

0 comments on commit 10e2732

Please sign in to comment.