afscgap.test.test_flat_index_util
Tests for precomputed index filters.
(c) 2025 Regents of University of California / The Eric and Wendy Schmidt Center for Data Science and the Environment at UC Berkeley.
This file is part of afscgap released under the BSD 3-Clause License. See LICENSE.md.
1""" 2Tests for precomputed index filters. 3 4(c) 2025 Regents of University of California / The Eric and Wendy Schmidt Center 5for Data Science and the Environment at UC Berkeley. 6 7This file is part of afscgap released under the BSD 3-Clause License. See 8LICENSE.md. 9""" 10import unittest 11import unittest.mock 12 13import afscgap.flat_index_util 14import afscgap.param 15 16 17class StringEqIndexFilterTests(unittest.TestCase): 18 19 def setUp(self): 20 param = unittest.mock.MagicMock() 21 param.get_value = unittest.mock.MagicMock(return_value='test') 22 self._index_filter = afscgap.flat_index_util.StringEqIndexFilter('index', param) 23 24 def test_matches(self): 25 self.assertTrue(self._index_filter.get_matches('test')) 26 27 def test_not_matches(self): 28 self.assertFalse(self._index_filter.get_matches('other')) 29 30 def test_not_matches_case(self): 31 self.assertFalse(self._index_filter.get_matches('Test')) 32 33 def test_none(self): 34 self.assertFalse(self._index_filter.get_matches(None)) 35 36 37class StringRangeIndexFilterTests(unittest.TestCase): 38 39 def setUp(self): 40 param = unittest.mock.MagicMock() 41 param.get_low = unittest.mock.MagicMock(return_value='b') 42 param.get_high = unittest.mock.MagicMock(return_value='d') 43 self._index_filter = afscgap.flat_index_util.StringRangeIndexFilter('index', param) 44 45 def test_out_low(self): 46 self.assertFalse(self._index_filter.get_matches('a')) 47 48 def test_low(self): 49 self.assertTrue(self._index_filter.get_matches('b')) 50 51 def test_mid(self): 52 self.assertTrue(self._index_filter.get_matches('c')) 53 54 def test_high(self): 55 self.assertTrue(self._index_filter.get_matches('d')) 56 57 def test_out_high(self): 58 self.assertFalse(self._index_filter.get_matches('e')) 59 60 def test_none(self): 61 self.assertFalse(self._index_filter.get_matches(None)) 62 63 64class IntEqIndexFilterTests(unittest.TestCase): 65 66 def setUp(self): 67 param = unittest.mock.MagicMock() 68 param.get_value = unittest.mock.MagicMock(return_value=123) 69 self._index_filter = afscgap.flat_index_util.IntEqIndexFilter('index', param) 70 71 def test_matches(self): 72 self.assertTrue(self._index_filter.get_matches(123)) 73 74 def test_not_matches(self): 75 self.assertFalse(self._index_filter.get_matches(12)) 76 77 def test_none(self): 78 self.assertFalse(self._index_filter.get_matches(None)) 79 80 81class IntRangeIndexFilterTests(unittest.TestCase): 82 83 def setUp(self): 84 param = unittest.mock.MagicMock() 85 param.get_low = unittest.mock.MagicMock(return_value=2) 86 param.get_high = unittest.mock.MagicMock(return_value=4) 87 self._index_filter = afscgap.flat_index_util.IntRangeIndexFilter('index', param) 88 89 def test_out_low(self): 90 self.assertFalse(self._index_filter.get_matches(1)) 91 92 def test_low(self): 93 self.assertTrue(self._index_filter.get_matches(2)) 94 95 def test_mid(self): 96 self.assertTrue(self._index_filter.get_matches(3)) 97 98 def test_high(self): 99 self.assertTrue(self._index_filter.get_matches(4)) 100 101 def test_out_high(self): 102 self.assertFalse(self._index_filter.get_matches(5)) 103 104 def test_none(self): 105 self.assertFalse(self._index_filter.get_matches(None)) 106 107 108class FloatEqIndexFilterTests(unittest.TestCase): 109 110 def setUp(self): 111 param = unittest.mock.MagicMock() 112 param.get_value = unittest.mock.MagicMock(return_value=123.45) 113 self._index_filter = afscgap.flat_index_util.FloatEqIndexFilter('index', param) 114 115 def test_matches(self): 116 self.assertTrue(self._index_filter.get_matches(123.45)) 117 118 def test_not_matches(self): 119 self.assertFalse(self._index_filter.get_matches(12)) 120 121 def test_approx_not_matches(self): 122 self.assertFalse(self._index_filter.get_matches(123.4555)) 123 124 def test_approx_matches(self): 125 self.assertTrue(self._index_filter.get_matches(123.454)) 126 127 def test_none(self): 128 self.assertFalse(self._index_filter.get_matches(None)) 129 130 131class FloatRangeIndexFilterTests(unittest.TestCase): 132 133 def setUp(self): 134 param = unittest.mock.MagicMock() 135 param.get_low = unittest.mock.MagicMock(return_value=2.34) 136 param.get_high = unittest.mock.MagicMock(return_value=4.56) 137 self._index_filter = afscgap.flat_index_util.FloatRangeIndexFilter('index', param) 138 139 def test_out_low(self): 140 self.assertFalse(self._index_filter.get_matches(1)) 141 142 def test_low(self): 143 self.assertTrue(self._index_filter.get_matches(2.34)) 144 145 def test_low_approx_match(self): 146 self.assertTrue(self._index_filter.get_matches(2.3355)) 147 148 def test_low_approx_not_match(self): 149 self.assertFalse(self._index_filter.get_matches(2.3344)) 150 151 def test_mid(self): 152 self.assertTrue(self._index_filter.get_matches(3)) 153 154 def test_high(self): 155 self.assertTrue(self._index_filter.get_matches(4.56)) 156 157 def test_high_approx_match(self): 158 self.assertTrue(self._index_filter.get_matches(4.561)) 159 160 def test_high_approx_not_match(self): 161 self.assertFalse(self._index_filter.get_matches(4.5655)) 162 163 def test_out_high(self): 164 self.assertFalse(self._index_filter.get_matches(5)) 165 166 def test_none(self): 167 self.assertFalse(self._index_filter.get_matches(None)) 168 169 170class DatetimeEqIndexFilterTests(unittest.TestCase): 171 172 def setUp(self): 173 param = unittest.mock.MagicMock() 174 param.get_value = unittest.mock.MagicMock(return_value='2025-01-13T13:50:50Z') 175 self._index_filter = afscgap.flat_index_util.DatetimeEqIndexFilter('index', param) 176 177 def test_matches(self): 178 self.assertTrue(self._index_filter.get_matches('2025-01-13T13:50:50Z')) 179 180 def test_not_matches(self): 181 self.assertFalse(self._index_filter.get_matches('2025-02-13T13:50:50Z')) 182 183 def test_approx_not_matches(self): 184 self.assertFalse(self._index_filter.get_matches('2025-01-14T13:50:50Z')) 185 186 def test_approx_matches(self): 187 self.assertTrue(self._index_filter.get_matches('2025-01-13T14:50:50Z')) 188 189 def test_none(self): 190 self.assertFalse(self._index_filter.get_matches(None)) 191 192 193class DatetimeRangeIndexFilterTests(unittest.TestCase): 194 195 def setUp(self): 196 param = unittest.mock.MagicMock() 197 param.get_low = unittest.mock.MagicMock(return_value='2025-01-13T13:50:50Z') 198 param.get_high = unittest.mock.MagicMock(return_value='2025-03-13T13:50:50Z') 199 self._index_filter = afscgap.flat_index_util.DatetimeRangeIndexFilter('index', param) 200 201 def test_out_low(self): 202 self.assertFalse(self._index_filter.get_matches('2024-06-07T13:50:50Z')) 203 204 def test_low(self): 205 self.assertTrue(self._index_filter.get_matches('2025-01-13T13:50:50Z')) 206 207 def test_low_approx_match(self): 208 self.assertTrue(self._index_filter.get_matches('2025-01-13T14:50:50Z')) 209 210 def test_low_approx_not_match(self): 211 self.assertFalse(self._index_filter.get_matches('2025-01-12T13:50:50Z')) 212 213 def test_mid(self): 214 self.assertTrue(self._index_filter.get_matches('2025-02-13T14:50:50Z')) 215 216 def test_high(self): 217 self.assertTrue(self._index_filter.get_matches('2025-03-13T14:50:50Z')) 218 219 def test_high_approx_match(self): 220 self.assertTrue(self._index_filter.get_matches('2025-03-13T15:50:50Z')) 221 222 def test_high_approx_not_match(self): 223 self.assertFalse(self._index_filter.get_matches('2025-03-14T14:50:50Z')) 224 225 def test_out_high(self): 226 self.assertFalse(self._index_filter.get_matches('2025-04-13T14:50:50Z')) 227 228 def test_none(self): 229 self.assertFalse(self._index_filter.get_matches(None)) 230 231 232class UnitConversionIndexFilterTests(unittest.TestCase): 233 234 def setUp(self): 235 self._inner = unittest.mock.MagicMock() 236 self._inner.get_matches = lambda x: x is not None and abs(x - 10000) < 0.001 237 238 def test_noop_true(self): 239 index_filter = afscgap.flat_index_util.UnitConversionIndexFilter(self._inner, 'ha', 'ha') 240 self.assertTrue(index_filter.get_matches(10000)) 241 242 def test_noop_false(self): 243 index_filter = afscgap.flat_index_util.UnitConversionIndexFilter(self._inner, 'ha', 'ha') 244 self.assertFalse(index_filter.get_matches(20000)) 245 246 def test_noop_none(self): 247 index_filter = afscgap.flat_index_util.UnitConversionIndexFilter(self._inner, 'ha', 'ha') 248 self.assertFalse(index_filter.get_matches(None)) 249 250 def test_convert_true(self): 251 index_filter = afscgap.flat_index_util.UnitConversionIndexFilter(self._inner, 'm2', 'ha') 252 self.assertTrue(index_filter.get_matches(1)) 253 254 def test_convert_false(self): 255 index_filter = afscgap.flat_index_util.UnitConversionIndexFilter(self._inner, 'm2', 'ha') 256 self.assertFalse(index_filter.get_matches(2)) 257 258 def test_convert_none(self): 259 index_filter = afscgap.flat_index_util.UnitConversionIndexFilter(self._inner, 'm2', 'ha') 260 self.assertFalse(index_filter.get_matches(None)) 261 262 263class LogicalOrIndexFilterTests(unittest.TestCase): 264 265 def test_true_single(self): 266 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 267 self._make_inner_filter(1, 'test') 268 ]) 269 self.assertTrue(index_filter.get_matches(1)) 270 271 def test_true_multiple(self): 272 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 273 self._make_inner_filter(1, 'test'), 274 self._make_inner_filter(1, 'test') 275 ]) 276 self.assertTrue(index_filter.get_matches(1)) 277 278 def test_true_multiple_different(self): 279 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 280 self._make_inner_filter(1, 'test'), 281 self._make_inner_filter(2, 'test') 282 ]) 283 self.assertTrue(index_filter.get_matches(1)) 284 285 def test_false_single(self): 286 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 287 self._make_inner_filter(1, 'test') 288 ]) 289 self.assertFalse(index_filter.get_matches(2)) 290 291 def test_false_multiple(self): 292 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 293 self._make_inner_filter(1, 'test'), 294 self._make_inner_filter(1, 'test') 295 ]) 296 self.assertFalse(index_filter.get_matches(2)) 297 298 def test_empty(self): 299 with self.assertRaises(RuntimeError): 300 afscgap.flat_index_util.LogicalOrIndexFilter([]) 301 302 def test_unmatched(self): 303 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 304 self._make_inner_filter(1, 'test1'), 305 self._make_inner_filter(2, 'test2') 306 ]) 307 index_names = list(index_filter.get_index_names()) 308 self.assertEqual(len(index_names), 2) 309 self.assertTrue('test1' in index_names) 310 self.assertTrue('test2' in index_names) 311 312 def _make_inner_filter(self, value, index): 313 mock = unittest.mock.MagicMock() 314 mock.get_matches = lambda x: x == value 315 mock.get_index_names = unittest.mock.MagicMock(return_value=[index]) 316 return mock 317 318 319class DecorateFilterTests(unittest.TestCase): 320 321 def setUp(self): 322 self._inner = unittest.mock.MagicMock() 323 self._inner.get_matches = lambda x: x is not None and abs(x - 123) < 0.001 324 325 def test_decorate_filter_active_true(self): 326 decorated = afscgap.flat_index_util.decorate_filter('area_swept_ha', self._inner) 327 self.assertTrue(decorated.get_matches(12300)) 328 329 def test_decorate_filter_active_false(self): 330 decorated = afscgap.flat_index_util.decorate_filter('area_swept_ha', self._inner) 331 self.assertFalse(decorated.get_matches(12400)) 332 333 def test_decorate_filter_active_none(self): 334 decorated = afscgap.flat_index_util.decorate_filter('area_swept_ha', self._inner) 335 self.assertFalse(decorated.get_matches(None)) 336 337 def test_decorate_filter_active_true(self): 338 decorated = afscgap.flat_index_util.decorate_filter('other', self._inner) 339 self.assertTrue(decorated.get_matches(123)) 340 341 def test_decorate_filter_active_true(self): 342 decorated = afscgap.flat_index_util.decorate_filter('other', self._inner) 343 self.assertFalse(decorated.get_matches(124)) 344 345 def test_decorate_filter_active_none(self): 346 decorated = afscgap.flat_index_util.decorate_filter('other', self._inner) 347 self.assertFalse(decorated.get_matches(None)) 348 349 350class DetermineIfIgnorableTests(unittest.TestCase): 351 352 def test_explicit_ignorable_require_zero(self): 353 param = self._make_test_param(True, 'int') 354 ignorable = afscgap.flat_index_util.determine_if_ignorable('test', param, False) 355 self.assertTrue(ignorable) 356 357 def test_explicit_ignorable_presence_only(self): 358 param = self._make_test_param(True, 'int') 359 ignorable = afscgap.flat_index_util.determine_if_ignorable('test', param, True) 360 self.assertTrue(ignorable) 361 362 def test_require_zero_supported(self): 363 param = self._make_test_param(False, 'int') 364 ignorable = afscgap.flat_index_util.determine_if_ignorable('count', param, False) 365 self.assertFalse(ignorable) 366 367 def test_require_zero_unsupported(self): 368 param = self._make_test_param(False, 'str') 369 ignorable = afscgap.flat_index_util.determine_if_ignorable('species_code', param, False) 370 self.assertTrue(ignorable) 371 372 def test_presence_only_unsupported(self): 373 param = self._make_test_param(False, 'str') 374 ignorable = afscgap.flat_index_util.determine_if_ignorable('species_code', param, True) 375 self.assertFalse(ignorable) 376 377 def test_empty(self): 378 param = afscgap.param.EmptyParam() 379 ignorable = afscgap.flat_index_util.determine_if_ignorable('count', param, True) 380 self.assertTrue(ignorable) 381 382 def test_plain_not_ignorable(self): 383 param = afscgap.param.IntRangeParam(1, None) 384 ignorable = afscgap.flat_index_util.determine_if_ignorable('count', param, True) 385 self.assertFalse(ignorable) 386 387 def _make_test_param(self, ignorable, filter_type): 388 param = unittest.mock.MagicMock() 389 param.get_is_ignorable = unittest.mock.MagicMock(return_value=ignorable) 390 param.get_filter_type = unittest.mock.MagicMock(return_value=filter_type) 391 return param 392 393 394class MakeFilterTests(unittest.TestCase): 395 396 def test_empty(self): 397 param = afscgap.param.EmptyParam() 398 filters = afscgap.flat_index_util.make_filters('test', param, True) 399 self.assertEqual(len(filters), 0) 400 401 def test_string_true(self): 402 param = afscgap.param.StrEqualsParam('test') 403 filters = afscgap.flat_index_util.make_filters('common_name', param, True) 404 self.assertEqual(len(filters), 1) 405 self.assertTrue(filters[0].get_matches('test')) 406 407 def test_string_false(self): 408 param = afscgap.param.StrEqualsParam('test') 409 filters = afscgap.flat_index_util.make_filters('common_name', param, True) 410 self.assertEqual(len(filters), 1) 411 self.assertFalse(filters[0].get_matches('other')) 412 413 def test_presence_only(self): 414 param = afscgap.param.StrEqualsParam('test') 415 filters = afscgap.flat_index_util.make_filters('common_name', param, False) 416 self.assertEqual(len(filters), 0) 417 418 def test_int_true(self): 419 param = afscgap.param.IntEqualsParam(1) 420 filters = afscgap.flat_index_util.make_filters('vessel_id', param, True) 421 self.assertEqual(len(filters), 1) 422 self.assertTrue(filters[0].get_matches(1)) 423 424 def test_int_false(self): 425 param = afscgap.param.IntEqualsParam(1) 426 filters = afscgap.flat_index_util.make_filters('vessel_id', param, True) 427 self.assertEqual(len(filters), 1) 428 self.assertFalse(filters[0].get_matches(2)) 429 430 def test_float_true(self): 431 param = afscgap.param.FloatEqualsParam(1.234) 432 filters = afscgap.flat_index_util.make_filters('latitude_dd', param, True) 433 self.assertEqual(len(filters), 1) 434 self.assertTrue(filters[0].get_matches(1.233)) 435 436 def test_float_false(self): 437 param = afscgap.param.FloatEqualsParam(1.234) 438 filters = afscgap.flat_index_util.make_filters('latitude_dd', param, True) 439 self.assertEqual(len(filters), 1) 440 self.assertFalse(filters[0].get_matches(1.2355)) 441 442 def test_unit_conversion_true(self): 443 param = afscgap.param.FloatEqualsParam(1) 444 filters = afscgap.flat_index_util.make_filters('area_swept_ha', param, True) 445 self.assertEqual(len(filters), 1) 446 self.assertTrue(filters[0].get_matches(0.01)) 447 448 def test_unit_conversion_false(self): 449 param = afscgap.param.FloatEqualsParam(1) 450 filters = afscgap.flat_index_util.make_filters('area_swept_ha', param, True) 451 self.assertEqual(len(filters), 1) 452 self.assertFalse(filters[0].get_matches(0.02)) 453 454 def test_unknown_field(self): 455 param = afscgap.param.FloatEqualsParam(1) 456 filters = afscgap.flat_index_util.make_filters('other', param, True) 457 self.assertEqual(len(filters), 0)
18class StringEqIndexFilterTests(unittest.TestCase): 19 20 def setUp(self): 21 param = unittest.mock.MagicMock() 22 param.get_value = unittest.mock.MagicMock(return_value='test') 23 self._index_filter = afscgap.flat_index_util.StringEqIndexFilter('index', param) 24 25 def test_matches(self): 26 self.assertTrue(self._index_filter.get_matches('test')) 27 28 def test_not_matches(self): 29 self.assertFalse(self._index_filter.get_matches('other')) 30 31 def test_not_matches_case(self): 32 self.assertFalse(self._index_filter.get_matches('Test')) 33 34 def test_none(self): 35 self.assertFalse(self._index_filter.get_matches(None))
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
20 def setUp(self): 21 param = unittest.mock.MagicMock() 22 param.get_value = unittest.mock.MagicMock(return_value='test') 23 self._index_filter = afscgap.flat_index_util.StringEqIndexFilter('index', param)
Hook method for setting up the test fixture before exercising it.
38class StringRangeIndexFilterTests(unittest.TestCase): 39 40 def setUp(self): 41 param = unittest.mock.MagicMock() 42 param.get_low = unittest.mock.MagicMock(return_value='b') 43 param.get_high = unittest.mock.MagicMock(return_value='d') 44 self._index_filter = afscgap.flat_index_util.StringRangeIndexFilter('index', param) 45 46 def test_out_low(self): 47 self.assertFalse(self._index_filter.get_matches('a')) 48 49 def test_low(self): 50 self.assertTrue(self._index_filter.get_matches('b')) 51 52 def test_mid(self): 53 self.assertTrue(self._index_filter.get_matches('c')) 54 55 def test_high(self): 56 self.assertTrue(self._index_filter.get_matches('d')) 57 58 def test_out_high(self): 59 self.assertFalse(self._index_filter.get_matches('e')) 60 61 def test_none(self): 62 self.assertFalse(self._index_filter.get_matches(None))
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
40 def setUp(self): 41 param = unittest.mock.MagicMock() 42 param.get_low = unittest.mock.MagicMock(return_value='b') 43 param.get_high = unittest.mock.MagicMock(return_value='d') 44 self._index_filter = afscgap.flat_index_util.StringRangeIndexFilter('index', param)
Hook method for setting up the test fixture before exercising it.
65class IntEqIndexFilterTests(unittest.TestCase): 66 67 def setUp(self): 68 param = unittest.mock.MagicMock() 69 param.get_value = unittest.mock.MagicMock(return_value=123) 70 self._index_filter = afscgap.flat_index_util.IntEqIndexFilter('index', param) 71 72 def test_matches(self): 73 self.assertTrue(self._index_filter.get_matches(123)) 74 75 def test_not_matches(self): 76 self.assertFalse(self._index_filter.get_matches(12)) 77 78 def test_none(self): 79 self.assertFalse(self._index_filter.get_matches(None))
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
67 def setUp(self): 68 param = unittest.mock.MagicMock() 69 param.get_value = unittest.mock.MagicMock(return_value=123) 70 self._index_filter = afscgap.flat_index_util.IntEqIndexFilter('index', param)
Hook method for setting up the test fixture before exercising it.
82class IntRangeIndexFilterTests(unittest.TestCase): 83 84 def setUp(self): 85 param = unittest.mock.MagicMock() 86 param.get_low = unittest.mock.MagicMock(return_value=2) 87 param.get_high = unittest.mock.MagicMock(return_value=4) 88 self._index_filter = afscgap.flat_index_util.IntRangeIndexFilter('index', param) 89 90 def test_out_low(self): 91 self.assertFalse(self._index_filter.get_matches(1)) 92 93 def test_low(self): 94 self.assertTrue(self._index_filter.get_matches(2)) 95 96 def test_mid(self): 97 self.assertTrue(self._index_filter.get_matches(3)) 98 99 def test_high(self): 100 self.assertTrue(self._index_filter.get_matches(4)) 101 102 def test_out_high(self): 103 self.assertFalse(self._index_filter.get_matches(5)) 104 105 def test_none(self): 106 self.assertFalse(self._index_filter.get_matches(None))
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
84 def setUp(self): 85 param = unittest.mock.MagicMock() 86 param.get_low = unittest.mock.MagicMock(return_value=2) 87 param.get_high = unittest.mock.MagicMock(return_value=4) 88 self._index_filter = afscgap.flat_index_util.IntRangeIndexFilter('index', param)
Hook method for setting up the test fixture before exercising it.
109class FloatEqIndexFilterTests(unittest.TestCase): 110 111 def setUp(self): 112 param = unittest.mock.MagicMock() 113 param.get_value = unittest.mock.MagicMock(return_value=123.45) 114 self._index_filter = afscgap.flat_index_util.FloatEqIndexFilter('index', param) 115 116 def test_matches(self): 117 self.assertTrue(self._index_filter.get_matches(123.45)) 118 119 def test_not_matches(self): 120 self.assertFalse(self._index_filter.get_matches(12)) 121 122 def test_approx_not_matches(self): 123 self.assertFalse(self._index_filter.get_matches(123.4555)) 124 125 def test_approx_matches(self): 126 self.assertTrue(self._index_filter.get_matches(123.454)) 127 128 def test_none(self): 129 self.assertFalse(self._index_filter.get_matches(None))
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
111 def setUp(self): 112 param = unittest.mock.MagicMock() 113 param.get_value = unittest.mock.MagicMock(return_value=123.45) 114 self._index_filter = afscgap.flat_index_util.FloatEqIndexFilter('index', param)
Hook method for setting up the test fixture before exercising it.
132class FloatRangeIndexFilterTests(unittest.TestCase): 133 134 def setUp(self): 135 param = unittest.mock.MagicMock() 136 param.get_low = unittest.mock.MagicMock(return_value=2.34) 137 param.get_high = unittest.mock.MagicMock(return_value=4.56) 138 self._index_filter = afscgap.flat_index_util.FloatRangeIndexFilter('index', param) 139 140 def test_out_low(self): 141 self.assertFalse(self._index_filter.get_matches(1)) 142 143 def test_low(self): 144 self.assertTrue(self._index_filter.get_matches(2.34)) 145 146 def test_low_approx_match(self): 147 self.assertTrue(self._index_filter.get_matches(2.3355)) 148 149 def test_low_approx_not_match(self): 150 self.assertFalse(self._index_filter.get_matches(2.3344)) 151 152 def test_mid(self): 153 self.assertTrue(self._index_filter.get_matches(3)) 154 155 def test_high(self): 156 self.assertTrue(self._index_filter.get_matches(4.56)) 157 158 def test_high_approx_match(self): 159 self.assertTrue(self._index_filter.get_matches(4.561)) 160 161 def test_high_approx_not_match(self): 162 self.assertFalse(self._index_filter.get_matches(4.5655)) 163 164 def test_out_high(self): 165 self.assertFalse(self._index_filter.get_matches(5)) 166 167 def test_none(self): 168 self.assertFalse(self._index_filter.get_matches(None))
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
134 def setUp(self): 135 param = unittest.mock.MagicMock() 136 param.get_low = unittest.mock.MagicMock(return_value=2.34) 137 param.get_high = unittest.mock.MagicMock(return_value=4.56) 138 self._index_filter = afscgap.flat_index_util.FloatRangeIndexFilter('index', param)
Hook method for setting up the test fixture before exercising it.
171class DatetimeEqIndexFilterTests(unittest.TestCase): 172 173 def setUp(self): 174 param = unittest.mock.MagicMock() 175 param.get_value = unittest.mock.MagicMock(return_value='2025-01-13T13:50:50Z') 176 self._index_filter = afscgap.flat_index_util.DatetimeEqIndexFilter('index', param) 177 178 def test_matches(self): 179 self.assertTrue(self._index_filter.get_matches('2025-01-13T13:50:50Z')) 180 181 def test_not_matches(self): 182 self.assertFalse(self._index_filter.get_matches('2025-02-13T13:50:50Z')) 183 184 def test_approx_not_matches(self): 185 self.assertFalse(self._index_filter.get_matches('2025-01-14T13:50:50Z')) 186 187 def test_approx_matches(self): 188 self.assertTrue(self._index_filter.get_matches('2025-01-13T14:50:50Z')) 189 190 def test_none(self): 191 self.assertFalse(self._index_filter.get_matches(None))
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
173 def setUp(self): 174 param = unittest.mock.MagicMock() 175 param.get_value = unittest.mock.MagicMock(return_value='2025-01-13T13:50:50Z') 176 self._index_filter = afscgap.flat_index_util.DatetimeEqIndexFilter('index', param)
Hook method for setting up the test fixture before exercising it.
194class DatetimeRangeIndexFilterTests(unittest.TestCase): 195 196 def setUp(self): 197 param = unittest.mock.MagicMock() 198 param.get_low = unittest.mock.MagicMock(return_value='2025-01-13T13:50:50Z') 199 param.get_high = unittest.mock.MagicMock(return_value='2025-03-13T13:50:50Z') 200 self._index_filter = afscgap.flat_index_util.DatetimeRangeIndexFilter('index', param) 201 202 def test_out_low(self): 203 self.assertFalse(self._index_filter.get_matches('2024-06-07T13:50:50Z')) 204 205 def test_low(self): 206 self.assertTrue(self._index_filter.get_matches('2025-01-13T13:50:50Z')) 207 208 def test_low_approx_match(self): 209 self.assertTrue(self._index_filter.get_matches('2025-01-13T14:50:50Z')) 210 211 def test_low_approx_not_match(self): 212 self.assertFalse(self._index_filter.get_matches('2025-01-12T13:50:50Z')) 213 214 def test_mid(self): 215 self.assertTrue(self._index_filter.get_matches('2025-02-13T14:50:50Z')) 216 217 def test_high(self): 218 self.assertTrue(self._index_filter.get_matches('2025-03-13T14:50:50Z')) 219 220 def test_high_approx_match(self): 221 self.assertTrue(self._index_filter.get_matches('2025-03-13T15:50:50Z')) 222 223 def test_high_approx_not_match(self): 224 self.assertFalse(self._index_filter.get_matches('2025-03-14T14:50:50Z')) 225 226 def test_out_high(self): 227 self.assertFalse(self._index_filter.get_matches('2025-04-13T14:50:50Z')) 228 229 def test_none(self): 230 self.assertFalse(self._index_filter.get_matches(None))
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
196 def setUp(self): 197 param = unittest.mock.MagicMock() 198 param.get_low = unittest.mock.MagicMock(return_value='2025-01-13T13:50:50Z') 199 param.get_high = unittest.mock.MagicMock(return_value='2025-03-13T13:50:50Z') 200 self._index_filter = afscgap.flat_index_util.DatetimeRangeIndexFilter('index', param)
Hook method for setting up the test fixture before exercising it.
233class UnitConversionIndexFilterTests(unittest.TestCase): 234 235 def setUp(self): 236 self._inner = unittest.mock.MagicMock() 237 self._inner.get_matches = lambda x: x is not None and abs(x - 10000) < 0.001 238 239 def test_noop_true(self): 240 index_filter = afscgap.flat_index_util.UnitConversionIndexFilter(self._inner, 'ha', 'ha') 241 self.assertTrue(index_filter.get_matches(10000)) 242 243 def test_noop_false(self): 244 index_filter = afscgap.flat_index_util.UnitConversionIndexFilter(self._inner, 'ha', 'ha') 245 self.assertFalse(index_filter.get_matches(20000)) 246 247 def test_noop_none(self): 248 index_filter = afscgap.flat_index_util.UnitConversionIndexFilter(self._inner, 'ha', 'ha') 249 self.assertFalse(index_filter.get_matches(None)) 250 251 def test_convert_true(self): 252 index_filter = afscgap.flat_index_util.UnitConversionIndexFilter(self._inner, 'm2', 'ha') 253 self.assertTrue(index_filter.get_matches(1)) 254 255 def test_convert_false(self): 256 index_filter = afscgap.flat_index_util.UnitConversionIndexFilter(self._inner, 'm2', 'ha') 257 self.assertFalse(index_filter.get_matches(2)) 258 259 def test_convert_none(self): 260 index_filter = afscgap.flat_index_util.UnitConversionIndexFilter(self._inner, 'm2', 'ha') 261 self.assertFalse(index_filter.get_matches(None))
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
235 def setUp(self): 236 self._inner = unittest.mock.MagicMock() 237 self._inner.get_matches = lambda x: x is not None and abs(x - 10000) < 0.001
Hook method for setting up the test fixture before exercising it.
264class LogicalOrIndexFilterTests(unittest.TestCase): 265 266 def test_true_single(self): 267 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 268 self._make_inner_filter(1, 'test') 269 ]) 270 self.assertTrue(index_filter.get_matches(1)) 271 272 def test_true_multiple(self): 273 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 274 self._make_inner_filter(1, 'test'), 275 self._make_inner_filter(1, 'test') 276 ]) 277 self.assertTrue(index_filter.get_matches(1)) 278 279 def test_true_multiple_different(self): 280 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 281 self._make_inner_filter(1, 'test'), 282 self._make_inner_filter(2, 'test') 283 ]) 284 self.assertTrue(index_filter.get_matches(1)) 285 286 def test_false_single(self): 287 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 288 self._make_inner_filter(1, 'test') 289 ]) 290 self.assertFalse(index_filter.get_matches(2)) 291 292 def test_false_multiple(self): 293 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 294 self._make_inner_filter(1, 'test'), 295 self._make_inner_filter(1, 'test') 296 ]) 297 self.assertFalse(index_filter.get_matches(2)) 298 299 def test_empty(self): 300 with self.assertRaises(RuntimeError): 301 afscgap.flat_index_util.LogicalOrIndexFilter([]) 302 303 def test_unmatched(self): 304 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 305 self._make_inner_filter(1, 'test1'), 306 self._make_inner_filter(2, 'test2') 307 ]) 308 index_names = list(index_filter.get_index_names()) 309 self.assertEqual(len(index_names), 2) 310 self.assertTrue('test1' in index_names) 311 self.assertTrue('test2' in index_names) 312 313 def _make_inner_filter(self, value, index): 314 mock = unittest.mock.MagicMock() 315 mock.get_matches = lambda x: x == value 316 mock.get_index_names = unittest.mock.MagicMock(return_value=[index]) 317 return mock
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
303 def test_unmatched(self): 304 index_filter = afscgap.flat_index_util.LogicalOrIndexFilter([ 305 self._make_inner_filter(1, 'test1'), 306 self._make_inner_filter(2, 'test2') 307 ]) 308 index_names = list(index_filter.get_index_names()) 309 self.assertEqual(len(index_names), 2) 310 self.assertTrue('test1' in index_names) 311 self.assertTrue('test2' in index_names)
320class DecorateFilterTests(unittest.TestCase): 321 322 def setUp(self): 323 self._inner = unittest.mock.MagicMock() 324 self._inner.get_matches = lambda x: x is not None and abs(x - 123) < 0.001 325 326 def test_decorate_filter_active_true(self): 327 decorated = afscgap.flat_index_util.decorate_filter('area_swept_ha', self._inner) 328 self.assertTrue(decorated.get_matches(12300)) 329 330 def test_decorate_filter_active_false(self): 331 decorated = afscgap.flat_index_util.decorate_filter('area_swept_ha', self._inner) 332 self.assertFalse(decorated.get_matches(12400)) 333 334 def test_decorate_filter_active_none(self): 335 decorated = afscgap.flat_index_util.decorate_filter('area_swept_ha', self._inner) 336 self.assertFalse(decorated.get_matches(None)) 337 338 def test_decorate_filter_active_true(self): 339 decorated = afscgap.flat_index_util.decorate_filter('other', self._inner) 340 self.assertTrue(decorated.get_matches(123)) 341 342 def test_decorate_filter_active_true(self): 343 decorated = afscgap.flat_index_util.decorate_filter('other', self._inner) 344 self.assertFalse(decorated.get_matches(124)) 345 346 def test_decorate_filter_active_none(self): 347 decorated = afscgap.flat_index_util.decorate_filter('other', self._inner) 348 self.assertFalse(decorated.get_matches(None))
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
322 def setUp(self): 323 self._inner = unittest.mock.MagicMock() 324 self._inner.get_matches = lambda x: x is not None and abs(x - 123) < 0.001
Hook method for setting up the test fixture before exercising it.
351class DetermineIfIgnorableTests(unittest.TestCase): 352 353 def test_explicit_ignorable_require_zero(self): 354 param = self._make_test_param(True, 'int') 355 ignorable = afscgap.flat_index_util.determine_if_ignorable('test', param, False) 356 self.assertTrue(ignorable) 357 358 def test_explicit_ignorable_presence_only(self): 359 param = self._make_test_param(True, 'int') 360 ignorable = afscgap.flat_index_util.determine_if_ignorable('test', param, True) 361 self.assertTrue(ignorable) 362 363 def test_require_zero_supported(self): 364 param = self._make_test_param(False, 'int') 365 ignorable = afscgap.flat_index_util.determine_if_ignorable('count', param, False) 366 self.assertFalse(ignorable) 367 368 def test_require_zero_unsupported(self): 369 param = self._make_test_param(False, 'str') 370 ignorable = afscgap.flat_index_util.determine_if_ignorable('species_code', param, False) 371 self.assertTrue(ignorable) 372 373 def test_presence_only_unsupported(self): 374 param = self._make_test_param(False, 'str') 375 ignorable = afscgap.flat_index_util.determine_if_ignorable('species_code', param, True) 376 self.assertFalse(ignorable) 377 378 def test_empty(self): 379 param = afscgap.param.EmptyParam() 380 ignorable = afscgap.flat_index_util.determine_if_ignorable('count', param, True) 381 self.assertTrue(ignorable) 382 383 def test_plain_not_ignorable(self): 384 param = afscgap.param.IntRangeParam(1, None) 385 ignorable = afscgap.flat_index_util.determine_if_ignorable('count', param, True) 386 self.assertFalse(ignorable) 387 388 def _make_test_param(self, ignorable, filter_type): 389 param = unittest.mock.MagicMock() 390 param.get_is_ignorable = unittest.mock.MagicMock(return_value=ignorable) 391 param.get_filter_type = unittest.mock.MagicMock(return_value=filter_type) 392 return param
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
395class MakeFilterTests(unittest.TestCase): 396 397 def test_empty(self): 398 param = afscgap.param.EmptyParam() 399 filters = afscgap.flat_index_util.make_filters('test', param, True) 400 self.assertEqual(len(filters), 0) 401 402 def test_string_true(self): 403 param = afscgap.param.StrEqualsParam('test') 404 filters = afscgap.flat_index_util.make_filters('common_name', param, True) 405 self.assertEqual(len(filters), 1) 406 self.assertTrue(filters[0].get_matches('test')) 407 408 def test_string_false(self): 409 param = afscgap.param.StrEqualsParam('test') 410 filters = afscgap.flat_index_util.make_filters('common_name', param, True) 411 self.assertEqual(len(filters), 1) 412 self.assertFalse(filters[0].get_matches('other')) 413 414 def test_presence_only(self): 415 param = afscgap.param.StrEqualsParam('test') 416 filters = afscgap.flat_index_util.make_filters('common_name', param, False) 417 self.assertEqual(len(filters), 0) 418 419 def test_int_true(self): 420 param = afscgap.param.IntEqualsParam(1) 421 filters = afscgap.flat_index_util.make_filters('vessel_id', param, True) 422 self.assertEqual(len(filters), 1) 423 self.assertTrue(filters[0].get_matches(1)) 424 425 def test_int_false(self): 426 param = afscgap.param.IntEqualsParam(1) 427 filters = afscgap.flat_index_util.make_filters('vessel_id', param, True) 428 self.assertEqual(len(filters), 1) 429 self.assertFalse(filters[0].get_matches(2)) 430 431 def test_float_true(self): 432 param = afscgap.param.FloatEqualsParam(1.234) 433 filters = afscgap.flat_index_util.make_filters('latitude_dd', param, True) 434 self.assertEqual(len(filters), 1) 435 self.assertTrue(filters[0].get_matches(1.233)) 436 437 def test_float_false(self): 438 param = afscgap.param.FloatEqualsParam(1.234) 439 filters = afscgap.flat_index_util.make_filters('latitude_dd', param, True) 440 self.assertEqual(len(filters), 1) 441 self.assertFalse(filters[0].get_matches(1.2355)) 442 443 def test_unit_conversion_true(self): 444 param = afscgap.param.FloatEqualsParam(1) 445 filters = afscgap.flat_index_util.make_filters('area_swept_ha', param, True) 446 self.assertEqual(len(filters), 1) 447 self.assertTrue(filters[0].get_matches(0.01)) 448 449 def test_unit_conversion_false(self): 450 param = afscgap.param.FloatEqualsParam(1) 451 filters = afscgap.flat_index_util.make_filters('area_swept_ha', param, True) 452 self.assertEqual(len(filters), 1) 453 self.assertFalse(filters[0].get_matches(0.02)) 454 455 def test_unknown_field(self): 456 param = afscgap.param.FloatEqualsParam(1) 457 filters = afscgap.flat_index_util.make_filters('other', param, True) 458 self.assertEqual(len(filters), 0)
A class whose instances are single test cases.
By default, the test code itself should be placed in a method named 'runTest'.
If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.
When subclassing TestCase, you can set these attributes:
- failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
- longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
- maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.