Skip to content

Commit 5215ba0

Browse files
committed
Claude...
1 parent 7efffb0 commit 5215ba0

12 files changed

Lines changed: 189 additions & 220 deletions

.coveragerc

Lines changed: 0 additions & 40 deletions
This file was deleted.

Makefile

Lines changed: 41 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,44 @@
1-
.PHONY: help install install-dev test test-cov lint format clean run-server run-client build docker-build docker-run pre-commit docs docs-serve
1+
.PHONY: help test clean format check install
22

3-
help: ## Show this help message
4-
@echo "Usage: make [target]"
5-
@echo ""
6-
@echo "Available targets:"
7-
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
8-
9-
install: ## Install production dependencies
10-
pip install -r requirements.txt
11-
12-
install-dev: ## Install development dependencies
13-
pip install -r requirements-dev.txt
14-
pip install -e .
15-
pre-commit install
16-
17-
test: ## Run tests
18-
pytest tests/ -v
19-
20-
test-cov: ## Run tests with coverage
21-
pytest tests/ --cov=src --cov-report=term-missing --cov-report=html:coverage/htmlcov --cov-report=xml:coverage/coverage.xml
3+
PYTHON := $(if $(wildcard .venv/bin/python),.venv/bin/python,python3)
4+
PIP := $(if $(wildcard .venv/bin/pip),.venv/bin/pip,pip3)
5+
SOURCES := tests
226

23-
test-watch: ## Run tests in watch mode
24-
pytest-watch tests/ -v
25-
26-
lint: ## Run linting checks
27-
@echo "Running flake8..."
28-
flake8 src/ tests/
29-
@echo "Running mypy..."
30-
mypy src/
31-
@echo "Running ruff..."
32-
ruff check src/ tests/
33-
34-
format: ## Format code with black and isort
35-
black src/ tests/
36-
isort src/ tests/
37-
ruff check --fix src/ tests/
38-
39-
clean: ## Clean up generated files
7+
# Default target
8+
help:
9+
@echo "Available targets:"
10+
@echo " test Run tests"
11+
@echo " format Format code with black and isort"
12+
@echo " check Run format and tests"
13+
@echo " clean Clean up generated files"
14+
@echo " install Install dependencies"
15+
@echo " update Update dependencies"
16+
17+
# Testing
18+
test:
19+
$(PYTHON) -m pytest tests/ -v --tb=short
20+
21+
# Code formatting
22+
format:
23+
$(PYTHON) -m black $(SOURCES) tests/
24+
$(PYTHON) -m isort $(SOURCES) tests/
25+
26+
# Combined check
27+
check: format test
28+
29+
# Installation
30+
install:
31+
$(PIP) install -r requirements.txt
32+
$(PIP) install -r requirements-dev.txt
33+
34+
# Updates
35+
update:
36+
$(PIP) install --upgrade pip
37+
$(PIP) install --upgrade -r requirements.txt
38+
$(PIP) install --upgrade -r requirements-dev.txt
39+
40+
# Clean up
41+
clean:
42+
rm -rf build/ dist/ *.egg-info .pytest_cache/ .mypy_cache/
43+
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
4044
find . -type f -name "*.pyc" -delete
41-
find . -type d -name "__pycache__" -delete
42-
find . -type d -name ".pytest_cache" -exec rm -rf {} +
43-
find . -type d -name ".mypy_cache" -exec rm -rf {} +
44-
find . -type d -name ".ruff_cache" -exec rm -rf {} +
45-
rm -rf coverage/
46-
rm -rf htmlcov/
47-
rm -f coverage.xml coverage.json .coverage
48-
rm -rf dist/ build/ *.egg-info src/*.egg-info
49-
50-
run-server: ## Run the WebSocket server
51-
python src/pubsub_ws.py
52-
53-
run-client: ## Run the client
54-
python src/client.py
55-
56-
build: ## Build the package
57-
python -m build
58-
59-
docker-build: ## Build Docker image
60-
docker build -t python.publisher.subscriber:latest .
61-
62-
docker-run: ## Run Docker container
63-
docker run -p 5000:5000 python.publisher.subscriber:latest
64-
65-
pre-commit: ## Run pre-commit hooks
66-
pre-commit run --all-files
67-
68-
docs: ## Generate documentation
69-
cd docs && make html
70-
71-
docs-serve: ## Serve documentation locally
72-
cd docs && python -m http.server --directory _build/html 8000

pyproject.toml

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ dependencies = [
4040
[project.optional-dependencies]
4141
dev = [
4242
"pytest==7.4.3",
43-
"pytest-cov==4.1.0",
4443
"pytest-mock==3.12.0",
4544
"pytest-asyncio==0.21.1",
4645
"pytest-watch==4.2.0",
@@ -118,44 +117,12 @@ minversion = "7.0"
118117
addopts = [
119118
"-ra",
120119
"--strict-markers",
121-
"--cov=src",
122-
"--cov-report=term-missing",
123-
"--cov-report=html:coverage/htmlcov",
124-
"--cov-report=xml:coverage/coverage.xml",
125-
"--cov-report=json:coverage/coverage.json",
126120
]
127121
testpaths = ["tests"]
128122
python_files = ["test_*.py", "*_test.py"]
129123
python_classes = ["Test*"]
130124
python_functions = ["test_*"]
131125

132-
[tool.coverage.run]
133-
source = ["src"]
134-
omit = [
135-
"*/tests/*",
136-
"*/test_*.py",
137-
"*/__pycache__/*",
138-
"*/migrations/*",
139-
"*/.venv/*",
140-
]
141-
142-
[tool.coverage.report]
143-
exclude_lines = [
144-
"pragma: no cover",
145-
"def __repr__",
146-
"if self.debug:",
147-
"if __name__ == .__main__.:",
148-
"raise AssertionError",
149-
"raise NotImplementedError",
150-
"if 0:",
151-
"if False:",
152-
"pass",
153-
]
154-
precision = 2
155-
show_missing = true
156-
157-
[tool.coverage.html]
158-
directory = "coverage/htmlcov"
159126

160127
[tool.ruff]
161128
line-length = 100

requirements-dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
# Development and testing dependencies
55
pytest==7.4.3
6-
pytest-cov==4.1.0
76
pytest-mock==3.12.0
87
pytest-asyncio==0.21.1
98
pytest-watch==4.2.0

setup.cfg

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ where = src
4242
[options.extras_require]
4343
dev =
4444
pytest==7.4.3
45-
pytest-cov==4.1.0
4645
pytest-mock==3.12.0
4746
pytest-asyncio==0.21.1
4847
pytest-watch==4.2.0
@@ -100,35 +99,7 @@ python_functions = test_*
10099
addopts =
101100
-ra
102101
--strict-markers
103-
--cov=src
104-
--cov-report=term-missing
105-
--cov-report=html:coverage/htmlcov
106-
--cov-report=xml:coverage/coverage.xml
107-
--cov-report=json:coverage/coverage.json
108102

109-
[coverage:run]
110-
source = src
111-
omit =
112-
*/tests/*
113-
*/test_*.py
114-
*/__pycache__/*
115-
*/migrations/*
116-
*/.venv/*
117-
118-
[coverage:report]
119-
exclude_lines =
120-
pragma: no cover
121-
def __repr__
122-
if self.debug:
123-
if __name__ == .__main__.:
124-
raise AssertionError
125-
raise NotImplementedError
126-
if 0:
127-
if False:
128-
pass
129-
130-
[coverage:html]
131-
directory = coverage/htmlcov
132103

133104
[isort]
134105
profile = black

src/pubsub_ws.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def init_db(db_name: str, connection: Optional[sqlite3.Connection] = None) -> No
4545

4646
# Default DB file name
4747
DB_FILE_NAME = "pubsub.db"
48-
# --- FIN MODIFICATION POUR LA GESTION DE LA DB ET LES TESTS ---
48+
# --- END MODIFICATION FOR DB MANAGEMENT AND TESTS ---
4949

5050

5151
app = Flask(__name__)
@@ -97,7 +97,7 @@ def register_subscription(self, sid: str, consumer: str, topic: str) -> None:
9797

9898
socketio.emit(
9999
"new_client",
100-
{"consumer": consumer, "topic": topic, "connected_at": time.time()}, # Ajoutez le timestamp pour l'UI
100+
{"consumer": consumer, "topic": topic, "connected_at": time.time()}, # Add timestamp for the UI
101101
)
102102
except sqlite3.Error as e:
103103
logger.error(f"Database error during subscription registration: {e}")

tests/test_basic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def test_requirements_file():
9797
content = req_file.read_text()
9898
assert "Flask" in content
9999
assert "flask-socketio" in content
100-
assert "pytest" in content
101100

102101

103102
@pytest.mark.parametrize(

tests/test_integration.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ class TestIntegration:
1717

1818
def test_json_message_structure(self):
1919
"""Test JSON message structure for pub/sub."""
20-
message = {"topic": "test", "message_id": "123", "message": "Hello World", "producer": "test_producer"}
20+
message = {
21+
"topic": "test",
22+
"message_id": "123",
23+
"message": "Hello World",
24+
"producer": "test_producer",
25+
}
2126

2227
# Test serialization
2328
json_str = json.dumps(message)
@@ -56,10 +61,13 @@ def test_database_integration(self):
5661

5762
# Test message flow
5863
cursor.execute(
59-
"INSERT INTO messages (topic, message, producer) VALUES (?, ?, ?)", ("sports", "Game started", "sports_bot")
64+
"INSERT INTO messages (topic, message, producer) VALUES (?, ?, ?)",
65+
("sports", "Game started", "sports_bot"),
6066
)
6167

62-
cursor.execute("INSERT INTO subscriptions (consumer, topic) VALUES (?, ?)", ("alice", "sports"))
68+
cursor.execute(
69+
"INSERT INTO subscriptions (consumer, topic) VALUES (?, ?)", ("alice", "sports")
70+
)
6371

6472
# Verify integration
6573
cursor.execute(
@@ -117,7 +125,8 @@ def insert_messages(thread_id):
117125
# noinspection PyShadowingNames
118126
for i in range(3):
119127
thread_cursor.execute(
120-
"INSERT INTO test_messages (content, thread_id) VALUES (?, ?)", (f"Message {i}", thread_id)
128+
"INSERT INTO test_messages (content, thread_id) VALUES (?, ?)",
129+
(f"Message {i}", thread_id),
121130
)
122131
thread_conn.commit()
123132
thread_conn.close()
@@ -235,7 +244,11 @@ def test_websocket_message_format(self):
235244
def test_subscription_matching(self):
236245
"""Test subscription topic matching logic."""
237246
# Simulate subscription patterns
238-
subscriptions = {"alice": ["sports", "news"], "bob": ["tech", "finance"], "charlie": ["sports", "tech", "news"]}
247+
subscriptions = {
248+
"alice": ["sports", "news"],
249+
"bob": ["tech", "finance"],
250+
"charlie": ["sports", "tech", "news"],
251+
}
239252

240253
# Test message routing
241254
message_topic = "sports"

0 commit comments

Comments
 (0)