diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index b2bd760..a59db23 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -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 diff --git a/.gitignore b/.gitignore index 23ab267..50e2fb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Home Assistant config/ +tests/script/ tests/hass/ # Byte-compiled / optimized / DLL files diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..24ee5b1 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.13 diff --git a/README.md b/README.md index 4392244..5f62c93 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 4b46118..56c2d21 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,6 @@ dev = [ "tox", # Home Assistant fixtures "freezegun", - "pytest-asyncio", "pytest-socket", "requests-mock", "syrupy", diff --git a/scripts/download_fixtures.sh b/scripts/download_fixtures.sh index b545a90..22698f7 100755 --- a/scripts/download_fixtures.sh +++ b/scripts/download_fixtures.sh @@ -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/"