Skip to content

Commit b1f6760

Browse files
committed
precommit fix
1 parent b50049e commit b1f6760

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

code_to_optimize/topological_sort.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@ def addEdge(self, u, v):
1111

1212
def topologicalSortUtil(self, v, visited, stack):
1313
visited[v] = True
14-
1514
for i in self.graph[v]:
16-
if visited[i] == False:
15+
if not visited[i]:
1716
self.topologicalSortUtil(i, visited, stack)
18-
19-
stack.insert(0, v)
17+
stack.append(v) # append to end for O(1) operation
2018

2119
def topologicalSort(self):
2220
visited = [False] * self.V
2321
stack = []
24-
2522
for i in range(self.V):
26-
if visited[i] == False:
23+
if not visited[i]:
2724
self.topologicalSortUtil(i, visited, stack)
28-
25+
stack.reverse() # correct order after all vertices are processed
2926
return stack

codeflash/discovery/discover_unit_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pydantic.dataclasses import dataclass
1818

1919
from codeflash.cli_cmds.console import console, logger, test_files_progress_bar
20-
from codeflash.code_utils.code_utils import get_run_tmp_file, module_name_from_file_path, custom_addopts
20+
from codeflash.code_utils.code_utils import custom_addopts, get_run_tmp_file, module_name_from_file_path
2121
from codeflash.code_utils.compat import SAFE_SYS_EXECUTABLE, codeflash_cache_db
2222
from codeflash.models.models import CodePosition, FunctionCalledInTest, TestsInFile, TestType
2323

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ formatter-cmds = [
240240
]
241241

242242

243+
[tool.pytest.ini_options]
244+
addopts = ["-n=auto", "-n", "1", "-n 1", "-n 1", "-n auto"]
243245
[build-system]
244246
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.2.0,<2.0.0"]
245247
build-backend = "poetry_dynamic_versioning.backend"

tests/scripts/end_to_end_test_topological_sort.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
def run_test(expected_improvement_pct: int) -> bool:
99
try:
1010
# Modify Pyproject file
11-
with pathlib.Path.open((pathlib.Path(__file__).parent.parent.parent / "pyproject.toml").resolve(), encoding="utf-8") as f:
11+
with pathlib.Path.open(
12+
(pathlib.Path(__file__).parent.parent.parent / "pyproject.toml").resolve(), encoding="utf-8"
13+
) as f:
1214
original_content = f.read()
1315
data = tomlkit.parse(original_content)
1416
data["tool"]["pytest"] = {}
1517
data["tool"]["pytest"]["ini_options"] = {}
1618
data["tool"]["pytest"]["ini_options"]["addopts"] = ["-n=auto", "-n", "1", "-n 1", "-n 1", "-n auto"]
17-
with pathlib.Path.open((pathlib.Path(__file__).parent.parent.parent / "pyproject.toml").resolve(), "w", encoding="utf-8") as f:
19+
with pathlib.Path.open(
20+
(pathlib.Path(__file__).parent.parent.parent / "pyproject.toml").resolve(), "w", encoding="utf-8"
21+
) as f:
1822
f.write(tomlkit.dumps(data))
1923
config = TestConfig(
2024
file_path="topological_sort.py",
@@ -23,7 +27,9 @@ def run_test(expected_improvement_pct: int) -> bool:
2327
min_improvement_x=0.05,
2428
coverage_expectations=[
2529
CoverageExpectation(
26-
function_name="Graph.topologicalSort", expected_coverage=100.0, expected_lines=[24, 25, 26, 27, 28, 29]
30+
function_name="Graph.topologicalSort",
31+
expected_coverage=100.0,
32+
expected_lines=[24, 25, 26, 27, 28, 29],
2733
)
2834
],
2935
)

0 commit comments

Comments
 (0)