Skip to content

Commit edd89c6

Browse files
committed
Add pre-commit hooks as tests
1 parent e7a225e commit edd89c6

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

.internal/pre_commit_tools/clean_timeouts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env python3
22

3+
import subprocess
34
import sys
45
from collections import Counter
56
from pathlib import Path
67

78
import yaml
89

9-
PROJECT_ROOT = Path(__file__).parents[2]
10+
PROJECT_ROOT = Path(subprocess.getoutput("git rev-parse --show-toplevel")) # noqa: S605
1011
TIMEOUTS_FILE = PROJECT_ROOT / "tests" / "resources" / "timeouts.yaml"
1112

1213

.internal/pre_commit_tools/notebook_pre_commit_collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
# ruff: noqa: F841,E713
33

44
import os
5+
import subprocess
56
import sys
67
from collections import Counter
78
from collections.abc import Iterable
89
from pathlib import Path
910

1011
import yaml
1112

12-
PROJECT_ROOT = Path(__file__).parents[2]
13+
PROJECT_ROOT = Path(subprocess.getoutput("git rev-parse --show-toplevel")) # noqa: S605
1314
TIMEOUTS_FILE = PROJECT_ROOT / "tests" / "resources" / "timeouts.yaml"
1415

1516
Seconds = float

.internal/pre_commit_tools/qmod_pre_commit_collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
# ruff: noqa: F841,E713
33

44
import os
5+
import subprocess
56
import sys
67
from collections import Counter
78
from collections.abc import Iterable
89
from pathlib import Path
910

1011
import yaml
1112

12-
PROJECT_ROOT = Path(__file__).parents[2]
13+
PROJECT_ROOT = Path(subprocess.getoutput("git rev-parse --show-toplevel")) # noqa: S605
1314
TIMEOUTS_FILE = PROJECT_ROOT / "tests" / "resources" / "timeouts.yaml"
1415

1516
Seconds = float

tests/internal/pre_commit_tools

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.internal/pre_commit_tools

tests/internal/test_pre_commit.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import pytest
2+
from pre_commit_tools import (
3+
clean_timeouts,
4+
notebook_pre_commit_collection,
5+
qmod_pre_commit_collection,
6+
)
7+
8+
PROJECT_ROOT = clean_timeouts.PROJECT_ROOT
9+
10+
11+
#
12+
# tests from `clean_timeouts`
13+
#
14+
def test_timeouts_unique_keys():
15+
assert clean_timeouts.validate_unique_keys()
16+
17+
18+
def test_timeouts_missing_files():
19+
missing_files = clean_timeouts.find_missing_files()
20+
assert not missing_files
21+
22+
23+
#
24+
# tests from `notebook_pre_commit_collection`
25+
#
26+
@pytest.mark.parametrize("notebook_path", map(str, PROJECT_ROOT.rglob("*.ipynb")))
27+
def test_notebooks(notebook_path: str):
28+
assert notebook_pre_commit_collection.validate_notebook(
29+
notebook_path, automatically_add_timeout=False
30+
)
31+
32+
33+
def test_notebooks_unique_names():
34+
assert notebook_pre_commit_collection.validate_unique_names()
35+
36+
37+
#
38+
# tests from `qmod_pre_commit_collection`
39+
#
40+
@pytest.mark.parametrize("qmod_path", map(str, PROJECT_ROOT.rglob("*.qmod")))
41+
def test_notebooks(qmod_path: str):
42+
if "functions/function_declarations" in qmod_path:
43+
return # skipped
44+
if "functions/open_library_definitions" in qmod_path:
45+
return # skipped
46+
47+
assert qmod_pre_commit_collection.validate_qmod(
48+
qmod_path, automatically_add_timeout=False
49+
)
50+
51+
52+
def test_notebooks_unique_names():
53+
assert qmod_pre_commit_collection.validate_unique_names()

0 commit comments

Comments
 (0)