|
2 | 2 | # SPDX-License-Identifier: Apache-2.0
|
3 | 3 |
|
4 | 4 | import pytest
|
5 |
| -from pathlib import Path |
6 | 5 |
|
7 |
| -from access.parsers.profiling import _convert_from_string |
| 6 | +from access.parsers.profiling import ProfilingParser, _convert_from_string |
| 7 | + |
| 8 | + |
| 9 | +class MockProfilingParser(ProfilingParser): |
| 10 | + """A Mock concrete Profiling Parser.""" |
| 11 | + |
| 12 | + def __init__(self, data: dict): |
| 13 | + self._metrics = ["hits", "tmin", "tmax", "tavg"] |
| 14 | + self._data = data |
| 15 | + |
| 16 | + @property |
| 17 | + def metrics(self) -> list: |
| 18 | + return self._metrics |
| 19 | + |
| 20 | + def read(self, stream: str) -> dict: |
| 21 | + return self._data[stream] |
| 22 | + |
| 23 | + |
| 24 | +@pytest.fixture(scope="module") |
| 25 | +def profiling_data(): |
| 26 | + """Fixture instantiating fake parsed profiling data.""" |
| 27 | + return { |
| 28 | + "1cpu_stream": { |
| 29 | + "regions": ["Total runtime", "Ocean Initialization"], |
| 30 | + "hits": [1, 2], |
| 31 | + "tmin": [138.600364, 2.344926], |
| 32 | + "tmax": [138.600366, 2.345701], |
| 33 | + "tavg": [600365, 2.345388], |
| 34 | + }, |
| 35 | + "2cpu_stream": { |
| 36 | + "regions": ["Total runtime", "Ocean Initialization"], |
| 37 | + "hits": [3, 4], |
| 38 | + "tmin": [69.300182, 1.162463], |
| 39 | + "tmax": [49.300182, 1.162463], |
| 40 | + "tavg": [300182.5, 1.172694], |
| 41 | + }, |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | +def test_base_parser(profiling_data): |
| 46 | + """Tests methods and properties of abstract base class, ProfilingParser.""" |
| 47 | + |
| 48 | + parser = MockProfilingParser(profiling_data) |
| 49 | + |
| 50 | + assert parser.metrics == ["hits", "tmin", "tmax", "tavg"], "Incorrect metrics returned in MockProfilingParser!" |
| 51 | + for stream in ("1cpu_stream", "2cpu_stream"): |
| 52 | + assert parser.read(stream) == profiling_data[stream], f'Incorrect profiling stats returned for "{stream}"' |
8 | 53 |
|
9 | 54 |
|
10 | 55 | def test_str2num():
|
|
0 commit comments