From bf059b8b781c786edb4b3ca7ef838e9b4d16d3a0 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Fri, 20 Feb 2015 20:31:59 +0200 Subject: [PATCH 1/2] Cover "lib" commands with tests --- tests/commands/test_lib.py | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/commands/test_lib.py diff --git a/tests/commands/test_lib.py b/tests/commands/test_lib.py new file mode 100644 index 00000000..b6a07618 --- /dev/null +++ b/tests/commands/test_lib.py @@ -0,0 +1,74 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +from os import listdir +from os.path import isdir, isfile, join + +import re + +from click.testing import CliRunner + +from platformio.commands.lib import cli +from platformio import util + +runner = CliRunner() + + +def validate_output(result): + assert result.exit_code == 0 + assert not result.exception + assert "error" not in result.output.lower() + + +def validate_libfolder(): + libs_path = util.get_lib_dir() + installed_libs = listdir(libs_path) + for lib in installed_libs: + assert isdir(join(libs_path, lib)) + assert isfile(join(libs_path, lib, ".library.json")) and isfile( + join(libs_path, lib, "library.json")) + + +def test_lib_search(): + result = runner.invoke(cli, ["search", "DHT22"]) + validate_output(result) + match = re.search(r"Found\s+(\d+)\slibraries:", result.output) + assert int(match.group(1)) > 2 + + result = runner.invoke(cli, ["search", "DHT22", "--platform=timsp430"]) + validate_output(result) + match = re.search(r"Found\s+(\d+)\slibraries:", result.output) + assert int(match.group(1)) == 1 + + +def test_lib_install(): + result = runner.invoke(cli, ["install", "58", "115"]) + validate_output(result) + validate_libfolder() + + +def test_lib_list(): + result = runner.invoke(cli, ["list"]) + validate_output(result) + assert "58" in result.output and "115" in result.output + + +def test_lib_show(): + result = runner.invoke(cli, ["show", "115"]) + validate_output(result) + assert "arduino" in result.output and "atmelavr" in result.output + + result = runner.invoke(cli, ["show", "58"]) + validate_output(result) + assert "energia" in result.output and "timsp430" in result.output + + +def test_lib_update(): + result = runner.invoke(cli, ["update"]) + validate_output(result) + assert "58" in result.output and "115" in result.output + + +def test_lib_uninstall(): + result = runner.invoke(cli, ["uninstall", "58", "115"]) + validate_output(result) From 05376f873d2b00c4e48dcabc393825d3d8098b01 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Fri, 20 Feb 2015 21:02:10 +0200 Subject: [PATCH 2/2] Cover package manifest with tests // Issue #69 --- tests/test_pkgmanifest.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/test_pkgmanifest.py diff --git a/tests/test_pkgmanifest.py b/tests/test_pkgmanifest.py new file mode 100644 index 00000000..aa95df8a --- /dev/null +++ b/tests/test_pkgmanifest.py @@ -0,0 +1,34 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +import requests +from platformio.util import get_api_result + + +def pytest_generate_tests(metafunc): + if "package_data" not in metafunc.fixturenames: + return + pkgs_manifest = get_api_result("/packages") + assert isinstance(pkgs_manifest, dict) + packages = [] + for _, variants in pkgs_manifest.iteritems(): + for item in variants: + packages.append(item) + metafunc.parametrize("package_data", packages) + + +def validate_response(req): + assert req.status_code == 200 + assert int(req.headers['Content-Length']) > 0 + + +def validate_package(url): + r = requests.head(url, allow_redirects=True) + validate_response(r) + assert r.headers['Content-Type'] == "application/x-gzip" + + +def test_package(package_data): + assert str( + package_data['version']) + ".tar.gz" in package_data['url'] + validate_package(package_data['url'])