From b9ff3d6f9a4df29f9089cac19d3cd338a196dc45 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sun, 28 Aug 2022 13:42:55 -0700 Subject: [PATCH] Try to copy over files --- .github/workflows/ci.yaml | 14 +++++++++----- test_dependencies.py | 27 +++++++++++++++++++++++++++ tests/test_config_flow.py | 2 +- tests/test_init.py | 4 ++-- tests/test_switch.py | 6 +++--- 5 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 test_dependencies.py diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 12074486..4e8ec83a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,7 +21,7 @@ jobs: uses: actions/checkout@v3.0.2 with: repository: home-assistant/core - path: homeassistant + path: core - name: Set up Python ${{ matrix.python-version }} id: python uses: actions/setup-python@v4.1.0 @@ -31,10 +31,14 @@ jobs: run: | pip install --upgrade pip pip install --upgrade pytest - pip install -r homeassistant/requirements.txt - pip install -r homeassistant/requirements_test_all.txt - pip install -e homeassistant/ + pip install -r core/requirements.txt + pip install -r core/requirements_test.txt + pip install -e core/ + pip install $(python test_dependencies.py) - name: Run pytest timeout-minutes: 60 run: | - PYTHONPATH=${PYTHONPATH}:custom_components/:homeassistant/tests pytest tests + cp -r custom_components/adaptive_lighting core/homeassistant/components/adaptive_lighting + cp -r tests/ core/tests/components/adaptive_lighting + cd core + pytest tests/components/adaptive_lighting diff --git a/test_dependencies.py b/test_dependencies.py new file mode 100644 index 00000000..3886b747 --- /dev/null +++ b/test_dependencies.py @@ -0,0 +1,27 @@ +from collections import defaultdict + +with open("core/requirements_test_all.txt") as f: + lines = f.readlines() + +components = [] +packages = [] +deps = {} +for i, line in enumerate(lines): + line = line.strip() + if line.startswith("# homeassistant."): + component = line.split("# homeassistant.")[1] + components.append(component) + elif components and line: + packages.append(line) + else: + for component in components: + for package in packages: + deps.setdefault(component, []).append(package) + components = [] + packages = [] + +required = ["components.recorder", "components.mqtt", "components.zeroconf"] +to_install = [] +for r in required: + to_install.extend(deps[r]) +print(" ".join(to_install)) diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index 5666cea0..53901cf9 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -1,6 +1,6 @@ """Test Adaptive Lighting config flow.""" from homeassistant import data_entry_flow -from adaptive_lighting.const import ( +from homeassistant.components.adaptive_lighting.const import ( CONF_SUNRISE_TIME, CONF_SUNSET_TIME, DEFAULT_NAME, diff --git a/tests/test_init.py b/tests/test_init.py index ed87a4ba..53f05c61 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -1,7 +1,7 @@ """Tests for Adaptive Lighting integration.""" from homeassistant import config_entries -import adaptive_lighting -from adaptive_lighting.const import ( +from homeassistant.components import adaptive_lighting +from homeassistant.components.adaptive_lighting.const import ( DEFAULT_NAME, UNDO_UPDATE_LISTENER, ) diff --git a/tests/test_switch.py b/tests/test_switch.py index f61170e9..e2bb19bd 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -6,7 +6,7 @@ from random import randint import pytest -from adaptive_lighting.const import ( +from homeassistant.components.adaptive_lighting.const import ( ADAPT_BRIGHTNESS_SWITCH, ADAPT_COLOR_SWITCH, ATTR_TURN_ON_OFF_LISTENER, @@ -31,7 +31,7 @@ from adaptive_lighting.const import ( SLEEP_MODE_SWITCH, UNDO_UPDATE_LISTENER, ) -from adaptive_lighting.switch import ( +from homeassistant.components.adaptive_lighting.switch import ( _attributes_have_changed, _expand_light_groups, color_difference_redmean, @@ -63,7 +63,7 @@ from homeassistant.core import Context, State from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util -from tests.async_mock import patch +from unittest.mock import patch from tests.common import MockConfigEntry from tests.components.demo.test_light import ENTITY_LIGHT