|
10 | 10 | import pandas as pd |
11 | 11 | import scipy.io as spio |
12 | 12 | from ebcpy import TimeSeriesData |
13 | | -from ebcpy.utils import setup_logger, conversion, statistics_analyzer, reproduction |
| 13 | +from ebcpy.utils import setup_logger, conversion, statistics_analyzer, reproduction, get_names |
14 | 14 |
|
15 | 15 |
|
16 | 16 | class TestConversion(unittest.TestCase): |
@@ -323,5 +323,41 @@ def tearDown(self) -> None: |
323 | 323 | pass |
324 | 324 |
|
325 | 325 |
|
| 326 | +class TestGetNames(unittest.TestCase): |
| 327 | + def test_matches(self): |
| 328 | + """ |
| 329 | + Test various literal and wildcard patterns, including brackets and multiple '*' usage. |
| 330 | + """ |
| 331 | + test_cases = [ |
| 332 | + # literal single match |
| 333 | + (['alpha', 'beta', 'gamma'], 'beta', ['beta']), |
| 334 | + # literal list of matches |
| 335 | + (['alpha', 'beta', 'gamma', 'delta'], ['alpha', 'delta'], ['alpha', 'delta']), |
| 336 | + # single '*' wildcard |
| 337 | + (['wall1.T', 'wall2.T', 'floor.T'], 'wall*.T', ['wall1.T', 'wall2.T']), |
| 338 | + # wildcard inside brackets |
| 339 | + (['wall[1].T', 'wall[2].T', 'wallX.T'], 'wall[*].T', ['wall[1].T', 'wall[2].T']), |
| 340 | + # two '*' wildcards |
| 341 | + (['a1b2', 'axby', 'ab'], 'a*b*', ['a1b2', 'axby', 'ab']), |
| 342 | + # mix of wildcard and literal in list |
| 343 | + (['a1', 'a2', 'b1', 'b2'], ['a*', 'b1'], ['a1', 'a2', 'b1']), |
| 344 | + # order preservation test |
| 345 | + (['first', 'second', 'third'], ['third', 'first'], ['first', 'third']), |
| 346 | + ] |
| 347 | + for all_names, patterns, expected in test_cases: |
| 348 | + with self.subTest(patterns=patterns): |
| 349 | + result = get_names(all_names, patterns) |
| 350 | + self.assertEqual(result, expected) |
| 351 | + |
| 352 | + def test_errors(self): |
| 353 | + """ |
| 354 | + Patterns or literals that match nothing should raise KeyError. |
| 355 | + """ |
| 356 | + with self.assertRaises(KeyError): |
| 357 | + get_names(['alpha', 'beta'], 'unknown') |
| 358 | + with self.assertRaises(KeyError): |
| 359 | + get_names(['x1', 'x2'], 'y*') |
| 360 | + |
| 361 | + |
326 | 362 | if __name__ == "__main__": |
327 | 363 | unittest.main() |
0 commit comments