mirror of
https://github.com/esphome/esphome.git
synced 2025-02-16 01:41:42 +01:00
Add pytest to CI (#1138)
This commit is contained in:
parent
a20e71b32a
commit
d5c59292c8
42
.github/workflows/ci.yml
vendored
42
.github/workflows/ci.yml
vendored
@ -9,8 +9,6 @@ on:
|
|||||||
branches: [beta, master]
|
branches: [beta, master]
|
||||||
|
|
||||||
pull_request:
|
pull_request:
|
||||||
# Only trigger on certain events (not when comments are added)
|
|
||||||
types: [opened, reopened, synchronize]
|
|
||||||
# Only run when PR is against dev branch (all PRs should be against dev branch)
|
# Only run when PR is against dev branch (all PRs should be against dev branch)
|
||||||
# Helps prevent accidentally merging PRs against master branch
|
# Helps prevent accidentally merging PRs against master branch
|
||||||
branches: [dev]
|
branches: [dev]
|
||||||
@ -176,15 +174,6 @@ jobs:
|
|||||||
key: test-home-platformio-${{ matrix.test }}-${{ hashFiles('esphome/core_config.py') }}
|
key: test-home-platformio-${{ matrix.test }}-${{ hashFiles('esphome/core_config.py') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
test-home-platformio-${{ matrix.test }}-
|
test-home-platformio-${{ matrix.test }}-
|
||||||
# Cache the intermediary build files
|
|
||||||
- name: Cache Test Build
|
|
||||||
uses: actions/cache@v1
|
|
||||||
with:
|
|
||||||
path: tests/build/${{ matrix.test }}
|
|
||||||
key: test-pio-${{ matrix.test }}-${{ hashFiles('esphome/core_config.py') }}-${{ hashFiles('esphome/**') }}
|
|
||||||
restore-keys: |
|
|
||||||
test-pio-${{ matrix.test }}-${{ hashFiles('esphome/core_config.py') }}-
|
|
||||||
test-pio-${{ matrix.test }}-
|
|
||||||
- name: Set up environment
|
- name: Set up environment
|
||||||
run: script/setup
|
run: script/setup
|
||||||
|
|
||||||
@ -194,3 +183,34 @@ jobs:
|
|||||||
echo "::add-matcher::.github/workflows/matchers/gcc.json"
|
echo "::add-matcher::.github/workflows/matchers/gcc.json"
|
||||||
echo "::add-matcher::.github/workflows/matchers/python.json"
|
echo "::add-matcher::.github/workflows/matchers/python.json"
|
||||||
- run: esphome tests/${{ matrix.test }}.yaml compile
|
- run: esphome tests/${{ matrix.test }}.yaml compile
|
||||||
|
|
||||||
|
pytest:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.7'
|
||||||
|
- name: Cache pip modules
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.cache/pip
|
||||||
|
key: esphome-pip-3.7-${{ hashFiles('setup.py') }}
|
||||||
|
restore-keys: |
|
||||||
|
esphome-pip-3.7-
|
||||||
|
- name: Set up environment
|
||||||
|
run: script/setup
|
||||||
|
- name: Install Github Actions annotator
|
||||||
|
run: pip install pytest-github-actions-annotate-failures
|
||||||
|
|
||||||
|
- name: Register problem matchers
|
||||||
|
run: |
|
||||||
|
echo "::add-matcher::.github/workflows/matchers/python.json"
|
||||||
|
- name: Run pytest
|
||||||
|
run: |
|
||||||
|
pytest \
|
||||||
|
-qq \
|
||||||
|
--durations=10 \
|
||||||
|
-o console_output_style=count \
|
||||||
|
tests
|
||||||
|
42
.github/workflows/release-dev.yml
vendored
42
.github/workflows/release-dev.yml
vendored
@ -129,15 +129,6 @@ jobs:
|
|||||||
key: test-home-platformio-${{ matrix.test }}-${{ hashFiles('esphome/core_config.py') }}
|
key: test-home-platformio-${{ matrix.test }}-${{ hashFiles('esphome/core_config.py') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
test-home-platformio-${{ matrix.test }}-
|
test-home-platformio-${{ matrix.test }}-
|
||||||
# Cache the intermediary build files
|
|
||||||
- name: Cache Test Build
|
|
||||||
uses: actions/cache@v1
|
|
||||||
with:
|
|
||||||
path: tests/build/${{ matrix.test }}
|
|
||||||
key: test-pio-${{ matrix.test }}-${{ hashFiles('esphome/core_config.py') }}-${{ hashFiles('esphome/**') }}
|
|
||||||
restore-keys: |
|
|
||||||
test-pio-${{ matrix.test }}-${{ hashFiles('esphome/core_config.py') }}-
|
|
||||||
test-pio-${{ matrix.test }}-
|
|
||||||
- name: Set up environment
|
- name: Set up environment
|
||||||
run: script/setup
|
run: script/setup
|
||||||
|
|
||||||
@ -148,10 +139,41 @@ jobs:
|
|||||||
echo "::add-matcher::.github/workflows/matchers/python.json"
|
echo "::add-matcher::.github/workflows/matchers/python.json"
|
||||||
- run: esphome tests/${{ matrix.test }}.yaml compile
|
- run: esphome tests/${{ matrix.test }}.yaml compile
|
||||||
|
|
||||||
|
pytest:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.7'
|
||||||
|
- name: Cache pip modules
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.cache/pip
|
||||||
|
key: esphome-pip-3.7-${{ hashFiles('setup.py') }}
|
||||||
|
restore-keys: |
|
||||||
|
esphome-pip-3.7-
|
||||||
|
- name: Set up environment
|
||||||
|
run: script/setup
|
||||||
|
- name: Install Github Actions annotator
|
||||||
|
run: pip install pytest-github-actions-annotate-failures
|
||||||
|
|
||||||
|
- name: Register problem matchers
|
||||||
|
run: |
|
||||||
|
echo "::add-matcher::.github/workflows/matchers/python.json"
|
||||||
|
- name: Run pytest
|
||||||
|
run: |
|
||||||
|
pytest \
|
||||||
|
-qq \
|
||||||
|
--durations=10 \
|
||||||
|
-o console_output_style=count \
|
||||||
|
tests
|
||||||
|
|
||||||
deploy-docker:
|
deploy-docker:
|
||||||
name: Build and publish docker containers
|
name: Build and publish docker containers
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [lint-clang-format, lint-clang-tidy, lint-python, test]
|
needs: [lint-clang-format, lint-clang-tidy, lint-python, test, pytest]
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
arch: [amd64, i386, armv7, aarch64]
|
arch: [amd64, i386, armv7, aarch64]
|
||||||
|
44
.github/workflows/release.yml
vendored
44
.github/workflows/release.yml
vendored
@ -128,15 +128,6 @@ jobs:
|
|||||||
key: test-home-platformio-${{ matrix.test }}-${{ hashFiles('esphome/core_config.py') }}
|
key: test-home-platformio-${{ matrix.test }}-${{ hashFiles('esphome/core_config.py') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
test-home-platformio-${{ matrix.test }}-
|
test-home-platformio-${{ matrix.test }}-
|
||||||
# Cache the intermediary build files
|
|
||||||
- name: Cache Test Build
|
|
||||||
uses: actions/cache@v1
|
|
||||||
with:
|
|
||||||
path: tests/build/${{ matrix.test }}
|
|
||||||
key: test-pio-${{ matrix.test }}-${{ hashFiles('esphome/core_config.py') }}-${{ hashFiles('esphome/**') }}
|
|
||||||
restore-keys: |
|
|
||||||
test-pio-${{ matrix.test }}-${{ hashFiles('esphome/core_config.py') }}-
|
|
||||||
test-pio-${{ matrix.test }}-
|
|
||||||
- name: Set up environment
|
- name: Set up environment
|
||||||
run: script/setup
|
run: script/setup
|
||||||
|
|
||||||
@ -145,10 +136,41 @@ jobs:
|
|||||||
echo "::add-matcher::.github/workflows/matchers/gcc.json"
|
echo "::add-matcher::.github/workflows/matchers/gcc.json"
|
||||||
echo "::add-matcher::.github/workflows/matchers/python.json"
|
echo "::add-matcher::.github/workflows/matchers/python.json"
|
||||||
- run: esphome tests/${{ matrix.test }}.yaml compile
|
- run: esphome tests/${{ matrix.test }}.yaml compile
|
||||||
|
|
||||||
|
pytest:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.7'
|
||||||
|
- name: Cache pip modules
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.cache/pip
|
||||||
|
key: esphome-pip-3.7-${{ hashFiles('setup.py') }}
|
||||||
|
restore-keys: |
|
||||||
|
esphome-pip-3.7-
|
||||||
|
- name: Set up environment
|
||||||
|
run: script/setup
|
||||||
|
- name: Install Github Actions annotator
|
||||||
|
run: pip install pytest-github-actions-annotate-failures
|
||||||
|
|
||||||
|
- name: Register problem matchers
|
||||||
|
run: |
|
||||||
|
echo "::add-matcher::.github/workflows/matchers/python.json"
|
||||||
|
- name: Run pytest
|
||||||
|
run: |
|
||||||
|
pytest \
|
||||||
|
-qq \
|
||||||
|
--durations=10 \
|
||||||
|
-o console_output_style=count \
|
||||||
|
tests
|
||||||
|
|
||||||
deploy-pypi:
|
deploy-pypi:
|
||||||
name: Build and publish to PyPi
|
name: Build and publish to PyPi
|
||||||
needs: [lint-clang-format, lint-clang-tidy, lint-python, test]
|
needs: [lint-clang-format, lint-clang-tidy, lint-python, test, pytest]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@ -171,7 +193,7 @@ jobs:
|
|||||||
deploy-docker:
|
deploy-docker:
|
||||||
name: Build and publish docker containers
|
name: Build and publish docker containers
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [lint-clang-format, lint-clang-tidy, lint-python, test]
|
needs: [lint-clang-format, lint-clang-tidy, lint-python, test, pytest]
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
arch: [amd64, i386, armv7, aarch64]
|
arch: [amd64, i386, armv7, aarch64]
|
||||||
|
@ -493,9 +493,9 @@ class EsphomeCore:
|
|||||||
# The board that's used (for example nodemcuv2)
|
# The board that's used (for example nodemcuv2)
|
||||||
self.board: Optional[str] = None
|
self.board: Optional[str] = None
|
||||||
# The full raw configuration
|
# The full raw configuration
|
||||||
self.raw_config: ConfigType = {}
|
self.raw_config: Optional[ConfigType] = None
|
||||||
# The validated configuration, this is None until the config has been validated
|
# The validated configuration, this is None until the config has been validated
|
||||||
self.config: ConfigType = {}
|
self.config: Optional[ConfigType] = None
|
||||||
# The pending tasks in the task queue (mostly for C++ generation)
|
# The pending tasks in the task queue (mostly for C++ generation)
|
||||||
# This is a priority queue (with heapq)
|
# This is a priority queue (with heapq)
|
||||||
# Each item is a tuple of form: (-priority, unique number, task)
|
# Each item is a tuple of form: (-priority, unique number, task)
|
||||||
@ -547,6 +547,10 @@ class EsphomeCore:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def address(self) -> Optional[str]:
|
def address(self) -> Optional[str]:
|
||||||
|
if self.config is None:
|
||||||
|
raise ValueError("Config has not been loaded yet")
|
||||||
|
|
||||||
|
# pylint: disable=unsupported-membership-test,unsubscriptable-object
|
||||||
if 'wifi' in self.config:
|
if 'wifi' in self.config:
|
||||||
return self.config[CONF_WIFI][CONF_USE_ADDRESS]
|
return self.config[CONF_WIFI][CONF_USE_ADDRESS]
|
||||||
|
|
||||||
@ -557,6 +561,10 @@ class EsphomeCore:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def comment(self) -> Optional[str]:
|
def comment(self) -> Optional[str]:
|
||||||
|
if self.config is None:
|
||||||
|
raise ValueError("Config has not been loaded yet")
|
||||||
|
|
||||||
|
# pylint: disable=unsubscriptable-object
|
||||||
if CONF_COMMENT in self.config[CONF_ESPHOME]:
|
if CONF_COMMENT in self.config[CONF_ESPHOME]:
|
||||||
return self.config[CONF_ESPHOME][CONF_COMMENT]
|
return self.config[CONF_ESPHOME][CONF_COMMENT]
|
||||||
|
|
||||||
@ -570,6 +578,10 @@ class EsphomeCore:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def arduino_version(self) -> str:
|
def arduino_version(self) -> str:
|
||||||
|
if self.config is None:
|
||||||
|
raise ValueError("Config has not been loaded yet")
|
||||||
|
|
||||||
|
# pylint: disable=unsubscriptable-object
|
||||||
return self.config[CONF_ESPHOME][CONF_ARDUINO_VERSION]
|
return self.config[CONF_ESPHOME][CONF_ARDUINO_VERSION]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -256,16 +256,20 @@ ESP32_BOARD_PINS = {
|
|||||||
|
|
||||||
def _lookup_pin(value):
|
def _lookup_pin(value):
|
||||||
if CORE.is_esp8266:
|
if CORE.is_esp8266:
|
||||||
board_pins = ESP8266_BOARD_PINS.get(CORE.board, {})
|
board_pins_dict = ESP8266_BOARD_PINS
|
||||||
base_pins = ESP8266_BASE_PINS
|
base_pins = ESP8266_BASE_PINS
|
||||||
elif CORE.is_esp32:
|
elif CORE.is_esp32:
|
||||||
board_pins = ESP32_BOARD_PINS.get(CORE.board, {})
|
board_pins_dict = ESP32_BOARD_PINS
|
||||||
base_pins = ESP32_BASE_PINS
|
base_pins = ESP32_BASE_PINS
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
board_pins = board_pins_dict.get(CORE.board, {})
|
||||||
|
|
||||||
|
# Resolved aliased board pins (shorthand when two boards have the same pin configuration)
|
||||||
while isinstance(board_pins, str):
|
while isinstance(board_pins, str):
|
||||||
board_pins = ESP8266_BOARD_PINS.get(board_pins, {})
|
board_pins = board_pins_dict[board_pins]
|
||||||
|
|
||||||
if value in board_pins:
|
if value in board_pins:
|
||||||
return board_pins[value]
|
return board_pins[value]
|
||||||
if value in base_pins:
|
if value in base_pins:
|
||||||
|
@ -459,7 +459,6 @@ class TestEsphomeCore:
|
|||||||
target.config_path = "foo/config"
|
target.config_path = "foo/config"
|
||||||
return target
|
return target
|
||||||
|
|
||||||
@pytest.mark.xfail(reason="raw_config and config differ, should they?")
|
|
||||||
def test_reset(self, target):
|
def test_reset(self, target):
|
||||||
"""Call reset on target and compare to new instance"""
|
"""Call reset on target and compare to new instance"""
|
||||||
other = core.EsphomeCore()
|
other = core.EsphomeCore()
|
||||||
@ -469,15 +468,18 @@ class TestEsphomeCore:
|
|||||||
assert target.__dict__ == other.__dict__
|
assert target.__dict__ == other.__dict__
|
||||||
|
|
||||||
def test_address__none(self, target):
|
def test_address__none(self, target):
|
||||||
|
target.config = {}
|
||||||
assert target.address is None
|
assert target.address is None
|
||||||
|
|
||||||
def test_address__wifi(self, target):
|
def test_address__wifi(self, target):
|
||||||
|
target.config = {}
|
||||||
target.config[const.CONF_WIFI] = {const.CONF_USE_ADDRESS: "1.2.3.4"}
|
target.config[const.CONF_WIFI] = {const.CONF_USE_ADDRESS: "1.2.3.4"}
|
||||||
target.config["ethernet"] = {const.CONF_USE_ADDRESS: "4.3.2.1"}
|
target.config["ethernet"] = {const.CONF_USE_ADDRESS: "4.3.2.1"}
|
||||||
|
|
||||||
assert target.address == "1.2.3.4"
|
assert target.address == "1.2.3.4"
|
||||||
|
|
||||||
def test_address__ethernet(self, target):
|
def test_address__ethernet(self, target):
|
||||||
|
target.config = {}
|
||||||
target.config["ethernet"] = {const.CONF_USE_ADDRESS: "4.3.2.1"}
|
target.config["ethernet"] = {const.CONF_USE_ADDRESS: "4.3.2.1"}
|
||||||
|
|
||||||
assert target.address == "4.3.2.1"
|
assert target.address == "4.3.2.1"
|
||||||
|
@ -94,7 +94,6 @@ class Test_lookup_pin:
|
|||||||
|
|
||||||
assert actual == expected
|
assert actual == expected
|
||||||
|
|
||||||
@pytest.mark.xfail(reason="This may be expected")
|
|
||||||
def test_valid_32_pin_alias(self, core_esp32):
|
def test_valid_32_pin_alias(self, core_esp32):
|
||||||
core_esp32.board = MOCK_ESP32_BOARD_ALIAS_ID
|
core_esp32.board = MOCK_ESP32_BOARD_ALIAS_ID
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user