diff options
author | Zygmunt Krynicki <zygmunt.krynicki@linaro.org> | 2012-01-30 13:16:52 +0100 |
---|---|---|
committer | Zygmunt Krynicki <zygmunt.krynicki@linaro.org> | 2012-01-30 13:16:52 +0100 |
commit | 278974a3e88c086771cb498a6dddaa12f4bb406a (patch) | |
tree | 7174ad9e0e42a773520d553492a67386b904106d |
-rw-r--r-- | .bzrignore | 1 | ||||
-rw-r--r-- | lava/__init__.py | 3 | ||||
-rw-r--r-- | lava/utils/__init__.py | 3 | ||||
-rw-r--r-- | lava/utils/interface/__init__.py | 41 | ||||
-rw-r--r-- | lava/utils/interface/tests.py | 70 | ||||
-rw-r--r-- | setup.cfg | 2 | ||||
-rwxr-xr-x | setup.py | 51 |
7 files changed, 171 insertions, 0 deletions
diff --git a/.bzrignore b/.bzrignore new file mode 100644 index 0000000..11041c7 --- /dev/null +++ b/.bzrignore @@ -0,0 +1 @@ +*.egg-info diff --git a/lava/__init__.py b/lava/__init__.py new file mode 100644 index 0000000..d3a6eaf --- /dev/null +++ b/lava/__init__.py @@ -0,0 +1,3 @@ +__import__('pkg_resources').declare_namespace(__name__) +# DO NOT ADD ANYTHING TO THIS FILE! +# IT MUST STAY AS IS (empty apart from the two lines above) diff --git a/lava/utils/__init__.py b/lava/utils/__init__.py new file mode 100644 index 0000000..d3a6eaf --- /dev/null +++ b/lava/utils/__init__.py @@ -0,0 +1,3 @@ +__import__('pkg_resources').declare_namespace(__name__) +# DO NOT ADD ANYTHING TO THIS FILE! +# IT MUST STAY AS IS (empty apart from the two lines above) diff --git a/lava/utils/interface/__init__.py b/lava/utils/interface/__init__.py new file mode 100644 index 0000000..46b686e --- /dev/null +++ b/lava/utils/interface/__init__.py @@ -0,0 +1,41 @@ +# Copyright (C) 2012 Linaro Limited
+#
+# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
+#
+# This file is part of LAVA Utils Interface.
+#
+# LAVA Utils Interface is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# as published by the Free Software Foundation
+#
+# LAVA Utils Interface 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 Lesser General Public License
+# along with LAVA Utils Interface. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+lava.utils.interface
+====================
+
+Common interface class for LAVA
+"""
+
+
+__version__ = (1, 0, 0, "final", 0)
+
+
+from abc import ABCMeta, abstractmethod, abstractproperty
+
+
+class Interface(object):
+ """
+ Interface class.
+
+ This trivial class simply wraps the ABCMeta metaclass so you don't have to
+ worry about it much.
+ """
+
+ __metaclass__ = ABCMeta
diff --git a/lava/utils/interface/tests.py b/lava/utils/interface/tests.py new file mode 100644 index 0000000..e2a149a --- /dev/null +++ b/lava/utils/interface/tests.py @@ -0,0 +1,70 @@ +# Copyright (C) 2012 Linaro Limited +# +# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org> +# +# This file is part of LAVA Utils Interface. +# +# LAVA Utils Interface is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# as published by the Free Software Foundation +# +# LAVA Utils Interface 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 Lesser General Public License +# along with LAVA Utils Interface. If not, see <http://www.gnu.org/licenses/>. + +""" +lava.utils.interface.tests +========================== + +Unit tests for the interface class +""" + +import unittest2 + +from lava.utils.interface import Interface, abstractmethod, abstractproperty + + +class IAnimal(Interface): + """ + Animal interface, you can pat and call your pupils + """ + + @abstractmethod + def pat(self): + """ + Pat this animal, returns a string of what the reaction is + """ + + @abstractproperty + def name(self): + """ + Name of this animal + """ + + +class Dog(IAnimal): + + def __init__(self, name): + self._name = name + + @property + def name(self): + return self._name + + def pat(self): + return "The dog wiggles its tail" + + +class InterfaceTests(unittest2.TestCase): + + def test_raises_exceptions_for_missing_methods(self): + self.assertRaises(TypeError, IAnimal) + + def test_full_subclasses_work(self): + bit = Dog("bit") + self.assertEqual(bit.name, "bit") + self.assertEqual(bit.pat(), "The dog wiggles its tail") diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..58e0e0c --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[upload] +sign=True diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..67307a6 --- /dev/null +++ b/setup.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# +# Copyright (C) 2010 Linaro Limited +# +# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org> +# +# This file is part of LAVA Utils Interface. +# +# LAVA Utils Interface is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# as published by the Free Software Foundation +# +# LAVA Utils Interface 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 Lesser General Public License +# along with LAVA Utils Interface. If not, see <http://www.gnu.org/licenses/>. + +from setuptools import setup, find_packages + + +setup( + name='lava-utils-interface', + version=":versiontools:lava.utils.interface:__version__", + author="Zygmunt Krynicki", + author_email="zygmunt.krynicki@linaro.org", + namespace_packages=['lava', 'lava.utils'], + packages=find_packages(), + test_suite="unittest2.collector", + license="LGPL", + description="Common interface class for LAVA", + long_description=""" + A quite trivial package with generic abstract intraface class for LAVA. It + may look like an overkill but I'm tired of copy-pasting this code around. + """, + url='https://launchpad.net/lava-utils-interface', + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + ("License :: OSI Approved :: GNU Library or Lesser General Public" + " License (LGPL)"), + "Operating System :: OS Independent", + "Programming Language :: Python :: 2.6", + "Programming Language :: Python :: 2.7", + ], + setup_requires=['versiontools >= 1.8'], + tests_require=['unittest2'], + zip_safe=True, + include_package_data=True) |