Wrapper to make xtop-tui testable
| 33 | import importlib.util |
| 34 | |
| 35 | class XtopTUIWrapper: |
| 36 | """Wrapper to make xtop-tui testable""" |
| 37 | def __init__(self, datadir: str, |
| 38 | low_time=None, high_time=None, initial_group_cols=None): |
| 39 | # Load the TUI module dynamically |
| 40 | spec = importlib.util.spec_from_file_location( |
| 41 | "xtop_tui", |
| 42 | Path(__file__).parent.parent / "xtop-tui.py" |
| 43 | ) |
| 44 | module = importlib.util.module_from_spec(spec) |
| 45 | |
| 46 | # Set the module's __path__ to help with relative imports |
| 47 | module.__file__ = str(Path(__file__).parent.parent / "xtop-tui.py") |
| 48 | |
| 49 | # Execute the module |
| 50 | spec.loader.exec_module(module) |
| 51 | |
| 52 | self.app_class = module.XTopTUI |
| 53 | self.datadir = datadir |
| 54 | # Removed initial_query_type - always dynamic now |
| 55 | self.low_time = low_time |
| 56 | self.high_time = high_time |
| 57 | self.initial_group_cols = initial_group_cols or ['state'] # Default to just 'state' |
| 58 | |
| 59 | def create_app(self): |
| 60 | """Create an instance of the app""" |
| 61 | # Override the default grouping to just 'state' for tests |
| 62 | original_defaults = QueryEngine.DEFAULT_GROUP_COLS.copy() |
| 63 | for key in original_defaults: |
| 64 | QueryEngine.DEFAULT_GROUP_COLS[key] = self.initial_group_cols |
| 65 | |
| 66 | app = self.app_class( |
| 67 | datadir=self.datadir, |
| 68 | low_time=self.low_time, |
| 69 | high_time=self.high_time |
| 70 | ) |
| 71 | |
| 72 | # Restore original defaults after creating app |
| 73 | QueryEngine.DEFAULT_GROUP_COLS = original_defaults |
| 74 | |
| 75 | return app |
| 76 | |
| 77 | |
| 78 | # Helper functions for navigation |
no outgoing calls