
Sean Mooney had a good idea that for future-proofing the os-traits library and ensuring that we don't have to deal with one giant const.py file, that we break the library into various modules corresponding to the higher-level namespaces. This patch adds some symbol-registration foo into a utils module and allows the os_traits module and "leaf modules" to be called in the following way: import os_traits from os_traits.hw.cpu import x86 assert os_traits.HW_CPU_X86_SSE42 == x86.SSE42 assert x86.SSE42 == 'HW_CPU_X86_SSE42' Change-Id: I0e8f50822ab67cb3be85ed3b935dd6cdb4436dbf
56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import os_traits as ot
|
|
from os_traits.hw.cpu import x86
|
|
from os_traits.tests import base
|
|
|
|
|
|
class TestSymbols(base.TestCase):
|
|
|
|
def test_trait(self):
|
|
"""Simply tests that the constants from submodules are imported into
|
|
the primary os_traits module space.
|
|
"""
|
|
trait = ot.HW_CPU_X86_SSE42
|
|
self.assertEqual("HW_CPU_X86_SSE42", trait)
|
|
|
|
# And the "leaf-module" namespace...
|
|
self.assertEqual(x86.SSE42, ot.HW_CPU_X86_SSE42)
|
|
|
|
def test_get_symbol_names(self):
|
|
names = ot.get_symbol_names()
|
|
self.assertIn("HW_CPU_X86_AVX2", names)
|
|
self.assertIn("STORAGE_DISK_SSD", names)
|
|
|
|
def test_get_traits(self):
|
|
traits = ot.get_traits('HW_CPU')
|
|
self.assertIn("HW_CPU_X86_SSE42", traits)
|
|
self.assertIn(ot.HW_CPU_X86_AVX2, traits)
|
|
self.assertNotIn(ot.STORAGE_DISK_SSD, 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))
|
|
|
|
def test_is_custom(self):
|
|
self.assertTrue(ot.is_custom('CUSTOM_FOO'))
|
|
self.assertFalse(ot.is_custom('HW_CPU_X86_SSE42'))
|