зеркало из https://github.com/microsoft/InQRy.git
major updates
- added new modules "systemspecs" and "system_profiler" to differentiate between different functions - implemented the use of pytest fixtures - several renames
This commit is contained in:
Родитель
b776ef7afb
Коммит
18f6815ddb
|
@ -18,8 +18,5 @@ def _get_system_profiler_output(arguments=None):
|
|||
|
||||
|
||||
def _hardware_parser(system_profiler_output):
|
||||
hardware_dict = yaml.load(system_profiler_output)
|
||||
try:
|
||||
return hardware_dict['Hardware']['Hardware Overview']
|
||||
except:
|
||||
raise KeyError("Keys 'Hardware' and 'Hardware Overview' do not exist")
|
||||
return yaml.safe_load(system_profiler_output)['Hardware'][
|
||||
'Hardware Overview']
|
||||
|
|
|
@ -12,13 +12,13 @@ from inqry import system_profiler
|
|||
# import linux_sysinfo as sysinfo
|
||||
# etc
|
||||
|
||||
def mac_hardware():
|
||||
# return create_specs_from_system_profiler_hardware_output(
|
||||
return system_profiler.hardware()
|
||||
def create_specs_from_system_profiler_hardware_output(output):
|
||||
return SystemSpecs(output)
|
||||
|
||||
|
||||
# def create_specs_from_system_profiler_hardware_output(output):
|
||||
# return SystemSpecs(yaml.load(output))
|
||||
def get_mac_hardware():
|
||||
return create_specs_from_system_profiler_hardware_output(
|
||||
system_profiler.hardware())
|
||||
|
||||
|
||||
def mac_storage():
|
||||
|
@ -47,62 +47,57 @@ class SystemSpecs(object):
|
|||
A SystemSpecs object should also be able to be used the same way,
|
||||
regardless of which operating system the specs were generated from"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, attributes):
|
||||
"""TODO"""
|
||||
self.os_type = platform.system()
|
||||
|
||||
def operating_system(self):
|
||||
if self.os_type == 'Darwin':
|
||||
mac_hardware()
|
||||
elif self.os_type == 'Windows':
|
||||
windows()
|
||||
else:
|
||||
raise OSError(
|
||||
'{os}: Unknown operating system'.format(os=self.os_type))
|
||||
self.attributes = attributes
|
||||
|
||||
def storage(self):
|
||||
pass
|
||||
|
||||
def operating_system(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def serial(self):
|
||||
# assert isinstance(serial, str)
|
||||
return mac_hardware().get('Serial Number (system)')
|
||||
return self.attributes.get('Serial Number (system)')
|
||||
|
||||
@property
|
||||
def cpu_name(self):
|
||||
name = mac_hardware().get('Processor Name')
|
||||
name = self.attributes.get('Processor Name')
|
||||
assert isinstance(name, str)
|
||||
return name
|
||||
|
||||
@property
|
||||
def cpu_processors(self):
|
||||
processors = mac_hardware().get('Number of Processors')
|
||||
processors = self.attributes.get('Number of Processors')
|
||||
assert isinstance(processors, int)
|
||||
return processors
|
||||
|
||||
@property
|
||||
def cpu_cores(self):
|
||||
cores = mac_hardware().get('Total Number of Cores')
|
||||
cores = self.attributes.get('Total Number of Cores')
|
||||
assert isinstance(cores, int)
|
||||
return cores
|
||||
|
||||
@property
|
||||
def cpu_speed(self):
|
||||
speed = mac_hardware().get('Processor Speed')
|
||||
speed = self.attributes.get('Processor Speed')
|
||||
assert isinstance(speed, str)
|
||||
return speed
|
||||
|
||||
@property
|
||||
def memory(self):
|
||||
memory = mac_hardware().get('Memory')
|
||||
memory = self.attributes.get('Memory')
|
||||
return memory
|
||||
|
||||
@property
|
||||
def model(self):
|
||||
model = mac_hardware().get('Model Identifier')
|
||||
model = self.attributes.get('Model Identifier')
|
||||
return model
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
name = mac_hardware().get('Model Name')
|
||||
name = self.attributes.get('Model Name')
|
||||
return name
|
|
@ -1,83 +1,109 @@
|
|||
import pytest
|
||||
from inqry.asset import Asset
|
||||
from inqry.system_summary import SystemSpecs
|
||||
|
||||
sp = SystemSpecs()
|
||||
asset = Asset(sp)
|
||||
from inqry.systemspecs import SystemSpecs
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_instantiating_system_specs(profile_fixture):
|
||||
SystemSpecs(profile_fixture)
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_instantiating_asset():
|
||||
Asset()
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_empty_asset_instantiation_works():
|
||||
Asset(sp)
|
||||
Asset()
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_empty_asset_is_not_valid():
|
||||
assert not asset.is_valid()
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_presence_of_cpu_name_attribute():
|
||||
assert hasattr(asset, 'cpu_name')
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_cpu_attribute_is_tuple():
|
||||
assert isinstance(asset.cpu_name, str)
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_presence_of_cpu_speed_attribute():
|
||||
assert hasattr(asset, 'cpu_speed')
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_cpu_speed_is_integer():
|
||||
assert isinstance(asset.cpu_speed, str)
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_presence_of_cpu_processors_attribute():
|
||||
assert hasattr(asset, 'cpu_processors')
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_cpu_processor_is_string():
|
||||
assert isinstance(asset.cpu_processors, int)
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_presence_of_cpu_cores_attribute():
|
||||
assert hasattr(asset, 'cpu_cores')
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_cpu_cores_is_integer():
|
||||
assert isinstance(asset.cpu_cores, int)
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_presence_of_memory_attribute():
|
||||
assert hasattr(asset, 'memory')
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_memory_attribute_is_string():
|
||||
assert isinstance(asset.memory, str)
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_presence_of_serial_attribute():
|
||||
assert hasattr(asset, 'serial')
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_serial_attribute_is_string():
|
||||
assert isinstance(asset.serial, str)
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_presence_of_name_attribute():
|
||||
assert hasattr(asset, 'name')
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_name_attribute_is_string():
|
||||
assert isinstance(asset.model, str)
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_presence_of_model_attribute():
|
||||
assert hasattr(asset, 'model')
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_model_attribute_is_string():
|
||||
assert isinstance(asset.model, str)
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_serial_is_correct_length():
|
||||
assert len(asset.serial) == 12
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
import pytest
|
||||
from inqry import system_profiler
|
||||
from inqry.system_summary import SystemSpecs
|
||||
|
||||
|
||||
# system_profiler_hardware_data_type_output = """
|
||||
# Hardware:
|
||||
#
|
||||
# Hardware Overview:
|
||||
#
|
||||
# Model Name: Mac Pro
|
||||
# Model Identifier: MacPro6,1
|
||||
# Processor Name: Quad-Core Intel Xeon E5
|
||||
# Processor Speed: 3.7 GHz
|
||||
# Number of Processors: 1
|
||||
# Total Number of Cores: 4
|
||||
# L2 Cache (per Core): 256 KB
|
||||
# L3 Cache: 10 MB
|
||||
# Memory: 32 GB
|
||||
# Boot ROM Version: MP61.0116.B21
|
||||
# SMC Version (system): 2.20f18
|
||||
# Illumination Version: 1.4a6
|
||||
# Serial Number (system): F5KQH0P9F9VN
|
||||
# Hardware UUID: 4D4C19C7-19C4-5678-A936-A419C4609AFD"""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def system_profiler_hardware_data_type_output():
|
||||
return system_profiler.hardware()
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_parsing_fixture(system_profiler_hardware_data_type_output):
|
||||
pass
|
|
@ -0,0 +1,87 @@
|
|||
import pytest
|
||||
from inqry import system_profiler
|
||||
from inqry import systemspecs
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@pytest.fixture(scope="session")
|
||||
def hw_data_fixture():
|
||||
"""Used as data for testing with system profiler output"""
|
||||
return system_profiler.hardware()
|
||||
|
||||
|
||||
# noinspection PyShadowingNames,PyUnusedLocal
|
||||
@pytest.fixture(scope="session")
|
||||
def profile_fixture(hw_data_fixture):
|
||||
"""Used as data for testing with a system profiler object"""
|
||||
return systemspecs.create_specs_from_system_profiler_hardware_output(
|
||||
hw_data_fixture)
|
||||
|
||||
|
||||
# noinspection PyShadowingNames
|
||||
def test_getting_value_from_key(hw_data_fixture):
|
||||
assert hw_data_fixture.get('Boot ROM Version') == 'MBP112.0138.B21'
|
||||
|
||||
|
||||
# noinspection PyShadowingNames
|
||||
def test_profile_instantiation_works():
|
||||
systemspecs.SystemSpecs(hw_data_fixture)
|
||||
|
||||
|
||||
# noinspection PyShadowingNames
|
||||
def test_operating_system_attribute(profile_fixture):
|
||||
assert hasattr(profile_fixture, "operating_system")
|
||||
|
||||
|
||||
# noinspection PyShadowingNames
|
||||
def test_that_system_profile_object_has_storage_attribute(profile_fixture):
|
||||
assert hasattr(profile_fixture, "storage")
|
||||
|
||||
|
||||
# noinspection PyShadowingNames
|
||||
def test_that_system_profile_object_has_serial_attribute(profile_fixture):
|
||||
assert hasattr(profile_fixture, "serial")
|
||||
|
||||
|
||||
# noinspection PyShadowingNames
|
||||
def test_that_system_profile_object_has_cpu_name_attribute(profile_fixture):
|
||||
assert hasattr(profile_fixture, "cpu_name")
|
||||
|
||||
|
||||
# noinspection PyShadowingNames
|
||||
def test_that_system_profile_object_has_cpu_speed_attribute(profile_fixture):
|
||||
assert hasattr(profile_fixture, "cpu_speed")
|
||||
|
||||
|
||||
# noinspection PyShadowingNames
|
||||
def test_that_system_profile_object_has_cpu_processors_attribute(
|
||||
profile_fixture):
|
||||
assert hasattr(profile_fixture, "cpu_processors")
|
||||
|
||||
|
||||
# noinspection PyShadowingNames
|
||||
def test_system_profiler_has_os_type_attribute(profile_fixture):
|
||||
assert bool(profile_fixture.os_type) is True
|
||||
|
||||
|
||||
# noinspection PyShadowingNames
|
||||
@pytest.mark.skip
|
||||
def test_operating_system_fails_when_os_is_not_darwin_or_windows(
|
||||
profile_fixture):
|
||||
profile_fixture.os_type = 'Linux'
|
||||
with pytest.raises(OSError):
|
||||
profile_fixture.operating_system()
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_when_ios_device_is_connected():
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_ability_to_get_components_from_system_profile_object():
|
||||
pass
|
||||
|
||||
|
||||
def test_mac_hardware_method_output_data_type_is_system_specs_class():
|
||||
assert isinstance(systemspecs.get_mac_hardware(), systemspecs.SystemSpecs)
|
|
@ -1,114 +0,0 @@
|
|||
import pytest
|
||||
from inqry.system_summary import SystemSpecs, mac_hardware
|
||||
|
||||
hardware_test_data_as_dict = {
|
||||
'Hardware':
|
||||
{
|
||||
'Hardware Overview':
|
||||
{
|
||||
'Model Name': 'MacBook Pro',
|
||||
'Model Identifier': 'MacBookPro11,2',
|
||||
'Processor Name': 'Intel Core i7',
|
||||
'Processor Speed': '2.2 GHz',
|
||||
'Number of Processors': 1,
|
||||
'Total Number of Cores': 4,
|
||||
'L2 Cache (per Core)': '256 KB',
|
||||
'L3 Cache': '6 MB', 'Memory': '16 GB',
|
||||
'Boot ROM Version': 'MBP112.0138.B21',
|
||||
'SMC Version (system)': '2.18f15',
|
||||
'Serial Number (system)': 'C02NT9WJG3QC',
|
||||
'Hardware UUID': '7BE2608D-6373-52C7-B5FB-442C261A71A4'}}}
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_empty_profile_instantiation_works():
|
||||
SystemSpecs()
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_that_system_profile_object_operating_system_attribute():
|
||||
sp = SystemSpecs()
|
||||
assert hasattr(sp, "operating_system")
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_that_system_profile_object_has_storage_attribute():
|
||||
sp = SystemSpecs()
|
||||
assert hasattr(sp, "storage")
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_that_system_profile_object_has_serial_attribute():
|
||||
sp = SystemSpecs()
|
||||
assert hasattr(sp, "serial")
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_that_system_profile_object_has_cpu_name_attribute():
|
||||
sp = SystemSpecs()
|
||||
assert hasattr(sp, "cpu_name")
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_that_system_profile_object_has_cpu_speed_attribute():
|
||||
sp = SystemSpecs()
|
||||
assert hasattr(sp, "cpu_speed")
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_that_system_profile_object_has_cpu_processors_attribute():
|
||||
sp = SystemSpecs()
|
||||
assert hasattr(sp, "cpu_processors")
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_that_system_profile_object_has_cpu_cores_attribute():
|
||||
sp = SystemSpecs()
|
||||
assert hasattr(sp, "cpu_cores")
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_that_system_profile_object_has_model_attribute():
|
||||
sp = SystemSpecs()
|
||||
assert hasattr(sp, "model")
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_that_system_profile_object_has_name_attribute():
|
||||
sp = SystemSpecs()
|
||||
assert hasattr(sp, "name")
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_that_system_profile_object_has_memory_attribute():
|
||||
sp = SystemSpecs()
|
||||
assert hasattr(sp, "memory")
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_when_ios_device_is_connected():
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_ability_to_get_components_from_system_profile_object():
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_mac_hardware_method_output_data_type_is_dictionary():
|
||||
assert isinstance(mac_hardware(), dict)
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_system_profiler_has_os_type_attribute():
|
||||
sp = SystemSpecs()
|
||||
assert sp.os_type
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_operating_system_method_fails_when_operating_system_is_not_darwin_or_windows():
|
||||
sp = SystemSpecs()
|
||||
sp.os_type = 'Linux'
|
||||
with pytest.raises(OSError):
|
||||
sp.operating_system()
|
Загрузка…
Ссылка в новой задаче