From 7cad113f0a07875c74fef2ea5fca0057241fc1af Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 13 Jan 2018 01:19:41 +0200 Subject: [PATCH] Cleanup tests --- Makefile | 2 +- platformio/exception.py | 7 +++-- tests/commands/test_ci.py | 4 +-- tests/commands/test_init.py | 46 ++++++++++++++------------------- tests/commands/test_lib.py | 4 +-- tests/commands/test_platform.py | 20 +++++++------- tests/commands/test_settings.py | 2 +- tests/commands/test_update.py | 6 +---- tests/test_maintenance.py | 16 +++++------- tests/test_managers.py | 2 +- tox.ini | 1 + 11 files changed, 47 insertions(+), 63 deletions(-) diff --git a/Makefile b/Makefile index 0031d316..6df42c42 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ yapf: yapf --recursive --in-place platformio/ test: - py.test -v -s tests --ignore tests/test_examples.py --ignore tests/test_pkgmanifest.py + py.test -v -s -n 3 --dist=loadscope tests --ignore tests/test_examples.py --ignore tests/test_pkgmanifest.py before-commit: isort yapf lint test diff --git a/platformio/exception.py b/platformio/exception.py index 891b994e..073ea4f7 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -97,10 +97,9 @@ class UndefinedPackageVersion(PlatformioException): class PackageInstallError(PlatformioException): - MESSAGE = ( - "Could not install '{0}' with version requirements '{1}' " - "for your system '{2}'.\n" - "More details: http://bit.ly/faq-package-manager") + MESSAGE = ("Could not install '{0}' with version requirements '{1}' " + "for your system '{2}'.\n" + "More details: http://bit.ly/faq-package-manager") class FDUnrecognizedStatusCode(PlatformioException): diff --git a/tests/commands/test_ci.py b/tests/commands/test_ci.py index 9c77582b..2ab76544 100644 --- a/tests/commands/test_ci.py +++ b/tests/commands/test_ci.py @@ -45,7 +45,7 @@ def test_ci_lib_and_board(clirunner, validate_cliresult): example_dir = join("examples", "atmelavr", "arduino-external-libs") result = clirunner.invoke(cmd_ci, [ join(example_dir, "lib", "OneWire", "examples", "DS2408_Switch", - "DS2408_Switch.pde"), "-l", join(example_dir, "lib", "OneWire"), - "-b", "uno" + "DS2408_Switch.pde"), "-l", + join(example_dir, "lib", "OneWire"), "-b", "uno" ]) validate_cliresult(result) diff --git a/tests/commands/test_init.py b/tests/commands/test_init.py index 4b7c0a94..eecb25f3 100644 --- a/tests/commands/test_init.py +++ b/tests/commands/test_init.py @@ -54,7 +54,7 @@ def test_init_duplicated_boards(clirunner, validate_cliresult, tmpdir): assert set(config.sections()) == set(["env:uno"]) -def test_init_ide_without_board(clirunner, validate_cliresult, tmpdir): +def test_init_ide_without_board(clirunner, tmpdir): with tmpdir.as_cwd(): result = clirunner.invoke(cmd_init, ["--ide", "atom"]) assert result.exit_code == -1 @@ -67,13 +67,15 @@ def test_init_ide_atom(clirunner, validate_cliresult, tmpdir): cmd_init, ["--ide", "atom", "-b", "uno", "-b", "teensy31"]) validate_cliresult(result) validate_pioproject(str(tmpdir)) - assert all([tmpdir.join(f).check() - for f in (".clang_complete", ".gcc-flags.json")]) + assert all([ + tmpdir.join(f).check() + for f in (".clang_complete", ".gcc-flags.json") + ]) assert "arduinoavr" in tmpdir.join(".clang_complete").read() # switch to NodeMCU - result = clirunner.invoke( - cmd_init, ["--ide", "atom", "-b", "nodemcuv2"]) + result = clirunner.invoke(cmd_init, + ["--ide", "atom", "-b", "nodemcuv2"]) validate_cliresult(result) validate_pioproject(str(tmpdir)) assert "arduinoespressif" in tmpdir.join(".clang_complete").read() @@ -104,15 +106,13 @@ def test_init_special_board(clirunner, validate_cliresult): boards = json.loads(result.output) config = util.load_project_config() - expected_result = [ - ("platform", str(boards[0]['platform'])), - ("framework", str(boards[0]['frameworks'][0])), ("board", "uno") - ] + expected_result = [("platform", str(boards[0]['platform'])), + ("framework", + str(boards[0]['frameworks'][0])), ("board", "uno")] assert config.has_section("env:uno") - assert len( - set(expected_result).symmetric_difference( - set(config.items("env:uno")))) == 0 + assert not set(expected_result).symmetric_difference( + set(config.items("env:uno"))) def test_init_enable_auto_uploading(clirunner, validate_cliresult): @@ -122,14 +122,11 @@ def test_init_enable_auto_uploading(clirunner, validate_cliresult): validate_cliresult(result) validate_pioproject(getcwd()) config = util.load_project_config() - expected_result = [ - ("platform", "atmelavr"), ("framework", "arduino"), - ("board", "uno"), ("targets", "upload") - ] + expected_result = [("platform", "atmelavr"), ("framework", "arduino"), + ("board", "uno"), ("targets", "upload")] assert config.has_section("env:uno") - assert len( - set(expected_result).symmetric_difference( - set(config.items("env:uno")))) == 0 + assert not set(expected_result).symmetric_difference( + set(config.items("env:uno"))) def test_init_custom_framework(clirunner, validate_cliresult): @@ -139,14 +136,11 @@ def test_init_custom_framework(clirunner, validate_cliresult): validate_cliresult(result) validate_pioproject(getcwd()) config = util.load_project_config() - expected_result = [ - ("platform", "teensy"), ("framework", "mbed"), - ("board", "teensy31") - ] + expected_result = [("platform", "teensy"), ("framework", "mbed"), + ("board", "teensy31")] assert config.has_section("env:teensy31") - assert len( - set(expected_result).symmetric_difference( - set(config.items("env:teensy31")))) == 0 + assert not set(expected_result).symmetric_difference( + set(config.items("env:teensy31"))) def test_init_incorrect_board(clirunner): diff --git a/tests/commands/test_lib.py b/tests/commands/test_lib.py index 657297a8..2aa1d0d4 100644 --- a/tests/commands/test_lib.py +++ b/tests/commands/test_lib.py @@ -148,8 +148,8 @@ def test_global_lib_list(clirunner, validate_cliresult): items2 = [ "OneWire", "DHT22", "PJON", "ESPAsyncTCP", "ArduinoJson", "PubSubClient", "rs485-nodeproto", "Adafruit ST7735 Library", - "RadioHead-1.62", "DallasTemperature", "NeoPixelBus", - "RFcontrol", "platformio-libmirror" + "RadioHead-1.62", "DallasTemperature", "NeoPixelBus", "RFcontrol", + "platformio-libmirror" ] assert set(items1) == set(items2) diff --git a/tests/commands/test_platform.py b/tests/commands/test_platform.py index 2bb747fd..5b3053fe 100644 --- a/tests/commands/test_platform.py +++ b/tests/commands/test_platform.py @@ -24,27 +24,25 @@ def test_search_json_output(clirunner, validate_cliresult, isolated_pio_home): validate_cliresult(result) search_result = json.loads(result.output) assert isinstance(search_result, list) - assert len(search_result) + assert search_result platforms = [item['name'] for item in search_result] assert "atmelsam" in platforms -def test_search_raw_output(clirunner, validate_cliresult, isolated_pio_home): +def test_search_raw_output(clirunner, validate_cliresult): result = clirunner.invoke(cli_platform.platform_search, ["arduino"]) validate_cliresult(result) assert "teensy" in result.output -def test_install_unknown_version(clirunner, validate_cliresult, - isolated_pio_home): +def test_install_unknown_version(clirunner): result = clirunner.invoke(cli_platform.platform_install, ["atmelavr@99.99.99"]) assert result.exit_code == -1 assert isinstance(result.exception, exception.UndefinedPackageVersion) -def test_install_unknown_from_registry(clirunner, validate_cliresult, - isolated_pio_home): +def test_install_unknown_from_registry(clirunner): result = clirunner.invoke(cli_platform.platform_install, ["unknown-platform"]) assert result.exit_code == -1 @@ -63,7 +61,7 @@ def test_install_known_version(clirunner, validate_cliresult, assert len(isolated_pio_home.join("packages").listdir()) == 1 -def test_install_from_vcs(clirunner, validate_cliresult, isolated_pio_home): +def test_install_from_vcs(clirunner, validate_cliresult): result = clirunner.invoke(cli_platform.platform_install, [ "https://github.com/platformio/" "platform-espressif8266.git#feature/stage", "--skip-default-package" @@ -72,17 +70,17 @@ def test_install_from_vcs(clirunner, validate_cliresult, isolated_pio_home): assert "espressif8266" in result.output -def test_list_json_output(clirunner, validate_cliresult, isolated_pio_home): +def test_list_json_output(clirunner, validate_cliresult): 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) + assert list_result platforms = [item['name'] for item in list_result] assert set(["atmelavr", "espressif8266"]) == set(platforms) -def test_list_raw_output(clirunner, validate_cliresult, isolated_pio_home): +def test_list_raw_output(clirunner, validate_cliresult): result = clirunner.invoke(cli_platform.platform_list) validate_cliresult(result) assert all( @@ -111,4 +109,4 @@ def test_uninstall(clirunner, validate_cliresult, isolated_pio_home): result = clirunner.invoke(cli_platform.platform_uninstall, ["atmelavr", "espressif8266"]) validate_cliresult(result) - assert len(isolated_pio_home.join("platforms").listdir()) == 0 + assert not isolated_pio_home.join("platforms").listdir() diff --git a/tests/commands/test_settings.py b/tests/commands/test_settings.py index c6cd33da..e846ecc6 100644 --- a/tests/commands/test_settings.py +++ b/tests/commands/test_settings.py @@ -19,6 +19,6 @@ from platformio.commands.settings import cli def test_settings_check(clirunner, validate_cliresult): result = clirunner.invoke(cli, ["get"]) validate_cliresult(result) - assert len(result.output) + assert result.output for item in app.DEFAULT_SETTINGS.items(): assert item[0] in result.output diff --git a/tests/commands/test_update.py b/tests/commands/test_update.py index b8309fb8..9325e501 100644 --- a/tests/commands/test_update.py +++ b/tests/commands/test_update.py @@ -16,11 +16,7 @@ from platformio.commands.update import cli as cmd_update def test_update(clirunner, validate_cliresult): - matches = ( - "Platform Manager", - "Up-to-date", - "Library Manager" - ) + matches = ("Platform Manager", "Up-to-date", "Library Manager") result = clirunner.invoke(cmd_update, ["--only-check"]) validate_cliresult(result) assert all([m in result.output for m in matches]) diff --git a/tests/test_maintenance.py b/tests/test_maintenance.py index 9fd7fd6b..667c1563 100644 --- a/tests/test_maintenance.py +++ b/tests/test_maintenance.py @@ -57,8 +57,7 @@ def test_after_upgrade_2_to_3(clirunner, validate_cliresult, assert board_ids == set([b['id'] for b in json.loads(result.output)]) -def test_after_upgrade_silence(clirunner, validate_cliresult, - isolated_pio_home): +def test_after_upgrade_silence(clirunner, validate_cliresult): app.set_state_item("last_version", "2.11.2") result = clirunner.invoke(cli_pio, ["boards", "--json-output"]) validate_cliresult(result) @@ -66,7 +65,7 @@ def test_after_upgrade_silence(clirunner, validate_cliresult, assert any([b['id'] == "uno" for b in boards]) -def test_check_pio_upgrade(clirunner, validate_cliresult, isolated_pio_home): +def test_check_pio_upgrade(clirunner, validate_cliresult): def _patch_pio_version(version): maintenance.__version__ = version @@ -96,7 +95,7 @@ def test_check_pio_upgrade(clirunner, validate_cliresult, isolated_pio_home): _patch_pio_version(origin_version) -def test_check_lib_updates(clirunner, validate_cliresult, isolated_pio_home): +def test_check_lib_updates(clirunner, validate_cliresult): # install obsolete library result = clirunner.invoke(cli_pio, ["lib", "-g", "install", "ArduinoJson@<5.7"]) @@ -113,8 +112,7 @@ def test_check_lib_updates(clirunner, validate_cliresult, isolated_pio_home): result.output) -def test_check_and_update_libraries(clirunner, validate_cliresult, - isolated_pio_home): +def test_check_and_update_libraries(clirunner, validate_cliresult): # enable library auto-updates result = clirunner.invoke( cli_pio, ["settings", "set", "auto_update_libraries", "Yes"]) @@ -168,8 +166,7 @@ def test_check_platform_updates(clirunner, validate_cliresult, assert "There are the new updates for platforms (native)" in result.output -def test_check_and_update_platforms(clirunner, validate_cliresult, - isolated_pio_home): +def test_check_and_update_platforms(clirunner, validate_cliresult): # enable library auto-updates result = clirunner.invoke( cli_pio, ["settings", "set", "auto_update_platforms", "Yes"]) @@ -190,8 +187,7 @@ def test_check_and_update_platforms(clirunner, validate_cliresult, validate_cliresult(result) assert "There are the new updates for platforms (native)" in result.output assert "Please wait while updating platforms" in result.output - assert re.search(r"Updating native\s+@ 0.0.0\s+\[[\d\.]+\]", - result.output) + assert re.search(r"Updating native\s+@ 0.0.0\s+\[[\d\.]+\]", result.output) # check updated version result = clirunner.invoke(cli_pio, ["platform", "list", "--json-output"]) diff --git a/tests/test_managers.py b/tests/test_managers.py index 559c9d29..6fe2f273 100644 --- a/tests/test_managers.py +++ b/tests/test_managers.py @@ -186,7 +186,7 @@ def test_install_packages(isolated_pio_home, tmpdir): "packages").listdir()]) == set(pkg_dirnames) -def test_get_package(isolated_pio_home): +def test_get_package(): tests = [ [("unknown", ), None], [("1", ), None], diff --git a/tox.ini b/tox.ini index ad3288c7..f1196266 100644 --- a/tox.ini +++ b/tox.ini @@ -23,6 +23,7 @@ deps = yapf pylint pytest + pytest-xdist commands = python --version [testenv:docs]