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 .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

- name: Install Home Assistant testing platform
run: |
./scripts/download_fixtures.sh $(curl --silent "https://api.github.com/repos/home-assistant/core/releases/latest" | grep -Po "(?<=\"tag_name\": \").*(?=\")")
./scripts/download_fixtures.sh $(curl --silent "https://api.github.com/repos/home-assistant/core/releases/latest" | sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p')

- name: Test with tox environments
run: tox
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Home Assistant
config/
tests/script/
tests/hass/

# Byte-compiled / optimized / DLL files
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ terminal:

```bash
# Initialize the environment with the latest version of Home Assistant
E_HASS_VERSION=$(curl --silent "https://api.github.com/repos/home-assistant/core/releases/latest" | grep -Po "(?<=\"tag_name\": \").*(?=\")")
E_HASS_VERSION=$(curl --silent "https://api.github.com/repos/home-assistant/core/releases/latest" | sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p')
./scripts/init $E_HASS_VERSION
source venv/bin/activate

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ dev = [
"tox",
# Home Assistant fixtures
"freezegun",
"pytest-asyncio",
"pytest-socket",
"requests-mock",
"syrupy",
Expand Down
52 changes: 28 additions & 24 deletions scripts/download_fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,31 @@ fi

# Variables
DOWNLOAD_FOLDER=$(mktemp -d)
HASS_TESTS_FOLDER=$DOWNLOAD_FOLDER/core-$VERSION/tests/

# Remove previous folder if exists
if [ -d "tests/hass" ]; then
echo "Removing previous tests/hass/ folder"
rm -rf tests/hass
fi

# Download HASS version
echo "Downloading Home Assistant $VERSION in $DOWNLOAD_FOLDER"
curl -L https://github.com/home-assistant/core/archive/refs/tags/$VERSION.tar.gz -o $DOWNLOAD_FOLDER/$VERSION.tar.gz

# Extract HASS fixtures and tests helpers, excluding all components and actual tests
echo "Extracting tests/ folder from $VERSION.tar.gz"
tar -C $DOWNLOAD_FOLDER --exclude='*/components/*' --exclude='*/pylint/*' -xf $DOWNLOAD_FOLDER/$VERSION.tar.gz core-$VERSION/tests
find $HASS_TESTS_FOLDER -type f -name "test_*.py" -delete

# Recursively find and update imports
find $HASS_TESTS_FOLDER -type f -exec sed -i 's/from tests\./from tests.hass./g' {} +
mv $HASS_TESTS_FOLDER/conftest.py $HASS_TESTS_FOLDER/fixtures.py

# Copy Home Assistant fixtures
mv $HASS_TESTS_FOLDER ./tests/hass
echo "Home Assistant $VERSION tests are now in tests/hass/"
HASS_FOLDER="$DOWNLOAD_FOLDER/core-$VERSION"

# Remove previous folders if they exist
rm -rf tests/hass tests/script

# Download and extract Home Assistant
echo "Downloading Home Assistant $VERSION..."
curl -sL "https://github.com/home-assistant/core/archive/refs/tags/$VERSION.tar.gz" -o "$DOWNLOAD_FOLDER/$VERSION.tar.gz"

echo "Extracting fixtures..."
tar -C "$DOWNLOAD_FOLDER" -xf "$DOWNLOAD_FOLDER/$VERSION.tar.gz" \
--exclude='*/components/*' \
--exclude='*/pylint/*' \
"core-$VERSION/tests" \
"core-$VERSION/script/__init__.py" \
"core-$VERSION/script/hassfest/__init__.py" \
"core-$VERSION/script/hassfest/model.py"

# Process tests folder
find "$HASS_FOLDER/tests" -type f -name "test_*.py" -delete
find "$HASS_FOLDER" -type f -name "*.py" -exec perl -pi -e 's/from (tests|script)\./from tests.$1./g' {} +
mv "$HASS_FOLDER/tests/conftest.py" "$HASS_FOLDER/tests/fixtures.py"

# Move to final location
mv "$HASS_FOLDER/tests" ./tests/hass
mv "$HASS_FOLDER/script" ./tests/script

echo "Home Assistant $VERSION fixtures installed in tests/"
Loading