Browse Source

Tests for parsing of generic attribute rules

tags/0.4
Johann Schmitz 2 years ago
parent
commit
af48146cd0
1 changed files with 38 additions and 1 deletions
  1. 38
    1
      tests/check.py

+ 38
- 1
tests/check.py View File

@@ -1,7 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import unittest
3 3
 import os
4
-from smartcheck.check import SMARTCheck, AttributeWarning
4
+from smartcheck.check import SMARTCheck, AttributeWarning, parse_range_specifier
5 5
 
6 6
 samples_path = os.path.join(os.path.dirname(__file__), 'samples')
7 7
 db_path = os.path.join(samples_path, '../../smartcheck/disks.yaml')
@@ -180,3 +180,40 @@ ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_
180 180
             self.assertEqual(failed, {
181 181
                 (5, 'Reallocated_Sector_Ct'): AttributeWarning(AttributeWarning.Notice, 'Reallocated_Sector_Ct', 84)
182 182
             })
183
+
184
+    def test_parse_range_specifier(self):
185
+        # greater than
186
+        f = parse_range_specifier(1)
187
+        assert f(1) is False
188
+        assert f(2)
189
+
190
+        # greater than
191
+        f = parse_range_specifier('1')
192
+        assert f(1) is False
193
+        assert f(2)
194
+
195
+        # greater than
196
+        f = parse_range_specifier('1:')
197
+        assert f(1) is False
198
+        assert f(2)
199
+
200
+        # less than
201
+        f = parse_range_specifier(':2')
202
+        assert f(-11)
203
+        assert f(1)
204
+        assert f(2) is False
205
+
206
+        # range 'from:to' - including both ends as valid values
207
+        f = parse_range_specifier('1:2')
208
+        assert f(-1) is False
209
+        assert f(0) is False
210
+        assert f(1)
211
+        assert f(2)
212
+        assert f(3) is False
213
+
214
+        # invalid
215
+        f = parse_range_specifier('test')
216
+        assert f(0) is False
217
+        assert f(1) is False
218
+        assert f(2) is False
219
+

Loading…
Cancel
Save