MCPcopy Index your code
hub / github.com/tanelpoder/0xtools / _detect_default_time_range

Function _detect_default_time_range

xtop/tests/test_tui_simple.py:42–73  ·  view source on GitHub ↗

Detect an available hour of data for the TUI tests.

(datadir: str)

Source from the content-addressed store, hash-verified

40from tui.value_filter_modal import ValueFilterModal
41
42def _detect_default_time_range(datadir: str) -> tuple[datetime, datetime]:
43 """Detect an available hour of data for the TUI tests."""
44 path = Path(datadir)
45 candidates = list(path.glob("xcapture_samples_*.csv"))
46 candidates += list(path.glob("xcapture_samples_*.parquet"))
47
48 if not candidates:
49 pytest.skip(
50 f"No xcapture sample files found in {datadir}; skipping TUI tests",
51 allow_module_level=True,
52 )
53
54 pattern = re.compile(r"xcapture_samples_(\d{4}-\d{2}-\d{2})\.(\d{2})")
55 timestamps: list[datetime] = []
56 for candidate in candidates:
57 match = pattern.search(candidate.name)
58 if not match:
59 continue
60 date_part, hour_part = match.groups()
61 try:
62 timestamps.append(datetime.strptime(f"{date_part} {hour_part}", "%Y-%m-%d %H"))
63 except ValueError:
64 continue
65
66 if not timestamps:
67 pytest.skip(
68 f"Could not parse timestamps from sample files in {datadir}; skipping TUI tests",
69 allow_module_level=True,
70 )
71
72 hour = max(timestamps)
73 return hour, hour + timedelta(hours=1)
74
75
76DEFAULT_LOW_TIME, DEFAULT_HIGH_TIME = _detect_default_time_range(XCAPTURE_DATADIR)

Callers 1

test_tui_simple.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected