2017-06-05 16:02:39 +03:00
|
|
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
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
|
|
|
|
|
2017-01-30 20:21:16 +02:00
|
|
|
from platformio import exception
|
2016-08-02 19:10:29 +03:00
|
|
|
from platformio.commands import platform as cli_platform
|
2015-04-17 15:32:33 +01:00
|
|
|
|
|
|
|
|
2020-06-27 12:36:57 +03:00
|
|
|
def test_search_json_output(clirunner, validate_cliresult, isolated_pio_core):
|
2019-09-23 23:13:48 +03:00
|
|
|
result = clirunner.invoke(
|
|
|
|
cli_platform.platform_search, ["arduino", "--json-output"]
|
|
|
|
)
|
2015-04-17 15:32:33 +01:00
|
|
|
validate_cliresult(result)
|
|
|
|
search_result = json.loads(result.output)
|
|
|
|
assert isinstance(search_result, list)
|
2018-01-13 01:19:41 +02:00
|
|
|
assert search_result
|
2019-09-23 23:13:48 +03:00
|
|
|
platforms = [item["name"] for item in search_result]
|
2015-04-17 15:32:33 +01:00
|
|
|
assert "atmelsam" in platforms
|
|
|
|
|
|
|
|
|
2018-01-13 01:19:41 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
2018-01-13 01:19:41 +02:00
|
|
|
def test_install_unknown_version(clirunner):
|
2019-09-23 23:13:48 +03:00
|
|
|
result = clirunner.invoke(cli_platform.platform_install, ["atmelavr@99.99.99"])
|
2019-05-09 00:51:28 +03:00
|
|
|
assert result.exit_code != 0
|
2017-01-30 20:21:16 +02:00
|
|
|
assert isinstance(result.exception, exception.UndefinedPackageVersion)
|
|
|
|
|
|
|
|
|
2018-01-13 01:19:41 +02:00
|
|
|
def test_install_unknown_from_registry(clirunner):
|
2019-09-23 23:13:48 +03:00
|
|
|
result = clirunner.invoke(cli_platform.platform_install, ["unknown-platform"])
|
2019-05-09 00:51:28 +03:00
|
|
|
assert result.exit_code != 0
|
2016-08-01 17:05:48 +03:00
|
|
|
assert isinstance(result.exception, exception.UnknownPackage)
|
|
|
|
|
|
|
|
|
2020-06-27 12:36:57 +03:00
|
|
|
def test_install_known_version(clirunner, validate_cliresult, isolated_pio_core):
|
2019-09-23 23:13:48 +03:00
|
|
|
result = clirunner.invoke(
|
|
|
|
cli_platform.platform_install,
|
|
|
|
["atmelavr@1.2.0", "--skip-default-package", "--with-package", "tool-avrdude"],
|
|
|
|
)
|
2017-01-30 20:21:16 +02:00
|
|
|
validate_cliresult(result)
|
2017-09-21 23:57:55 +03:00
|
|
|
assert "atmelavr @ 1.2.0" in result.output
|
2017-01-30 22:36:25 +02:00
|
|
|
assert "Installing tool-avrdude @" in result.output
|
2020-06-27 12:36:57 +03:00
|
|
|
assert len(isolated_pio_core.join("packages").listdir()) == 1
|
2017-01-30 20:21:16 +02:00
|
|
|
|
|
|
|
|
2020-06-27 12:36:57 +03:00
|
|
|
def test_install_from_vcs(clirunner, validate_cliresult, isolated_pio_core):
|
2019-09-23 23:13:48 +03:00
|
|
|
result = clirunner.invoke(
|
|
|
|
cli_platform.platform_install,
|
|
|
|
[
|
2020-04-06 18:19:34 +03:00
|
|
|
"https://github.com/platformio/" "platform-espressif8266.git",
|
2019-09-23 23:13:48 +03:00
|
|
|
"--skip-default-package",
|
|
|
|
],
|
|
|
|
)
|
2017-01-18 15:19:46 +02:00
|
|
|
validate_cliresult(result)
|
2017-11-26 01:02:21 +02:00
|
|
|
assert "espressif8266" in result.output
|
2020-06-27 12:36:57 +03:00
|
|
|
assert len(isolated_pio_core.join("packages").listdir()) == 1
|
2017-01-18 15:19:46 +02:00
|
|
|
|
|
|
|
|
2018-01-13 01:19:41 +02:00
|
|
|
def test_list_json_output(clirunner, validate_cliresult):
|
2017-01-30 20:21:16 +02:00
|
|
|
result = clirunner.invoke(cli_platform.platform_list, ["--json-output"])
|
|
|
|
validate_cliresult(result)
|
|
|
|
list_result = json.loads(result.output)
|
|
|
|
assert isinstance(list_result, list)
|
2018-01-13 01:19:41 +02:00
|
|
|
assert list_result
|
2019-09-23 23:13:48 +03:00
|
|
|
platforms = [item["name"] for item in list_result]
|
2017-11-26 01:02:21 +02:00
|
|
|
assert set(["atmelavr", "espressif8266"]) == set(platforms)
|
2017-01-30 20:21:16 +02:00
|
|
|
|
|
|
|
|
2018-01-13 01:19:41 +02:00
|
|
|
def test_list_raw_output(clirunner, validate_cliresult):
|
2017-01-30 20:21:16 +02:00
|
|
|
result = clirunner.invoke(cli_platform.platform_list)
|
|
|
|
validate_cliresult(result)
|
2019-09-23 23:13:48 +03:00
|
|
|
assert all([s in result.output for s in ("atmelavr", "espressif8266")])
|
2017-01-30 20:21:16 +02:00
|
|
|
|
2016-08-01 17:05:48 +03:00
|
|
|
|
2020-06-27 12:36:57 +03:00
|
|
|
def test_update_check(clirunner, validate_cliresult, isolated_pio_core):
|
2019-09-23 23:13:48 +03:00
|
|
|
result = clirunner.invoke(
|
|
|
|
cli_platform.platform_update, ["--only-check", "--json-output"]
|
|
|
|
)
|
2017-01-30 20:21:16 +02:00
|
|
|
validate_cliresult(result)
|
|
|
|
output = json.loads(result.output)
|
|
|
|
assert len(output) == 1
|
2019-09-23 23:13:48 +03:00
|
|
|
assert output[0]["name"] == "atmelavr"
|
2020-06-27 12:36:57 +03:00
|
|
|
assert len(isolated_pio_core.join("packages").listdir()) == 1
|
2017-01-30 22:36:25 +02:00
|
|
|
|
|
|
|
|
2020-06-27 12:36:57 +03:00
|
|
|
def test_update_raw(clirunner, validate_cliresult, isolated_pio_core):
|
2017-01-30 22:36:25 +02:00
|
|
|
result = clirunner.invoke(cli_platform.platform_update)
|
|
|
|
validate_cliresult(result)
|
2017-09-21 23:57:55 +03:00
|
|
|
assert "Uninstalling atmelavr @ 1.2.0:" in result.output
|
2017-01-30 22:36:25 +02:00
|
|
|
assert "PlatformManager: Installing atmelavr @" in result.output
|
2020-06-27 12:36:57 +03:00
|
|
|
assert len(isolated_pio_core.join("packages").listdir()) == 1
|
2016-08-01 17:05:48 +03:00
|
|
|
|
2017-01-30 20:21:16 +02:00
|
|
|
|
2020-06-27 12:36:57 +03:00
|
|
|
def test_uninstall(clirunner, validate_cliresult, isolated_pio_core):
|
2019-09-23 23:13:48 +03:00
|
|
|
result = clirunner.invoke(
|
|
|
|
cli_platform.platform_uninstall, ["atmelavr", "espressif8266"]
|
|
|
|
)
|
2017-01-30 20:21:16 +02:00
|
|
|
validate_cliresult(result)
|
2020-06-27 12:36:57 +03:00
|
|
|
assert not isolated_pio_core.join("platforms").listdir()
|