forked from platformio/platformio-core
Tests: skip dev-plalform without examples
This commit is contained in:
@ -12,10 +12,9 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
import random
|
import random
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from os import listdir, walk
|
|
||||||
from os.path import basename, dirname, getsize, isdir, isfile, join, normpath
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -32,24 +31,26 @@ def pytest_generate_tests(metafunc):
|
|||||||
examples_dirs = []
|
examples_dirs = []
|
||||||
|
|
||||||
# repo examples
|
# repo examples
|
||||||
examples_dirs.append(normpath(join(dirname(__file__), "..", "examples")))
|
examples_dirs.append(
|
||||||
|
os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "examples"))
|
||||||
|
)
|
||||||
|
|
||||||
# dev/platforms
|
# dev/platforms
|
||||||
for pkg in PlatformPackageManager().get_installed():
|
for pkg in PlatformPackageManager().get_installed():
|
||||||
p = PlatformFactory.new(pkg)
|
p = PlatformFactory.new(pkg)
|
||||||
examples_dir = join(p.get_dir(), "examples")
|
examples_dir = os.path.join(p.get_dir(), "examples")
|
||||||
assert isdir(examples_dir)
|
if os.path.isdir(examples_dir):
|
||||||
examples_dirs.append(examples_dir)
|
examples_dirs.append(examples_dir)
|
||||||
|
|
||||||
project_dirs = []
|
project_dirs = []
|
||||||
for examples_dir in examples_dirs:
|
for examples_dir in examples_dirs:
|
||||||
candidates = {}
|
candidates = {}
|
||||||
for root, _, files in walk(examples_dir):
|
for root, _, files in os.walk(examples_dir):
|
||||||
if "platformio.ini" not in files or ".skiptest" in files:
|
if "platformio.ini" not in files or ".skiptest" in files:
|
||||||
continue
|
continue
|
||||||
if "zephyr-" in root and PY2:
|
if "zephyr-" in root and PY2:
|
||||||
continue
|
continue
|
||||||
group = basename(root)
|
group = os.path.basename(root)
|
||||||
if "-" in group:
|
if "-" in group:
|
||||||
group = group.split("-", 1)[0]
|
group = group.split("-", 1)[0]
|
||||||
if group not in candidates:
|
if group not in candidates:
|
||||||
@ -67,7 +68,7 @@ def test_run(pioproject_dir):
|
|||||||
with fs.cd(pioproject_dir):
|
with fs.cd(pioproject_dir):
|
||||||
config = ProjectConfig()
|
config = ProjectConfig()
|
||||||
build_dir = config.get_optional_dir("build")
|
build_dir = config.get_optional_dir("build")
|
||||||
if isdir(build_dir):
|
if os.path.isdir(build_dir):
|
||||||
fs.rmtree(build_dir)
|
fs.rmtree(build_dir)
|
||||||
|
|
||||||
env_names = config.envs()
|
env_names = config.envs()
|
||||||
@ -77,18 +78,18 @@ def test_run(pioproject_dir):
|
|||||||
if result["returncode"] != 0:
|
if result["returncode"] != 0:
|
||||||
pytest.fail(str(result))
|
pytest.fail(str(result))
|
||||||
|
|
||||||
assert isdir(build_dir)
|
assert os.path.isdir(build_dir)
|
||||||
|
|
||||||
# check .elf file
|
# check .elf file
|
||||||
for item in listdir(build_dir):
|
for item in os.listdir(build_dir):
|
||||||
if not isdir(item):
|
if not os.path.isdir(item):
|
||||||
continue
|
continue
|
||||||
assert isfile(join(build_dir, item, "firmware.elf"))
|
assert os.path.isfile(os.path.join(build_dir, item, "firmware.elf"))
|
||||||
# check .hex or .bin files
|
# check .hex or .bin files
|
||||||
firmwares = []
|
firmwares = []
|
||||||
for ext in ("bin", "hex"):
|
for ext in ("bin", "hex"):
|
||||||
firmwares += glob(join(build_dir, item, "firmware*.%s" % ext))
|
firmwares += glob(os.path.join(build_dir, item, "firmware*.%s" % ext))
|
||||||
if not firmwares:
|
if not firmwares:
|
||||||
pytest.fail("Missed firmware file")
|
pytest.fail("Missed firmware file")
|
||||||
for firmware in firmwares:
|
for firmware in firmwares:
|
||||||
assert getsize(firmware) > 0
|
assert os.path.getsize(firmware) > 0
|
||||||
|
Reference in New Issue
Block a user