Skip to content

Commit d07090e

Browse files
committed
fix: clean room test for python
1 parent ebcc9d2 commit d07090e

File tree

5 files changed

+53
-15
lines changed

5 files changed

+53
-15
lines changed

Makefile

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,27 @@ install-py: uninstall-py clean-py wasm
124124
echo "$(BOLD)📦 Phase 3: Installing $$WHEEL_PATH...$(RESET)"; \
125125
if [ -n "$(UV)" ]; then $(UV) pip install $$WHEEL_PATH; \
126126
else $(PYTHON) -m pip install $$WHEEL_PATH; fi
127-
@echo "$(BOLD)🧪 Phase 4: Integration Test (Isolated from Source)...$(RESET)"
128-
@cd $(BINDING_PY)/tests && (if [ -n "$(UV)" ]; then $(UV) run python -m pytest . -s; \
129-
else $(PYTHON) -m pytest . -s; fi)
130-
@echo "$(GREEN)$(BOLD)✅ Success: Python Wheel verified.$(RESET)"
127+
@echo "$(BOLD)🧪 Phase 4: Integration Test (Clean-Room)...$(RESET)"
128+
@TEMP_DIR=$$(mktemp -d); \
129+
echo "Temp Test Directory: $$TEMP_DIR"; \
130+
cp -r $(BINDING_PY)/tests $$TEMP_DIR/tests; \
131+
mkdir -p $$TEMP_DIR/tests/samples; \
132+
cp -r $(PROJECT_ROOT)/j2735codec/core/$(J2735_REV)/samples/jer/* $$TEMP_DIR/tests/samples/; \
133+
cd $$TEMP_DIR; \
134+
echo "Contents of temp directory:"; \
135+
ls -R; \
136+
if [ -n "$(UV)" ]; then \
137+
$(UV) init; \
138+
$(UV) venv; \
139+
WHEEL_PATH=$$(realpath $(PROJECT_ROOT)/$(BINDING_PY)/dist/*.whl | head -n1); \
140+
$(UV) pip install --upgrade pip pytest psutil $$WHEEL_PATH; \
141+
$(UV) run python -m pytest tests -s; \
142+
else \
143+
$(PYTHON) -m pip install --upgrade pip pytest; \
144+
$(PYTHON) -m pytest tests -s; \
145+
fi; \
146+
rm -rf $$TEMP_DIR; \
147+
echo "$(GREEN)$(BOLD)✅ Success: Python Wheel verified in isolation.$(RESET)"
131148

132149
clean-py:
133150
rm -rf $(PY_DIST_DIR) $(BINDING_PY)/*.egg-info
@@ -151,6 +168,7 @@ clean-js:
151168
@echo "🧹 Cleaning Node artifacts..."
152169
@rm -rf $(JS_DIST_DIR)
153170
@find $(BINDING_JS) -name "*.tgz" -delete
171+
@find . -type d -name "node_modules" -exec rm -rf {} +
154172

155173
install-js: clean-js build-js
156174
@echo "$(BOLD)🧪 Phase 1: Local Source Test...$(RESET)"
@@ -167,6 +185,7 @@ install-js: clean-js build-js
167185
$(NPM) init -y > /dev/null && \
168186
echo "📦 Installing tarball..." && \
169187
$(NPM) install $$FULL_TARBALL_PATH > /dev/null && \
188+
$(NPM) install vitest --no-save > /dev/null && \
170189
cp -r $(PROJECT_ROOT)/$(BINDING_JS)/tests ./tests && \
171190
mkdir -p samples && \
172191
cp -r $(PROJECT_ROOT)/j2735codec/core/$(J2735_REV)/samples/jer/* ./samples/ && \

etx/examples/python/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ requires-python = ">=3.9"
1111
dependencies = [
1212
"j2735codec",
1313
"paho-mqtt>=2.1.0",
14-
"protobuf>=6.33.4",
1514
"python-geohash>=0.8.5",
1615
"requests>=2.32.5",
1716
]

j2735codec/bindings/python/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ authors = [
1010
requires-python = ">=3.9"
1111
dependencies = [
1212
"wasmtime>=25.0.0",
13+
"protobuf>=6.33.4",
1314
]
1415

1516
[build-system]
@@ -18,12 +19,14 @@ build-backend = "hatchling.build"
1819

1920
[dependency-groups]
2021
dev = [
21-
"protobuf>=6.33.4",
2222
"psutil>=7.2.1",
2323
"pytest>=8.3.5",
2424
"ruff>=0.14.11",
2525
]
2626

27+
[tool.hatch.build]
28+
ignore-vcs=true
29+
2730
[tool.hatch.build.targets.wheel]
2831
packages = ["src/j2735codec"]
2932

j2735codec/bindings/python/tests/test_codec.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,29 @@
1010
from j2735codec import EncodingRules, PDUTypes, Codec, GeoRoutedHeader
1111

1212
def get_sample_dir():
13-
"""Finds the core samples directory relative to this test file."""
13+
"""Finds the core samples directory for tests.
14+
15+
Tries these locations in order:
16+
1. ./samples relative to current working directory (clean-room test)
17+
2. core/j2735_202409/samples/jer relative to project root (source tree)
18+
"""
19+
# 1. Check if samples exist relative to tests/ (clean-room / packaged test)
20+
cwd_samples = Path(__file__).parent / "samples"
21+
if cwd_samples.exists():
22+
return cwd_samples.resolve()
23+
24+
# 2. Check relative to project root (source tree / monorepo)
1425
current_file = Path(__file__).resolve()
15-
# Path navigation based on your monorepo structure
26+
# Adjust 'parents[3]' if your file depth changes
1627
project_root = current_file.parents[3]
17-
sample_path = project_root / "core" / "j2735_202409" / "samples" / "jer"
18-
return sample_path
28+
repo_samples = project_root / "core" / "j2735_202409" / "samples" / "jer"
29+
30+
if repo_samples.exists():
31+
return repo_samples.resolve()
32+
33+
raise FileNotFoundError(
34+
"Samples directory not found in either packaged samples folder or source tree."
35+
)
1936

2037
def get_sample_files():
2138
sample_dir = get_sample_dir()

uv.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)