Skip to content

Commit

Permalink
Merge pull request #75 from valeros/develop
Browse files Browse the repository at this point in the history
Add integration test for "examples" / issue #2
  • Loading branch information
ivankravets committed Feb 13, 2015
2 parents 42caf78 + 68db70e commit ac14103
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 43 deletions.
6 changes: 2 additions & 4 deletions docs/userguide/cmd_settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Get/List existing settings
Examples
~~~~~~~~

1. List all settings and theirs current values
1. List all settings and current their values

.. code-block:: bash
Expand All @@ -38,9 +38,7 @@ Examples
auto_update_platforms Yes Automatically update platforms (Yes/No)
check_libraries_interval 7 Check for the library updates interval (days)
check_platformio_interval 3 Check for the new PlatformIO interval (days)
check_platforms_interval 7 Check for the platform updates interval (days)
enable_prompts Yes Can PlatformIO communicate with you via prompts: propose to install platforms which aren't installed yet, paginate over library search results and etc.)? ATTENTION!!! If you call PlatformIO like subprocess, please disable prompts to avoid blocking (Yes/No)
enable_telemetry Yes Shares commands, platforms and libraries usage to help us make PlatformIO better (Yes/No)
check_platforms_interval 7 Check for the platforms updates interval (days)
2. Show specified setting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,4 @@ Console Output
^
.pioenvs/arduino_uno/Adafruit_CC3000_Library/utility/sntp.cpp: In member function 'char sntp::GetNTPServerList(const char**, uint32_t*, int)':
.pioenvs/arduino_uno/Adafruit_CC3000_Library/utility/sntp.cpp:360:25: warning: converting to non-pointer type 'uint32_t {aka long unsigned int}' from NULL [-Wconversion-null]
uint32_t ntpServer= NULL;
uint32_t ntpServer= NULL;
2 changes: 1 addition & 1 deletion platformio/boards/arduino.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,5 +560,5 @@
"use_1200bps_touch": true,
"wait_for_upload_port": false
}
}
}
}
6 changes: 2 additions & 4 deletions platformio/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,9 @@
if "BOARD_F_CPU" not in env:
env.Replace(BOARD_F_CPU="${BOARD_OPTIONS['build']['f_cpu']}")
if "UPLOAD_PROTOCOL" not in env:
env.Replace(
UPLOAD_PROTOCOL="${BOARD_OPTIONS['upload'].get('protocol', None)}")
env.Replace(UPLOAD_PROTOCOL="${BOARD_OPTIONS['upload']['protocol']}")
if "UPLOAD_SPEED" not in env:
env.Replace(
UPLOAD_SPEED="${BOARD_OPTIONS['upload'].get('speed', None)}")
env.Replace(UPLOAD_SPEED="${BOARD_OPTIONS['upload']['speed']}")

if "IGNORE_LIBS" in env:
env['IGNORE_LIBS'] = [l.strip() for l in env['IGNORE_LIBS'].split(",")]
Expand Down
54 changes: 23 additions & 31 deletions platformio/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

import requests

from platformio import __apiurl__, __version__, exception
from platformio import __apiurl__, __version__
from platformio.exception import (APIRequestError, GetSerialPortsError,
NotPlatformProject)

try:
from configparser import ConfigParser
Expand All @@ -31,7 +33,7 @@ def get_home_dir():
if (config.has_section("platformio") and
config.has_option("platformio", "home_dir")):
home_dir = config.get("platformio", "home_dir")
except exception.NotPlatformProject:
except NotPlatformProject:
pass

if not home_dir:
Expand All @@ -53,7 +55,7 @@ def get_lib_dir():
if lib_dir.startswith("~"):
lib_dir = expanduser(lib_dir)
return abspath(lib_dir)
except exception.NotPlatformProject:
except NotPlatformProject:
pass
return join(get_home_dir(), "lib")

Expand All @@ -73,7 +75,7 @@ def get_pioenvs_dir():
def get_project_config():
path = join(get_project_dir(), "platformio.ini")
if not isfile(path):
raise exception.NotPlatformProject(get_project_dir())
raise NotPlatformProject(get_project_dir())
cp = ConfigParser()
cp.read(path)
return cp
Expand All @@ -99,7 +101,7 @@ def get_serialports():
elif os_name == "posix":
from serial.tools.list_ports_posix import comports
else:
raise exception.GetSerialPortsError(os_name)
raise GetSerialPortsError(os_name)
return[{"port": p, "description": d, "hwid": h} for p, d, h in comports()]


Expand All @@ -125,15 +127,14 @@ def get_api_result(path, params=None, data=None):
r.raise_for_status()
except requests.exceptions.HTTPError as e:
if result and "errors" in result:
raise exception.APIRequestError(result['errors'][0]['title'])
raise APIRequestError(result['errors'][0]['title'])
else:
raise exception.APIRequestError(e)
raise APIRequestError(e)
except requests.exceptions.ConnectionError:
raise exception.APIRequestError(
raise APIRequestError(
"Could not connect to PlatformIO Registry Service")
except ValueError:
raise exception.APIRequestError(
"Invalid response: %s" % r.text.encode("utf-8"))
raise APIRequestError("Invalid response: %s" % r.text.encode("utf-8"))
finally:
if r:
r.close()
Expand All @@ -142,24 +143,15 @@ def get_api_result(path, params=None, data=None):

def get_boards(type_=None):
boards = {}
try:
boards = get_boards._cache # pylint: disable=W0212
except AttributeError:
bdirs = [join(get_source_dir(), "boards")]
if isdir(join(get_home_dir(), "boards")):
bdirs.append(join(get_home_dir(), "boards"))

for bdir in bdirs:
for json_file in listdir(bdir):
if not json_file.endswith(".json"):
continue
with open(join(bdir, json_file)) as f:
boards.update(json.load(f))
get_boards._cache = boards # pylint: disable=W0212

if type_ is None:
return boards
else:
if type_ not in boards:
raise exception.UnknownBoard(type_)
return boards[type_]
bdirs = [join(get_source_dir(), "boards")]
if isdir(join(get_home_dir(), "boards")):
bdirs.append(join(get_home_dir(), "boards"))

for bdir in bdirs:
for json_file in listdir(bdir):
if not json_file.endswith(".json"):
continue
with open(join(bdir, json_file)) as f:
boards.update(json.load(f))

return boards[type_] if type_ is not None else boards
70 changes: 70 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details.

from os import listdir, walk
from os.path import dirname, getsize, isdir, isfile, join, normpath
from shutil import rmtree

import pytest

from platformio import app
from platformio.util import exec_command


@pytest.fixture(scope="module")
def platformio_setup(request):
prev_settings = dict(
enable_telemetry=None,
enable_prompts=None
)
for key, value in prev_settings.iteritems():
prev_settings[key] = app.get_setting(key)
# disable temporary
if prev_settings[key]:
app.set_setting(key, False)

def platformio_teardown():
# restore settings
for key, value in prev_settings.iteritems():
app.set_setting(key, value)

request.addfinalizer(platformio_teardown)


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:
continue
project_dirs.append(root)
metafunc.parametrize("pioproject_dir", project_dirs)


def test_run(platformio_setup, pioproject_dir):
if isdir(join(pioproject_dir, ".pioenvs")):
rmtree(join(pioproject_dir, ".pioenvs"))

result = exec_command(
["platformio", "run"],
cwd=pioproject_dir
)
output = "%s\n%s" % (result['out'], result['err'])
if "error" in output.lower():
pytest.fail(output)

# check .elf file
pioenvs_dir = join(pioproject_dir, ".pioenvs")
for item in listdir(pioenvs_dir):
assert isfile(join(pioenvs_dir, item, "firmware.elf"))
# check .hex or .bin file
bin_file = join(pioenvs_dir, item, "firmware.bin")
hex_file = join(pioenvs_dir, item, "firmware.hex")
if not isfile(bin_file):
if not isfile(hex_file):
pytest.fail("Missed firmware file")
assert getsize(hex_file) > 0
else:
assert getsize(bin_file) > 0
14 changes: 13 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details.

[tox]
# toxworkdir = /tmp/.tox
# toxworkdir = C:\Users\User\Downloads\.tox
envlist = docs, lint
envlist = docs, lint, pytest

[testenv]
envlogdir = /tmp/toxlogdir
Expand Down Expand Up @@ -33,3 +36,12 @@ deps =
commands =
flake8 ./platformio
pylint --rcfile=./.pylintrc ./platformio

[testenv:pytest]
changedir = tests
usedevelop = True
deps =
pytest
commands =
pip install --egg http://sourceforge.net/projects/scons/files/latest/download
py.test -v -s --basetemp={envtmpdir}

0 comments on commit ac14103

Please sign in to comment.