MCPcopy Index your code
hub / github.com/huggingface/diffusers / parse_durations_file

Function parse_durations_file

utils/consolidated_test_report.py:92–133  ·  view source on GitHub ↗

Parse a durations file to extract test timing information.

(file_path)

Source from the content-addressed store, hash-verified

90
91
92def parse_durations_file(file_path):
93 """Parse a durations file to extract test timing information."""
94 slowest_tests = []
95 try:
96 durations_file = file_path.replace("_stats.txt", "_durations.txt")
97 if os.path.exists(durations_file):
98 with open(durations_file, "r") as f:
99 content = f.read()
100
101 # Skip the header line
102 for line in content.split("\n")[1:]:
103 if line.strip():
104 # Format is typically: 10.37s call tests/path/to/test.py::TestClass::test_method
105 parts = line.strip().split()
106 if len(parts) >= 3:
107 time_str = parts[0]
108 test_path = " ".join(parts[2:])
109
110 # Skip entries with "< 0.05 secs were omitted" or similar
111 if "secs were omitted" in test_path:
112 continue
113
114 try:
115 time_seconds = float(time_str.rstrip("s"))
116 slowest_tests.append({"test": test_path, "duration": time_seconds})
117 except ValueError:
118 # If time_str is not a valid float, it might be a different format
119 # For example, some pytest formats show "< 0.05s" or similar
120 if test_path.startswith("<") and "secs were omitted" in test_path:
121 # Extract the time value from test_path if it's in the format "< 0.05 secs were omitted"
122 try:
123 # This handles entries where the time is in the test_path itself
124 dur_match = re.search(r"(\d+(?:\.\d+)?)", test_path)
125 if dur_match:
126 time_seconds = float(dur_match.group(1))
127 slowest_tests.append({"test": test_path, "duration": time_seconds})
128 except ValueError:
129 pass
130 except Exception as e:
131 print(f"Error parsing durations file {file_path.replace('_stats.txt', '_durations.txt')}: {e}")
132
133 return slowest_tests
134
135
136def parse_failures_file(file_path):

Callers 1

consolidate_reportsFunction · 0.85

Calls 2

existsMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…