public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
* [PATCH 1/3] test-utils: handle import bb failing and skip the test
@ 2013-05-23 18:44 Ross Burton
  2013-05-23 18:45 ` [PATCH 2/3] test_utils: import functions directly for conciseness Ross Burton
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ross Burton @ 2013-05-23 18:44 UTC (permalink / raw)
  To: openembedded-core

Instead of reporting an error when bb cannot be imported, skip the test
instead. This makes it a lot easier to iterate a test suite when we don't care
about this particular test.

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/lib/oe/tests/test_utils.py |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/meta/lib/oe/tests/test_utils.py b/meta/lib/oe/tests/test_utils.py
index 466c47e..779247a 100644
--- a/meta/lib/oe/tests/test_utils.py
+++ b/meta/lib/oe/tests/test_utils.py
@@ -1,11 +1,15 @@
 import unittest
-import bb, oe.utils
+import oe.utils
 
 class TestPackagesFilterOutSystem(unittest.TestCase):
     def test_filter(self):
         """
         Test that oe.utils.packages_filter_out_system works.
         """
+        try:
+            import bb
+        except ImportError:
+            self.skipTest("Cannot import bb")
 
         d = bb.data_smart.DataSmart()
         d.setVar("PN", "foo")
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] test_utils: import functions directly for conciseness
  2013-05-23 18:44 [PATCH 1/3] test-utils: handle import bb failing and skip the test Ross Burton
@ 2013-05-23 18:45 ` Ross Burton
  2013-05-23 18:45 ` [PATCH 3/3] utils: add trim_version() function Ross Burton
  2013-05-30 19:49 ` [PATCH 1/3] test-utils: handle import bb failing and skip the test Richard Purdie
  2 siblings, 0 replies; 5+ messages in thread
From: Ross Burton @ 2013-05-23 18:45 UTC (permalink / raw)
  To: openembedded-core

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/lib/oe/tests/test_utils.py |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/meta/lib/oe/tests/test_utils.py b/meta/lib/oe/tests/test_utils.py
index 779247a..8bb36f2 100644
--- a/meta/lib/oe/tests/test_utils.py
+++ b/meta/lib/oe/tests/test_utils.py
@@ -1,5 +1,5 @@
 import unittest
-import oe.utils
+from oe.utils import packages_filter_out_system
 
 class TestPackagesFilterOutSystem(unittest.TestCase):
     def test_filter(self):
@@ -15,17 +15,17 @@ class TestPackagesFilterOutSystem(unittest.TestCase):
         d.setVar("PN", "foo")
 
         d.setVar("PACKAGES", "foo foo-doc foo-dev")
-        pkgs = oe.utils.packages_filter_out_system(d)
+        pkgs = packages_filter_out_system(d)
         self.assertEqual(pkgs, [])
 
         d.setVar("PACKAGES", "foo foo-doc foo-data foo-dev")
-        pkgs = oe.utils.packages_filter_out_system(d)
+        pkgs = packages_filter_out_system(d)
         self.assertEqual(pkgs, ["foo-data"])
 
         d.setVar("PACKAGES", "foo foo-locale-en-gb")
-        pkgs = oe.utils.packages_filter_out_system(d)
+        pkgs = packages_filter_out_system(d)
         self.assertEqual(pkgs, [])
 
         d.setVar("PACKAGES", "foo foo-data foo-locale-en-gb")
-        pkgs = oe.utils.packages_filter_out_system(d)
+        pkgs = packages_filter_out_system(d)
         self.assertEqual(pkgs, ["foo-data"])
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] utils: add trim_version() function
  2013-05-23 18:44 [PATCH 1/3] test-utils: handle import bb failing and skip the test Ross Burton
  2013-05-23 18:45 ` [PATCH 2/3] test_utils: import functions directly for conciseness Ross Burton
@ 2013-05-23 18:45 ` Ross Burton
  2013-05-23 21:16   ` Chris Larson
  2013-05-30 19:49 ` [PATCH 1/3] test-utils: handle import bb failing and skip the test Richard Purdie
  2 siblings, 1 reply; 5+ messages in thread
From: Ross Burton @ 2013-05-23 18:45 UTC (permalink / raw)
  To: openembedded-core

Add a helper function that returns just the first <num_parts> of <version>,
split by periods.  For example, trim_version("1.2.3", 2) will return "1.2".

This should help reduce the spread of numerous copies of this idea across
classes and recipes.

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/lib/oe/tests/test_utils.py |   20 ++++++++++++++++++++
 meta/lib/oe/utils.py            |   15 +++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/meta/lib/oe/tests/test_utils.py b/meta/lib/oe/tests/test_utils.py
index 8bb36f2..5d9ac52 100644
--- a/meta/lib/oe/tests/test_utils.py
+++ b/meta/lib/oe/tests/test_utils.py
@@ -29,3 +29,23 @@ class TestPackagesFilterOutSystem(unittest.TestCase):
         d.setVar("PACKAGES", "foo foo-data foo-locale-en-gb")
         pkgs = packages_filter_out_system(d)
         self.assertEqual(pkgs, ["foo-data"])
+
+
+class TestTrimVersion(unittest.TestCase):
+    def test_version_exception(self):
+        with self.assertRaises(TypeError):
+            trim_version(None, 2)
+        with self.assertRaises(TypeError):
+            trim_version((1, 2, 3), 2)
+
+    def test_num_exception(self):
+        with self.assertRaises(ValueError):
+            trim_version("1.2.3", 0)
+        with self.assertRaises(ValueError):
+            trim_version("1.2.3", -1)
+
+    def test_valid(self):
+        self.assertEqual(trim_version("1.2.3", 1), "1")
+        self.assertEqual(trim_version("1.2.3", 2), "1.2")
+        self.assertEqual(trim_version("1.2.3", 3), "1.2.3")
+        self.assertEqual(trim_version("1.2.3", 4), "1.2.3")
diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
index 0a2092b..82987e8 100644
--- a/meta/lib/oe/utils.py
+++ b/meta/lib/oe/utils.py
@@ -135,3 +135,18 @@ def packages_filter_out_system(d):
 
 def getstatusoutput(cmd):
     return cmdstatus.getstatusoutput(cmd)
+
+
+def trim_version(version, num_parts=2):
+    """
+    Return just the first <num_parts> of <version>, split by periods.  For
+    example, trim_version("1.2.3", 2) will return "1.2".
+    """
+    if type(version) is not str:
+        raise TypeError("Version should be a string")
+    if num_parts < 1:
+        raise ValueError("Cannot split to parts < 1")
+
+    parts = version.split(".")
+    trimmed = ".".join(parts[:num_parts])
+    return trimmed
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/3] utils: add trim_version() function
  2013-05-23 18:45 ` [PATCH 3/3] utils: add trim_version() function Ross Burton
@ 2013-05-23 21:16   ` Chris Larson
  0 siblings, 0 replies; 5+ messages in thread
From: Chris Larson @ 2013-05-23 21:16 UTC (permalink / raw)
  To: Ross Burton; +Cc: Patches and discussions about the oe-core layer

[-- Attachment #1: Type: text/plain, Size: 915 bytes --]

On Thu, May 23, 2013 at 11:45 AM, Ross Burton <ross.burton@intel.com> wrote:

> +def trim_version(version, num_parts=2):
> +    """
> +    Return just the first <num_parts> of <version>, split by periods.  For
> +    example, trim_version("1.2.3", 2) will return "1.2".
> +    """
> +    if type(version) is not str:
> +        raise TypeError("Version should be a string")
> +    if num_parts < 1:
> +        raise ValueError("Cannot split to parts < 1")
> +
> +    parts = version.split(".")
> +    trimmed = ".".join(parts[:num_parts])
> +    return trimmed
>

Another option would be to do something like:

def trim_version(version, num_parts=2):
    v = distutils.version.LooseVersion(version)
    return v.version[:num_parts]
-- 
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics

[-- Attachment #2: Type: text/html, Size: 1576 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] test-utils: handle import bb failing and skip the test
  2013-05-23 18:44 [PATCH 1/3] test-utils: handle import bb failing and skip the test Ross Burton
  2013-05-23 18:45 ` [PATCH 2/3] test_utils: import functions directly for conciseness Ross Burton
  2013-05-23 18:45 ` [PATCH 3/3] utils: add trim_version() function Ross Burton
@ 2013-05-30 19:49 ` Richard Purdie
  2 siblings, 0 replies; 5+ messages in thread
From: Richard Purdie @ 2013-05-30 19:49 UTC (permalink / raw)
  To: Ross Burton; +Cc: openembedded-core

On Thu, 2013-05-23 at 19:44 +0100, Ross Burton wrote:
> Instead of reporting an error when bb cannot be imported, skip the test
> instead. This makes it a lot easier to iterate a test suite when we don't care
> about this particular test.
> 
> Signed-off-by: Ross Burton <ross.burton@intel.com>
> ---
>  meta/lib/oe/tests/test_utils.py |    6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/meta/lib/oe/tests/test_utils.py b/meta/lib/oe/tests/test_utils.py
> index 466c47e..779247a 100644
> --- a/meta/lib/oe/tests/test_utils.py
> +++ b/meta/lib/oe/tests/test_utils.py
> @@ -1,11 +1,15 @@
>  import unittest
> -import bb, oe.utils
> +import oe.utils
>  
>  class TestPackagesFilterOutSystem(unittest.TestCase):
>      def test_filter(self):
>          """
>          Test that oe.utils.packages_filter_out_system works.
>          """
> +        try:
> +            import bb
> +        except ImportError:
> +            self.skipTest("Cannot import bb")
>  
>          d = bb.data_smart.DataSmart()
>          d.setVar("PN", "foo")

This a python 2.7ism :(

For various reasons we should really add unittest from python 2.7 into
bitbake and solve this problem that way once and for all. I appreciate
that adds a hard dependency on using bitbake but OE isn't much use
without it...

Cheers,

Richard



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-05-30 19:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-23 18:44 [PATCH 1/3] test-utils: handle import bb failing and skip the test Ross Burton
2013-05-23 18:45 ` [PATCH 2/3] test_utils: import functions directly for conciseness Ross Burton
2013-05-23 18:45 ` [PATCH 3/3] utils: add trim_version() function Ross Burton
2013-05-23 21:16   ` Chris Larson
2013-05-30 19:49 ` [PATCH 1/3] test-utils: handle import bb failing and skip the test Richard Purdie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox