Skip to content

Commit b8d3a49

Browse files
Merge pull request #35 from springfall2008/update
Version and test flow
2 parents 609ffb7 + e5a6041 commit b8d3a49

File tree

7 files changed

+379
-3
lines changed

7 files changed

+379
-3
lines changed

.github/workflows/test.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: PredAI Tests
2+
3+
on:
4+
pull_request:
5+
branches: [ main, master, develop ]
6+
push:
7+
branches: [ main, master, develop ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: '3.12'
21+
22+
- name: Cache pip packages
23+
uses: actions/cache@v4
24+
with:
25+
path: ~/.cache/pip
26+
key: ${{ runner.os }}-pip-${{ hashFiles('predai/requirements.txt') }}
27+
restore-keys: |
28+
${{ runner.os }}-pip-
29+
30+
- name: Install dependencies
31+
run: |
32+
python -m pip install --upgrade pip
33+
pip install -r predai/requirements.txt
34+
35+
- name: Run unit tests
36+
run: |
37+
python -m unittest test_predai.py -v
38+
39+
- name: Test summary
40+
if: always()
41+
run: |
42+
if [ $? -eq 0 ]; then
43+
echo "✅ All tests passed successfully!"
44+
else
45+
echo "❌ Some tests failed"
46+
exit 1
47+
fi

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ wheels/
1919
*.egg-info/
2020
.installed.cfg
2121
*.egg
22+
.lr_find*
23+
.pytest_cache/
24+
events.out.*
25+
lightning_logs/*
2226

2327
# Virtual environments
2428
venv/

predai/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
neuralprophet==0.9.0
1+
neuralprophet
22
requests
33
aiohttp
44
pyyaml

predai/rootfs/predai.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
import math
1414
import yaml
1515

16-
# Fix for PyTorch 2.6 weights_only=True default
16+
# Fix for PyTorch 2.6+ weights_only=True default
1717
# Add NeuralProphet classes to safe globals for checkpoint loading
1818
try:
19+
import torch
1920
import torch.serialization
2021
from neuralprophet.configure import (
2122
ConfigSeasonality,
@@ -27,6 +28,7 @@
2728
ConfigEvents,
2829
ConfigCountryHolidays,
2930
)
31+
from collections import OrderedDict
3032

3133
# Add all NeuralProphet configuration classes to safe globals
3234
torch.serialization.add_safe_globals([
@@ -38,7 +40,17 @@
3840
ConfigLagged,
3941
ConfigEvents,
4042
ConfigCountryHolidays,
43+
OrderedDict,
4144
])
45+
46+
# Monkey-patch torch.load to use weights_only=False by default
47+
# This is needed for PyTorch 2.6+ compatibility with PyTorch Lightning
48+
_original_torch_load = torch.load
49+
def _patched_torch_load(*args, **kwargs):
50+
if 'weights_only' not in kwargs:
51+
kwargs['weights_only'] = False
52+
return _original_torch_load(*args, **kwargs)
53+
torch.load = _patched_torch_load
4254
except (ImportError, AttributeError):
4355
# If torch.serialization or classes are not available, continue without the fix
4456
# This allows backward compatibility with older PyTorch versions
@@ -483,4 +495,5 @@ async def main():
483495
break
484496
await asyncio.sleep(60)
485497

486-
asyncio.run(main())
498+
if __name__ == "__main__":
499+
asyncio.run(main())

run_all

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
# Run all PredAI unit tests
3+
4+
set -e
5+
6+
# Check if virtual environment exists
7+
if [ ! -d "venv" ]; then
8+
echo "Error: Virtual environment not found!"
9+
echo "Please run ./setup.csh first to create the environment"
10+
exit 1
11+
fi
12+
13+
# Activate virtual environment
14+
echo "Activating virtual environment..."
15+
source venv/bin/activate
16+
17+
# Run the tests
18+
echo ""
19+
echo "Running PredAI unit tests..."
20+
echo "================================"
21+
python -m unittest test_predai.py -v
22+
23+
# Check test result
24+
if [ $? -eq 0 ]; then
25+
echo ""
26+
echo "================================"
27+
echo "✅ All tests passed successfully!"
28+
else
29+
echo ""
30+
echo "================================"
31+
echo "❌ Some tests failed"
32+
exit 1
33+
fi

setup.csh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Setup script for PredAI test environment
2+
# Creates a virtual environment and installs dependencies
3+
4+
echo "Creating Python virtual environment..."
5+
python3 -m venv venv
6+
7+
echo "Activating virtual environment..."
8+
source venv/bin/activate
9+
10+
echo "Installing dependencies..."
11+
python -m pip install --upgrade pip
12+
python -m pip install -r predai/requirements.txt
13+
14+
echo ""
15+
echo "Setup complete!"
16+
echo "To activate the environment manually, run:"
17+
echo " source venv/bin/activate.csh"
18+
echo ""
19+
echo "To run tests, execute:"
20+
echo " ./run_all"
21+

0 commit comments

Comments
 (0)