Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ generate:
docker-compose run --rm -T protoc

test:
./tools/tests/run_tests.sh
./tools/tests/run_tests.sh $(TEST_FILE)
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
image: mongo:latest
container_name: test_mongodb
ports:
- "27017:27017"
- "27015:27017"
environment:
MONGO_INITDB_DATABASE: test_stock_db
protoc:
Expand All @@ -15,8 +15,8 @@ services:
- ./src/proto:/app/src/proto
- ./tools/protoc:/app/tools/protoc
working_dir: /app
command: ["/app/tools/protoc/gen-protoc.sh"]
command: [ "/app/tools/protoc/gen-protoc.sh" ]

networks:
default:
name: python-proto-net
name: python-proto-net
2 changes: 1 addition & 1 deletion src/tests/test_stock_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@pytest.fixture(scope="module")
def mongo_client():
client = MongoClient("mongodb://localhost:27017")
client = MongoClient("mongodb://localhost:27015")
yield client
client.drop_database("test_stock_db")
client.close()
Expand Down
12 changes: 11 additions & 1 deletion tools/tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ else
cov_report="--cov-report=term-missing"
fi

# Check if a test file path is provided as an argument
TEST_FILE=$1
if [ -n "$TEST_FILE" ]; then
echo -e "Running tests for: $TEST_FILE"
TEST_PATH="$TEST_FILE"
else
echo -e "Running all tests under src/tests"
TEST_PATH="src/tests/"
fi

# Run pytest with coverage
PYTHONPATH=./src uv run pytest src/tests/ --cov=src $cov_report -v
PYTHONPATH=./src uv run pytest "$TEST_PATH" --cov=src $cov_report -v
pytest_exit_code=$?
# Extract total coverage percentage
total_coverage=$(uv run coverage report | grep TOTAL | awk '{print $NF}' | sed 's/%//')
Expand Down
6 changes: 2 additions & 4 deletions tools/tests/wait_for_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
from pymongo.errors import ConnectionFailure, ServerSelectionTimeoutError


def wait_for_mongo(host="localhost", port=27017, timeout=30, db_name="test_stock_db"):
def wait_for_mongo(host="localhost", port=27015, timeout=30, db_name="test_stock_db"):
"""Wait for MongoDB to be ready by attempting to connect and ping."""
start_time = time.time()
while time.time() - start_time < timeout:
try:
client = MongoClient(
f"mongodb://{host}:{port}", serverSelectionTimeoutMS=1000
)
client = MongoClient(f"mongodb://{host}:{port}", serverSelectionTimeoutMS=1000)
client.admin.command("ping") # Ping the server to check if it's ready
client.drop_database(db_name) # Ensure clean state
client.close()
Expand Down