Add check_traits function
The added function check_traits accepts an iteration of string and group them as standard traits set and other traits set.
This commit is contained in:
parent
87c5fa8601
commit
f04ae239f4
|
@ -62,3 +62,18 @@ def get_traits(prefix=None):
|
|||
v not in excluded_values and
|
||||
(prefix is None or v.startswith(prefix))
|
||||
]
|
||||
|
||||
|
||||
def check_traits(traits):
|
||||
"""
|
||||
Returns a tuple of two trait string sets, the first set contains valid
|
||||
traits, and the second contains others.
|
||||
|
||||
:param traits: An iterable contains trait strings.
|
||||
"""
|
||||
trait_set = set(traits)
|
||||
valid_trait_set = set(get_traits())
|
||||
|
||||
valid_traits = trait_set & valid_trait_set
|
||||
|
||||
return (valid_traits, trait_set - valid_traits)
|
||||
|
|
|
@ -43,3 +43,13 @@ class TestOs_traits(base.TestCase):
|
|||
traits = ot.get_traits(ot.NAMESPACES['x86'])
|
||||
self.assertIn("hw:cpu:x86:sse42", traits)
|
||||
self.assertEqual(35, len(traits))
|
||||
|
||||
def test_check_traits(self):
|
||||
traits = set(["hw:cpu:x86:sse42", "hw:cpu:x86:xop"])
|
||||
not_traits = set(["not_trait1", "not_trait2"])
|
||||
|
||||
check_traits = []
|
||||
check_traits.extend(traits)
|
||||
check_traits.extend(not_traits)
|
||||
self.assertEqual((traits, not_traits),
|
||||
ot.check_traits(check_traits))
|
||||
|
|
Loading…
Reference in New Issue