From 4360ff7463f7aa171913d7bc991ba8a637e2c306 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 3 Feb 2018 22:59:41 +0200 Subject: [PATCH] Use examples from dev/platforms for test --- examples | 2 +- scripts/install_devplatforms.py | 30 ++++++++++++++++++++++++++++ tests/test_examples.py | 35 +++++++++++++++++++++++++++------ tox.ini | 1 + 4 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 scripts/install_devplatforms.py diff --git a/examples b/examples index 4920eec1..52af061b 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit 4920eec1fcfdbf04f1e17098d457dff2d0eb7a6d +Subproject commit 52af061b6a57669827bddf90a2f645ddd2a277b9 diff --git a/scripts/install_devplatforms.py b/scripts/install_devplatforms.py new file mode 100644 index 00000000..34e3e082 --- /dev/null +++ b/scripts/install_devplatforms.py @@ -0,0 +1,30 @@ +# Copyright (c) 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import subprocess +import sys + + +def main(): + platforms = json.loads( + subprocess.check_output( + ["platformio", "platform", "search", "--json-output"])) + for platform in platforms: + subprocess.check_call( + ["platformio", "platform", "install", platform['repository']]) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/test_examples.py b/tests/test_examples.py index 4d2a1a52..20e9cb63 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import random from glob import glob from os import listdir, walk from os.path import dirname, getsize, isdir, isfile, join, normpath @@ -19,17 +20,32 @@ from os.path import dirname, getsize, isdir, isfile, join, normpath import pytest from platformio import util +from platformio.managers.platform import PlatformFactory, PlatformManager def pytest_generate_tests(metafunc): if "pioproject_dir" not in metafunc.fixturenames: return - example_dirs = normpath(join(dirname(__file__), "..", "examples")) - project_dirs = [] - for root, _, files in walk(example_dirs): - if "platformio.ini" not in files or ".skiptest" in files: + examples_dirs = [] + + # repo examples + examples_dirs.append(normpath(join(dirname(__file__), "..", "examples"))) + + # dev/platforms + for manifest in PlatformManager().get_installed(): + p = PlatformFactory.newPlatform(manifest['__pkg_dir']) + if not p.is_embedded(): continue - project_dirs.append(root) + examples_dir = join(p.get_dir(), "examples") + assert isdir(examples_dir) + examples_dirs.append(examples_dir) + + project_dirs = [] + for examples_dir in examples_dirs: + for root, _, files in walk(examples_dir): + if "platformio.ini" not in files or ".skiptest" in files: + continue + project_dirs.append(root) project_dirs.sort() metafunc.parametrize("pioproject_dir", project_dirs) @@ -41,7 +57,14 @@ def test_run(pioproject_dir): if isdir(build_dir): util.rmtree_(build_dir) - result = util.exec_command(["platformio", "--force", "run"]) + env_names = [] + for section in util.load_project_config().sections(): + if section.startswith("env:"): + env_names.append(section[4:]) + + result = util.exec_command( + ["platformio", "run", "-e", + random.choice(env_names)]) if result['returncode'] != 0: pytest.fail(result) diff --git a/tox.ini b/tox.ini index f1196266..6432347f 100644 --- a/tox.ini +++ b/tox.ini @@ -58,6 +58,7 @@ deps = pytest commands = {envpython} --version + {envpython} scripts/install_devplatforms.py py.test -v --basetemp="{envtmpdir}" tests [testenv:skipexamples]