-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
356 lines (304 loc) · 12.4 KB
/
Copy pathMakefile
File metadata and controls
356 lines (304 loc) · 12.4 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# Vergi Hatırlatıcı Bot - Test Automation Makefile
# Python ve test komutları için automation
# Değişkenler
PYTHON = python3
PIP = pip3
PYTEST = pytest
TOX = tox
VENV = venv
COVERAGE_THRESHOLD = 80
# Renkler (terminal çıktısı için)
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[0;33m
BLUE = \033[0;34m
PURPLE = \033[0;35m
CYAN = \033[0;36m
WHITE = \033[0;37m
NC = \033[0m # No Color
.PHONY: help install install-dev test test-unit test-integration test-database test-scraper test-bot coverage clean lint format check tox run-bot setup-db docs
# Default target
all: help
# Yardım menüsü
help:
@echo "$(CYAN)======================================$(NC)"
@echo "$(CYAN) Vergi Hatırlatıcı Bot - Test Suite $(NC)"
@echo "$(CYAN)======================================$(NC)"
@echo ""
@echo "$(GREEN)Setup Commands:$(NC)"
@echo " $(WHITE)make install$(NC) - Install production dependencies"
@echo " $(WHITE)make install-dev$(NC) - Install development dependencies"
@echo " $(WHITE)make venv$(NC) - Create virtual environment"
@echo " $(WHITE)make setup$(NC) - Full project setup"
@echo ""
@echo "$(GREEN)Test Commands:$(NC)"
@echo " $(WHITE)make test$(NC) - Run all tests"
@echo " $(WHITE)make test-unit$(NC) - Run unit tests only"
@echo " $(WHITE)make test-integration$(NC) - Run integration tests"
@echo " $(WHITE)make test-database$(NC) - Run database tests"
@echo " $(WHITE)make test-scraper$(NC) - Run scraper tests"
@echo " $(WHITE)make test-bot$(NC) - Run bot tests"
@echo " $(WHITE)make test-fast$(NC) - Run fast tests (exclude slow)"
@echo " $(WHITE)make test-slow$(NC) - Run slow tests only"
@echo ""
@echo "$(GREEN)Coverage Commands:$(NC)"
@echo " $(WHITE)make coverage$(NC) - Run tests with coverage"
@echo " $(WHITE)make coverage-report$(NC) - Show coverage report"
@echo " $(WHITE)make coverage-html$(NC) - Generate HTML coverage report"
@echo ""
@echo "$(GREEN)Quality Commands:$(NC)"
@echo " $(WHITE)make lint$(NC) - Run linting (flake8)"
@echo " $(WHITE)make format$(NC) - Auto-format code (black, isort)"
@echo " $(WHITE)make format-check$(NC) - Check code formatting"
@echo " $(WHITE)make type-check$(NC) - Run type checking (mypy)"
@echo " $(WHITE)make security-check$(NC) - Run security checks"
@echo " $(WHITE)make check$(NC) - Run all quality checks"
@echo ""
@echo "$(GREEN)Tox Commands:$(NC)"
@echo " $(WHITE)make tox$(NC) - Run tox (all environments)"
@echo " $(WHITE)make tox-py39$(NC) - Run tox with Python 3.9"
@echo " $(WHITE)make tox-coverage$(NC) - Run tox coverage"
@echo ""
@echo "$(GREEN)Application Commands:$(NC)"
@echo " $(WHITE)make run-bot$(NC) - Run the Telegram bot"
@echo " $(WHITE)make run-tests$(NC) - Run the test runner script"
@echo " $(WHITE)make setup-db$(NC) - Setup test database"
@echo ""
@echo "$(GREEN)Utility Commands:$(NC)"
@echo " $(WHITE)make clean$(NC) - Clean up generated files"
@echo " $(WHITE)make clean-all$(NC) - Clean everything including venv"
@echo " $(WHITE)make requirements$(NC) - Update requirements files"
@echo " $(WHITE)make docs$(NC) - Generate documentation"
# Setup commands
venv:
@echo "$(BLUE)Creating virtual environment...$(NC)"
$(PYTHON) -m venv $(VENV)
@echo "$(GREEN)Virtual environment created! Activate with: source venv/bin/activate$(NC)"
install:
@echo "$(BLUE)Installing production dependencies...$(NC)"
$(PIP) install --upgrade pip
$(PIP) install -r requirements.txt
@echo "$(GREEN)Production dependencies installed!$(NC)"
install-dev: install
@echo "$(BLUE)Installing development dependencies...$(NC)"
$(PIP) install -r requirements-test.txt
@echo "$(GREEN)Development dependencies installed!$(NC)"
setup: venv install-dev
@echo "$(GREEN)Project setup complete!$(NC)"
@echo "$(YELLOW)Don't forget to activate venv: source venv/bin/activate$(NC)"
# Test commands
test:
@echo "$(BLUE)Running all tests...$(NC)"
$(PYTEST) tests/ -v
@echo "$(GREEN)All tests completed!$(NC)"
test-unit:
@echo "$(BLUE)Running unit tests...$(NC)"
$(PYTEST) tests/ -m "unit" -v
@echo "$(GREEN)Unit tests completed!$(NC)"
test-integration:
@echo "$(BLUE)Running integration tests...$(NC)"
$(PYTEST) tests/ -m "integration" -v
@echo "$(GREEN)Integration tests completed!$(NC)"
test-database:
@echo "$(BLUE)Running database tests...$(NC)"
$(PYTEST) tests/ -m "database" -v
@echo "$(GREEN)Database tests completed!$(NC)"
test-scraper:
@echo "$(BLUE)Running scraper tests...$(NC)"
$(PYTEST) tests/ -m "scraper" -v
@echo "$(GREEN)Scraper tests completed!$(NC)"
test-bot:
@echo "$(BLUE)Running bot tests...$(NC)"
$(PYTEST) tests/ -m "bot" -v
@echo "$(GREEN)Bot tests completed!$(NC)"
test-fast:
@echo "$(BLUE)Running fast tests...$(NC)"
$(PYTEST) tests/ -m "not slow" -v
@echo "$(GREEN)Fast tests completed!$(NC)"
test-slow:
@echo "$(BLUE)Running slow tests...$(NC)"
$(PYTEST) tests/ -m "slow" -v --timeout=60
@echo "$(GREEN)Slow tests completed!$(NC)"
# Coverage commands
coverage:
@echo "$(BLUE)Running tests with coverage...$(NC)"
$(PYTEST) tests/ --cov=. --cov-report=term-missing --cov-report=html --cov-report=xml --cov-fail-under=$(COVERAGE_THRESHOLD)
@echo "$(GREEN)Coverage analysis completed!$(NC)"
@echo "$(CYAN)HTML report available at: htmlcov/index.html$(NC)"
coverage-report:
@echo "$(BLUE)Showing coverage report...$(NC)"
coverage report --show-missing
coverage-html:
@echo "$(BLUE)Generating HTML coverage report...$(NC)"
coverage html
@echo "$(GREEN)HTML coverage report generated: htmlcov/index.html$(NC)"
# Quality commands
lint:
@echo "$(BLUE)Running linting checks...$(NC)"
flake8 bot.py database.py scraper.py main.py bot_handlers.py
@echo "$(GREEN)Linting completed!$(NC)"
format:
@echo "$(BLUE)Auto-formatting code...$(NC)"
black bot.py database.py scraper.py main.py bot_handlers.py tests/
isort bot.py database.py scraper.py main.py bot_handlers.py tests/
@echo "$(GREEN)Code formatting completed!$(NC)"
format-check:
@echo "$(BLUE)Checking code formatting...$(NC)"
black --check --diff bot.py database.py scraper.py main.py bot_handlers.py tests/
isort --check-only --diff bot.py database.py scraper.py main.py bot_handlers.py tests/
@echo "$(GREEN)Format checking completed!$(NC)"
type-check:
@echo "$(BLUE)Running type checking...$(NC)"
mypy bot.py database.py scraper.py main.py bot_handlers.py
@echo "$(GREEN)Type checking completed!$(NC)"
security-check:
@echo "$(BLUE)Running security checks...$(NC)"
safety check
bandit -r bot.py database.py scraper.py main.py bot_handlers.py
@echo "$(GREEN)Security checks completed!$(NC)"
check: lint format-check type-check
@echo "$(GREEN)All quality checks completed!$(NC)"
# Tox commands
tox:
@echo "$(BLUE)Running tox (all environments)...$(NC)"
$(TOX)
@echo "$(GREEN)Tox completed!$(NC)"
tox-py39:
@echo "$(BLUE)Running tox with Python 3.9...$(NC)"
$(TOX) -e py39
@echo "$(GREEN)Tox Python 3.9 completed!$(NC)"
tox-coverage:
@echo "$(BLUE)Running tox coverage...$(NC)"
$(TOX) -e coverage
@echo "$(GREEN)Tox coverage completed!$(NC)"
tox-clean:
@echo "$(BLUE)Cleaning tox environments...$(NC)"
$(TOX) -e clean
@echo "$(GREEN)Tox environments cleaned!$(NC)"
# Application commands
run-bot:
@echo "$(BLUE)Starting Telegram Bot...$(NC)"
@echo "$(YELLOW)Press Ctrl+C to stop the bot$(NC)"
$(PYTHON) main.py
run-tests:
@echo "$(BLUE)Running test runner script...$(NC)"
$(PYTHON) test_runner.py
setup-db:
@echo "$(BLUE)Setting up test database...$(NC)"
$(PYTHON) -c "from database import test_database; test_database()"
@echo "$(GREEN)Test database setup completed!$(NC)"
# Utility commands
clean:
@echo "$(BLUE)Cleaning up generated files...$(NC)"
rm -rf htmlcov/
rm -rf .coverage
rm -rf coverage.xml
rm -rf .pytest_cache/
rm -rf __pycache__/
rm -rf .tox/
find . -name "*.pyc" -delete
find . -name "__pycache__" -type d -exec rm -rf {} +
find . -name "*.egg-info" -type d -exec rm -rf {} +
@echo "$(GREEN)Cleanup completed!$(NC)"
clean-all: clean
@echo "$(BLUE)Cleaning everything including virtual environment...$(NC)"
rm -rf $(VENV)/
rm -rf logs/*.log
@echo "$(GREEN)Complete cleanup finished!$(NC)"
requirements:
@echo "$(BLUE)Updating requirements files...$(NC)"
$(PIP) freeze > requirements.txt
@echo "$(GREEN)Requirements files updated!$(NC)"
docs:
@echo "$(BLUE)Generating documentation...$(NC)"
@echo "$(YELLOW)Documentation generation not implemented yet$(NC)"
# Continuous Integration simulation
ci: clean install-dev lint format-check type-check test coverage
@echo "$(GREEN)========================================$(NC)"
@echo "$(GREEN) CI Pipeline Simulation Completed! $(NC)"
@echo "$(GREEN)========================================$(NC)"
# Development workflow
dev-check: format lint type-check test-fast
@echo "$(GREEN)=======================================$(NC)"
@echo "$(GREEN) Development checks completed! $(NC)"
@echo "$(GREEN)=======================================$(NC)"
# Pre-commit hook simulation
pre-commit: format-check lint type-check test-unit
@echo "$(GREEN)=======================================$(NC)"
@echo "$(GREEN) Pre-commit checks completed! $(NC)"
@echo "$(GREEN)=======================================$(NC)"
# Quick test (fast development cycle)
quick-test:
@echo "$(BLUE)Running quick tests...$(NC)"
$(PYTEST) tests/ -x -v --tb=short
@echo "$(GREEN)Quick tests completed!$(NC)"
# Watch mode (requires pytest-watch)
watch:
@echo "$(BLUE)Starting test watch mode...$(NC)"
@echo "$(YELLOW)Install pytest-watch first: pip install pytest-watch$(NC)"
ptw --runner "pytest -x -v --tb=short"
# Benchmark tests
benchmark:
@echo "$(BLUE)Running benchmark tests...$(NC)"
$(PYTEST) tests/ --benchmark-only -v
@echo "$(GREEN)Benchmark tests completed!$(NC)"
# Debug mode tests
debug:
@echo "$(BLUE)Running tests in debug mode...$(NC)"
$(PYTEST) tests/ -s -v --tb=long --log-cli-level=DEBUG
@echo "$(GREEN)Debug tests completed!$(NC)"
# Test specific file
test-file:
@echo "$(BLUE)Usage: make test-file FILE=tests/test_database.py$(NC)"
@if [ -z "$(FILE)" ]; then \
echo "$(RED)Please specify FILE parameter$(NC)"; \
exit 1; \
fi
$(PYTEST) $(FILE) -v
# Test specific function
test-func:
@echo "$(BLUE)Usage: make test-func FUNC=test_database_connection$(NC)"
@if [ -z "$(FUNC)" ]; then \
echo "$(RED)Please specify FUNC parameter$(NC)"; \
exit 1; \
fi
$(PYTEST) -k $(FUNC) -v
# Performance profiling
profile:
@echo "$(BLUE)Running performance profiling...$(NC)"
$(PYTEST) tests/ --profile --profile-svg
@echo "$(GREEN)Performance profiling completed!$(NC)"
# Generate test report
test-report:
@echo "$(BLUE)Generating comprehensive test report...$(NC)"
$(PYTEST) tests/ --html=reports/test_report.html --self-contained-html --junitxml=reports/junit.xml
@echo "$(GREEN)Test report generated: reports/test_report.html$(NC)"
# Database migration (if needed)
migrate-db:
@echo "$(BLUE)Running database migrations...$(NC)"
$(PYTHON) -c "from database import DatabaseConnection; db = DatabaseConnection(); db.connect()"
@echo "$(GREEN)Database migration completed!$(NC)"
# Installation verification
verify-install:
@echo "$(BLUE)Verifying installation...$(NC)"
$(PYTHON) -c "import bot, database, scraper; print('All modules imported successfully!')"
@echo "$(GREEN)Installation verified!$(NC)"
# Show project info
info:
@echo "$(CYAN)======================================$(NC)"
@echo "$(CYAN) Vergi Hatırlatıcı Bot Info $(NC)"
@echo "$(CYAN)======================================$(NC)"
@echo "$(WHITE)Project:$(NC) Otomatik Vergi Hatırlatıcı Bot"
@echo "$(WHITE)Developer:$(NC) Taha Furkan ŞEN"
@echo "$(WHITE)Python Version:$(NC) $$(python3 --version)"
@echo "$(WHITE)Pytest Version:$(NC) $$(pytest --version 2>/dev/null || echo 'Not installed')"
@echo "$(WHITE)Coverage:$(NC) Target $(COVERAGE_THRESHOLD)%"
@echo "$(WHITE)Test Markers:$(NC) unit, integration, database, scraper, bot, slow"
@echo "$(CYAN)======================================$(NC)"
# Error handling for missing dependencies
check-deps:
@echo "$(BLUE)Checking dependencies...$(NC)"
@command -v $(PYTHON) >/dev/null 2>&1 || { echo "$(RED)Python3 is required but not installed$(NC)"; exit 1; }
@command -v $(PIP) >/dev/null 2>&1 || { echo "$(RED)Pip3 is required but not installed$(NC)"; exit 1; }
@$(PYTHON) -c "import pytest" 2>/dev/null || { echo "$(YELLOW)Pytest not found. Run 'make install-dev'$(NC)"; }
@echo "$(GREEN)Dependencies check completed!$(NC)"