-
Notifications
You must be signed in to change notification settings - Fork 35
/
test_device_list.py
63 lines (47 loc) · 1.92 KB
/
test_device_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright (C) 2021 Rafael Leira, Naudit HPCN S.L.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program 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 General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
################################################################
import json
import os
import pytest
from pySMART import Device, DeviceList
from pySMART.utils import get_object_properties
from .smartctlfile import SmartctlFile
# discover tests
single_device_tests_main_path = './tests/dataset/listingtests/'
folders = [single_device_tests_main_path +
p for p in os.listdir(single_device_tests_main_path)]
class TestListDevice():
def get_device_data(self, folder: str) -> dict:
try:
with open(os.path.join(folder, 'device.json')) as json_file:
data = json.load(json_file)
except:
data = {}
return data
def create_list_device(self, folder: str, data: dict) -> DeviceList:
sf = SmartctlFile(folder)
if 'init' not in data:
return DeviceList(smartctl=sf)
else:
return DeviceList(init=data['init'], smartctl=sf)
@pytest.mark.parametrize("folder", folders)
def test_list_devices(self, folder):
data = self.get_device_data(folder)
device_data: DeviceList = self.create_list_device(folder, data)
# Check that the number of devices is correct
assert len(device_data.devices) == data['count']