Skip to content

Commit bfcc722

Browse files
authored
feat: add @pytest.mark.benchmark to all tests (#308)
1 parent d0bf5e7 commit bfcc722

File tree

9 files changed

+138
-0
lines changed

9 files changed

+138
-0
lines changed

tests/config_edge_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from commit_check.config import load_config
77

88

9+
@pytest.mark.benchmark
910
def test_load_config_invalid_toml():
1011
"""Test handling of invalid TOML syntax."""
1112
invalid_toml = b"""
@@ -23,6 +24,7 @@ def test_load_config_invalid_toml():
2324
os.unlink(f.name)
2425

2526

27+
@pytest.mark.benchmark
2628
def test_load_config_file_permission_error():
2729
"""Test handling of file permission errors."""
2830
config_content = b"""
@@ -45,6 +47,7 @@ def test_load_config_file_permission_error():
4547
os.unlink(f.name)
4648

4749

50+
@pytest.mark.benchmark
4851
def test_tomli_import_fallback():
4952
"""Test the tomli import fallback when tomllib is not available."""
5053
# We need to test the import fallback behavior

tests/config_fallback_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import sys
44
import tempfile
55
import os
6+
import pytest
67
from unittest.mock import patch
78

89

10+
@pytest.mark.benchmark
911
def test_config_tomli_fallback_direct():
1012
"""Test config.py fallback to tomli by manipulating imports."""
1113

tests/config_import_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import tempfile
44
import os
55
from unittest.mock import patch
6+
import pytest
67

78

9+
@pytest.mark.benchmark
810
def test_tomli_import_fallback_simulation():
911
"""Test tomli import fallback by simulating the ImportError condition."""
1012

@@ -63,6 +65,7 @@ def load(f):
6365
return __import__(name, *args, **kwargs)
6466

6567

68+
@pytest.mark.benchmark
6669
def test_import_paths_coverage():
6770
"""Ensure both import paths are conceptually tested."""
6871
# This test verifies that both the tomllib and tomli code paths

tests/config_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
class TestConfig:
12+
@pytest.mark.benchmark
1213
def test_load_config_with_path_hint(self):
1314
"""Test loading config with explicit path hint."""
1415
config_content = b"""
@@ -28,6 +29,7 @@ def test_load_config_with_path_hint(self):
2829
finally:
2930
os.unlink(f.name)
3031

32+
@pytest.mark.benchmark
3133
def test_load_config_with_nonexistent_path_hint(self):
3234
"""Test loading config when path hint doesn't exist - should raise FileNotFoundError."""
3335
# Test that specifying a nonexistent config file raises an error
@@ -36,6 +38,7 @@ def test_load_config_with_nonexistent_path_hint(self):
3638
):
3739
load_config("nonexistent.toml")
3840

41+
@pytest.mark.benchmark
3942
def test_load_config_default_cchk_toml(self):
4043
"""Test loading config from default cchk.toml path."""
4144
config_content = b"""
@@ -55,6 +58,7 @@ def test_load_config_default_cchk_toml(self):
5558
finally:
5659
os.chdir(original_cwd)
5760

61+
@pytest.mark.benchmark
5862
def test_load_config_default_commit_check_toml(self):
5963
"""Test loading config from default commit-check.toml path."""
6064
config_content = b"""
@@ -74,6 +78,7 @@ def test_load_config_default_commit_check_toml(self):
7478
finally:
7579
os.chdir(original_cwd)
7680

81+
@pytest.mark.benchmark
7782
def test_load_config_file_not_found(self):
7883
"""Test returning empty config when no default config files exist."""
7984
original_cwd = os.getcwd()
@@ -86,6 +91,7 @@ def test_load_config_file_not_found(self):
8691
finally:
8792
os.chdir(original_cwd)
8893

94+
@pytest.mark.benchmark
8995
def test_load_config_file_not_found_with_invalid_path_hint(self):
9096
"""Test FileNotFoundError when specified path hint doesn't exist."""
9197
original_cwd = os.getcwd()
@@ -100,12 +106,14 @@ def test_load_config_file_not_found_with_invalid_path_hint(self):
100106
finally:
101107
os.chdir(original_cwd)
102108

109+
@pytest.mark.benchmark
103110
def test_default_config_paths_constant(self):
104111
"""Test that DEFAULT_CONFIG_PATHS contains expected paths."""
105112
assert len(DEFAULT_CONFIG_PATHS) == 2
106113
assert Path("cchk.toml") in DEFAULT_CONFIG_PATHS
107114
assert Path("commit-check.toml") in DEFAULT_CONFIG_PATHS
108115

116+
@pytest.mark.benchmark
109117
def test_toml_load_function_exists(self):
110118
"""Test that toml_load function is properly set up."""
111119
from commit_check.config import toml_load
@@ -128,6 +136,7 @@ def test_toml_load_function_exists(self):
128136
finally:
129137
os.unlink(f.name)
130138

139+
@pytest.mark.benchmark
131140
def test_tomli_import_fallback(self):
132141
"""Test that tomli is imported when tomllib is not available (lines 10-13)."""
133142
import sys

tests/engine_comprehensive_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
CommitTypeValidator,
1818
)
1919
from commit_check.rule_builder import ValidationRule
20+
import pytest
2021

2122

2223
class TestValidationResult:
24+
@pytest.mark.benchmark
2325
def test_validation_result_values(self):
2426
"""Test ValidationResult enum values."""
2527
assert ValidationResult.PASS == 0
2628
assert ValidationResult.FAIL == 1
2729

2830

2931
class TestValidationContext:
32+
@pytest.mark.benchmark
3033
def test_validation_context_creation(self):
3134
"""Test ValidationContext creation."""
3235
context = ValidationContext()
@@ -41,6 +44,7 @@ def test_validation_context_creation(self):
4144

4245

4346
class TestCommitMessageValidator:
47+
@pytest.mark.benchmark
4448
def test_commit_message_validator_creation(self):
4549
"""Test CommitMessageValidator creation."""
4650
rule = ValidationRule(
@@ -53,6 +57,7 @@ def test_commit_message_validator_creation(self):
5357
assert validator.rule == rule
5458

5559
@patch("commit_check.engine.has_commits")
60+
@pytest.mark.benchmark
5661
def test_commit_message_validator_with_stdin(self, mock_has_commits):
5762
"""Test CommitMessageValidator with stdin text."""
5863
mock_has_commits.return_value = True
@@ -71,6 +76,7 @@ def test_commit_message_validator_with_stdin(self, mock_has_commits):
7176

7277
@patch("commit_check.engine.get_commit_info")
7378
@patch("commit_check.engine.has_commits")
79+
@pytest.mark.benchmark
7480
def test_commit_message_validator_failure(
7581
self, mock_has_commits, mock_get_commit_info
7682
):
@@ -92,6 +98,7 @@ def test_commit_message_validator_failure(
9298
mock_print.assert_called_once()
9399

94100
@patch("commit_check.engine.has_commits")
101+
@pytest.mark.benchmark
95102
def test_commit_message_validator_skip_validation(self, mock_has_commits):
96103
"""Test CommitMessageValidator skips when no commits and no stdin."""
97104
mock_has_commits.return_value = False
@@ -110,6 +117,7 @@ def test_commit_message_validator_skip_validation(self, mock_has_commits):
110117

111118

112119
class TestSubjectCapitalizationValidator:
120+
@pytest.mark.benchmark
113121
def test_subject_capitalization_pass(self):
114122
"""Test SubjectCapitalizationValidator pass case."""
115123
rule = ValidationRule(
@@ -125,6 +133,7 @@ def test_subject_capitalization_pass(self):
125133
result = validator.validate(context)
126134
assert result == ValidationResult.PASS
127135

136+
@pytest.mark.benchmark
128137
def test_subject_capitalization_fail(self):
129138
"""Test SubjectCapitalizationValidator fail case."""
130139
rule = ValidationRule(
@@ -144,6 +153,7 @@ def test_subject_capitalization_fail(self):
144153

145154

146155
class TestSubjectImperativeValidator:
156+
@pytest.mark.benchmark
147157
def test_subject_imperative_pass(self):
148158
"""Test SubjectImperativeValidator pass case."""
149159
rule = ValidationRule(
@@ -159,6 +169,7 @@ def test_subject_imperative_pass(self):
159169
result = validator.validate(context)
160170
assert result == ValidationResult.PASS
161171

172+
@pytest.mark.benchmark
162173
def test_subject_imperative_fail(self):
163174
"""Test SubjectImperativeValidator fail case."""
164175
rule = ValidationRule(
@@ -178,6 +189,7 @@ def test_subject_imperative_fail(self):
178189

179190

180191
class TestSubjectLengthValidator:
192+
@pytest.mark.benchmark
181193
def test_subject_length_pass(self):
182194
"""Test SubjectLengthValidator pass case."""
183195
rule = ValidationRule(
@@ -193,6 +205,7 @@ def test_subject_length_pass(self):
193205
result = validator.validate(context)
194206
assert result == ValidationResult.PASS
195207

208+
@pytest.mark.benchmark
196209
def test_subject_length_fail(self):
197210
"""Test SubjectLengthValidator fail case."""
198211
rule = ValidationRule(
@@ -212,6 +225,7 @@ def test_subject_length_fail(self):
212225

213226

214227
class TestValidationEngine:
228+
@pytest.mark.benchmark
215229
def test_validation_engine_creation(self):
216230
"""Test ValidationEngine creation."""
217231
rules = [
@@ -225,6 +239,7 @@ def test_validation_engine_creation(self):
225239
engine = ValidationEngine(rules)
226240
assert engine.rules == rules
227241

242+
@pytest.mark.benchmark
228243
def test_validation_engine_validator_map(self):
229244
"""Test ValidationEngine VALIDATOR_MAP contains expected mappings."""
230245
engine = ValidationEngine([])
@@ -252,6 +267,7 @@ def test_validation_engine_validator_map(self):
252267
for check, validator_class in expected_mappings.items():
253268
assert engine.VALIDATOR_MAP[check] == validator_class
254269

270+
@pytest.mark.benchmark
255271
def test_validation_engine_validate_all_pass(self):
256272
"""Test ValidationEngine validate_all with all passing rules."""
257273
rules = [
@@ -269,6 +285,7 @@ def test_validation_engine_validate_all_pass(self):
269285
result = engine.validate_all(context)
270286
assert result == ValidationResult.PASS
271287

288+
@pytest.mark.benchmark
272289
def test_validation_engine_validate_all_fail(self):
273290
"""Test ValidationEngine validate_all with failing rule."""
274291
rules = [
@@ -286,6 +303,7 @@ def test_validation_engine_validate_all_fail(self):
286303
result = engine.validate_all(context)
287304
assert result == ValidationResult.FAIL
288305

306+
@pytest.mark.benchmark
289307
def test_validation_engine_unknown_validator(self):
290308
"""Test ValidationEngine with unknown validator type."""
291309
rules = [

0 commit comments

Comments
 (0)