2016-01-01 20:51:48 +02:00
|
|
|
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
|
2015-11-18 17:16:17 +02:00
|
|
|
#
|
|
|
|
# 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.
|
2015-04-17 15:32:33 +01:00
|
|
|
|
|
|
|
import json
|
2016-08-01 17:05:48 +03:00
|
|
|
import os
|
|
|
|
from os.path import join
|
2015-04-17 15:32:33 +01:00
|
|
|
|
2016-08-01 17:05:48 +03:00
|
|
|
from platformio import exception, util
|
2016-08-02 19:10:29 +03:00
|
|
|
from platformio.commands import platform as cli_platform
|
2015-04-17 15:32:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_list_json_output(clirunner, validate_cliresult):
|
2016-08-01 17:05:48 +03:00
|
|
|
result = clirunner.invoke(cli_platform.platform_list, ["--json-output"])
|
2015-04-17 15:32:33 +01:00
|
|
|
validate_cliresult(result)
|
|
|
|
list_result = json.loads(result.output)
|
|
|
|
assert isinstance(list_result, list)
|
|
|
|
assert len(list_result)
|
|
|
|
platforms = [item['name'] for item in list_result]
|
|
|
|
assert "titiva" in platforms
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_raw_output(clirunner, validate_cliresult):
|
2016-08-01 17:05:48 +03:00
|
|
|
result = clirunner.invoke(cli_platform.platform_list)
|
2015-04-17 15:32:33 +01:00
|
|
|
validate_cliresult(result)
|
|
|
|
assert "teensy" in result.output
|
|
|
|
|
|
|
|
|
|
|
|
def test_search_json_output(clirunner, validate_cliresult):
|
2016-08-01 17:05:48 +03:00
|
|
|
result = clirunner.invoke(cli_platform.platform_search,
|
2015-04-17 15:32:33 +01:00
|
|
|
["arduino", "--json-output"])
|
|
|
|
validate_cliresult(result)
|
|
|
|
search_result = json.loads(result.output)
|
|
|
|
assert isinstance(search_result, list)
|
|
|
|
assert len(search_result)
|
2016-05-28 22:51:33 +03:00
|
|
|
platforms = [item['name'] for item in search_result]
|
2015-04-17 15:32:33 +01:00
|
|
|
assert "atmelsam" in platforms
|
|
|
|
|
|
|
|
|
|
|
|
def test_search_raw_output(clirunner, validate_cliresult):
|
2016-08-01 17:05:48 +03:00
|
|
|
result = clirunner.invoke(cli_platform.platform_search, ["arduino"])
|
2015-04-17 15:32:33 +01:00
|
|
|
validate_cliresult(result)
|
|
|
|
assert "teensy" in result.output
|
2016-08-01 17:05:48 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_install_uknown_from_registry(clirunner, validate_cliresult):
|
|
|
|
result = clirunner.invoke(cli_platform.platform_install,
|
|
|
|
["uknown-platform"])
|
|
|
|
assert result.exit_code == -1
|
|
|
|
assert isinstance(result.exception, exception.UnknownPackage)
|
|
|
|
|
|
|
|
|
|
|
|
def test_install_uknown_version(clirunner, validate_cliresult):
|
|
|
|
result = clirunner.invoke(cli_platform.platform_install,
|
|
|
|
["atmelavr@99.99.99"])
|
|
|
|
assert result.exit_code == -1
|
|
|
|
assert isinstance(result.exception, exception.UndefinedPackageVersion)
|
|
|
|
|
|
|
|
|
|
|
|
def test_complex(clirunner, validate_cliresult):
|
|
|
|
items = [
|
|
|
|
"teensy",
|
|
|
|
"https://github.com/platformio/platform-teensy/archive/develop.zip",
|
|
|
|
"https://github.com/platformio/platform-teensy.git",
|
|
|
|
"platformio/platform-teensy",
|
|
|
|
]
|
|
|
|
for item in items:
|
|
|
|
with clirunner.isolated_filesystem():
|
|
|
|
os.environ["PLATFORMIO_HOME_DIR"] = os.getcwd()
|
|
|
|
try:
|
|
|
|
result = clirunner.invoke(cli_platform.platform_install,
|
|
|
|
[item])
|
|
|
|
validate_cliresult(result)
|
|
|
|
assert all([
|
|
|
|
s in result.output
|
|
|
|
for s in ("teensy", "Downloading", "Unpacking",
|
|
|
|
"tool-scons")
|
|
|
|
])
|
|
|
|
|
|
|
|
# show platform information
|
|
|
|
result = clirunner.invoke(cli_platform.platform_show,
|
|
|
|
["teensy"])
|
|
|
|
validate_cliresult(result)
|
|
|
|
assert "teensy" in result.output
|
|
|
|
|
|
|
|
# list platforms
|
|
|
|
result = clirunner.invoke(cli_platform.platform_list,
|
|
|
|
["--json-output"])
|
|
|
|
validate_cliresult(result)
|
|
|
|
list_result = json.loads(result.output)
|
|
|
|
assert isinstance(list_result, list)
|
|
|
|
assert len(list_result) == 1
|
|
|
|
assert list_result[0]["name"] == "teensy"
|
|
|
|
assert list_result[0]["packages"] == ["tool-scons"]
|
|
|
|
|
|
|
|
# try to install again
|
|
|
|
result = clirunner.invoke(cli_platform.platform_install,
|
|
|
|
["teensy"])
|
|
|
|
validate_cliresult(result)
|
|
|
|
assert "is already installed" in result.output
|
|
|
|
|
|
|
|
# try to update
|
|
|
|
result = clirunner.invoke(cli_platform.platform_update)
|
|
|
|
validate_cliresult(result)
|
|
|
|
assert "teensy" in result.output
|
|
|
|
assert "Up-to-date" in result.output
|
|
|
|
|
|
|
|
# try to uninstall
|
|
|
|
result = clirunner.invoke(cli_platform.platform_uninstall,
|
|
|
|
["teensy"])
|
|
|
|
validate_cliresult(result)
|
|
|
|
for folder in ("platforms", "packages"):
|
|
|
|
assert len(os.listdir(join(util.get_home_dir(),
|
|
|
|
folder))) == 0
|
|
|
|
finally:
|
|
|
|
del os.environ["PLATFORMIO_HOME_DIR"]
|