-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathREADME.coders
More file actions
165 lines (126 loc) · 4.17 KB
/
README.coders
File metadata and controls
165 lines (126 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
This file contains notes to coders who want to contribute to the project
#
# Code Style
#
The code must run under Python 3.9+
Follow the PEP 8 style guide. Use modern Python tooling for formatting:
# Format code
black src/compiletools/
# or
ruff format src/compiletools/
# Lint code
ruff check src/compiletools/
#
# Running tests
#
The project uses pytest as its testing framework. First install development dependencies:
uv pip install -e ".[dev]"
Then run tests:
# Run all tests
pytest src/compiletools
# Run tests in parallel (faster)
pytest src/compiletools -n auto
# Run specific test file
pytest src/compiletools/test_utils.py
# Run with verbose output
pytest src/compiletools -v
#
# Test Style Guidelines
#
All tests should follow pytest conventions. Prefer function-based style over class-based:
# Preferred (function-based)
def test_something():
assert my_function() == expected_result
# Acceptable (class-based for complex tests with shared setup)
class TestComplexFeature:
def setup_method(self):
# setup code
def test_feature_behavior(self):
assert feature.behavior() == expected
Simple tests with single test methods should use function-based style.
Use class-based style only when tests share complex setup/teardown logic.
#
# pytest Features and Best Practices
#
pytest provides powerful features for testing:
**Fixtures**: Use fixtures for reusable setup and teardown
def test_with_temp_dir(tmp_path):
# tmp_path is a pytest built-in fixture providing temp directory
test_file = tmp_path / "test.txt"
test_file.write_text("content")
assert test_file.exists()
**Parametrization**: Test multiple inputs with single test function
@pytest.mark.parametrize("input,expected", [
(2, 4),
(3, 9),
(4, 16),
])
def test_square(input, expected):
assert input ** 2 == expected
**Markers**: Mark tests for selective execution
@pytest.mark.slow
def test_slow_operation():
# Run with: pytest -m "not slow" to skip slow tests
pass
**Assertions**: Use simple assert statements
def test_equality():
assert result == expected # pytest provides detailed failure messages
**Mocking**: unittest.mock works seamlessly with pytest
from unittest.mock import Mock, patch
def test_with_mock():
mock_obj = Mock(return_value=42)
assert mock_obj() == 42
**Test Discovery**: pytest automatically discovers tests
- Files matching test_*.py or *_test.py
- Functions named test_*
- Classes named Test* with test_* methods
#
# Caches/Performance
#
When you are doing performance testing there are 3 caches you need to be aware of
1) ccache: This can be cleaned by ccache -C
2) cake: The default is for any caches to be kept in the bin directory. rm -rf bin
3) ct-*: The default cache is supplied by the appdirs module.
So on linux that means the XDG user cache directory which defaults to $HOME/.cache/ct.
rm -rf ~/.cache/ct
Note that it obeys the XDG variables. Alter XDG_CACHE_HOME if you need to move the cache.
ct-cache-clean will correctly remove the cache as specified by the XDG_CACHE_HOME
It is possible to override the above by specifying the CTCACHE environment variable.
CTCACHE=None turns off diskcaching
#
# Gotchas
#
If you encounter cache-related issues, clear the cache using:
ct-cache-clean
#
# Package Structure
#
src/compiletools/ - Main package code (moved from ct/)
ct-* - Command-line scripts
pyproject.toml - Modern Python packaging configuration
CLAUDE.md - Project documentation and build instructions
#
# Development Setup
#
# Install development dependencies
uv pip install -e ".[dev]"
# or manually install dev tools
pip install bump-my-version twine
#
# Making a release
#
The ct-release script automates the release process, or you can do it manually:
# Increase the version number using bump-my-version
# Configuration is in pyproject.toml [tool.bumpversion] section
bump-my-version bump patch
# or
bump-my-version bump minor
# or
bump-my-version bump major
git push
git push --tags
# Build and upload to PyPI
uv build
twine upload dist/* -r pypi
# Test installation
pip install compiletools