Cleanup tests

This commit is contained in:
Ivan Kravets
2018-01-13 01:19:41 +02:00
parent 712155243c
commit 7cad113f0a
11 changed files with 47 additions and 63 deletions

View File

@ -10,7 +10,7 @@ yapf:
yapf --recursive --in-place platformio/ yapf --recursive --in-place platformio/
test: 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 before-commit: isort yapf lint test

View File

@ -97,10 +97,9 @@ class UndefinedPackageVersion(PlatformioException):
class PackageInstallError(PlatformioException): class PackageInstallError(PlatformioException):
MESSAGE = ( MESSAGE = ("Could not install '{0}' with version requirements '{1}' "
"Could not install '{0}' with version requirements '{1}' " "for your system '{2}'.\n"
"for your system '{2}'.\n" "More details: http://bit.ly/faq-package-manager")
"More details: http://bit.ly/faq-package-manager")
class FDUnrecognizedStatusCode(PlatformioException): class FDUnrecognizedStatusCode(PlatformioException):

View File

@ -45,7 +45,7 @@ def test_ci_lib_and_board(clirunner, validate_cliresult):
example_dir = join("examples", "atmelavr", "arduino-external-libs") example_dir = join("examples", "atmelavr", "arduino-external-libs")
result = clirunner.invoke(cmd_ci, [ result = clirunner.invoke(cmd_ci, [
join(example_dir, "lib", "OneWire", "examples", "DS2408_Switch", join(example_dir, "lib", "OneWire", "examples", "DS2408_Switch",
"DS2408_Switch.pde"), "-l", join(example_dir, "lib", "OneWire"), "DS2408_Switch.pde"), "-l",
"-b", "uno" join(example_dir, "lib", "OneWire"), "-b", "uno"
]) ])
validate_cliresult(result) validate_cliresult(result)

View File

@ -54,7 +54,7 @@ def test_init_duplicated_boards(clirunner, validate_cliresult, tmpdir):
assert set(config.sections()) == set(["env:uno"]) 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(): with tmpdir.as_cwd():
result = clirunner.invoke(cmd_init, ["--ide", "atom"]) result = clirunner.invoke(cmd_init, ["--ide", "atom"])
assert result.exit_code == -1 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"]) cmd_init, ["--ide", "atom", "-b", "uno", "-b", "teensy31"])
validate_cliresult(result) validate_cliresult(result)
validate_pioproject(str(tmpdir)) validate_pioproject(str(tmpdir))
assert all([tmpdir.join(f).check() assert all([
for f in (".clang_complete", ".gcc-flags.json")]) tmpdir.join(f).check()
for f in (".clang_complete", ".gcc-flags.json")
])
assert "arduinoavr" in tmpdir.join(".clang_complete").read() assert "arduinoavr" in tmpdir.join(".clang_complete").read()
# switch to NodeMCU # switch to NodeMCU
result = clirunner.invoke( result = clirunner.invoke(cmd_init,
cmd_init, ["--ide", "atom", "-b", "nodemcuv2"]) ["--ide", "atom", "-b", "nodemcuv2"])
validate_cliresult(result) validate_cliresult(result)
validate_pioproject(str(tmpdir)) validate_pioproject(str(tmpdir))
assert "arduinoespressif" in tmpdir.join(".clang_complete").read() 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) boards = json.loads(result.output)
config = util.load_project_config() config = util.load_project_config()
expected_result = [ expected_result = [("platform", str(boards[0]['platform'])),
("platform", str(boards[0]['platform'])), ("framework",
("framework", str(boards[0]['frameworks'][0])), ("board", "uno") str(boards[0]['frameworks'][0])), ("board", "uno")]
]
assert config.has_section("env:uno") assert config.has_section("env:uno")
assert len( assert not set(expected_result).symmetric_difference(
set(expected_result).symmetric_difference( set(config.items("env:uno")))
set(config.items("env:uno")))) == 0
def test_init_enable_auto_uploading(clirunner, validate_cliresult): 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_cliresult(result)
validate_pioproject(getcwd()) validate_pioproject(getcwd())
config = util.load_project_config() config = util.load_project_config()
expected_result = [ expected_result = [("platform", "atmelavr"), ("framework", "arduino"),
("platform", "atmelavr"), ("framework", "arduino"), ("board", "uno"), ("targets", "upload")]
("board", "uno"), ("targets", "upload")
]
assert config.has_section("env:uno") assert config.has_section("env:uno")
assert len( assert not set(expected_result).symmetric_difference(
set(expected_result).symmetric_difference( set(config.items("env:uno")))
set(config.items("env:uno")))) == 0
def test_init_custom_framework(clirunner, validate_cliresult): def test_init_custom_framework(clirunner, validate_cliresult):
@ -139,14 +136,11 @@ def test_init_custom_framework(clirunner, validate_cliresult):
validate_cliresult(result) validate_cliresult(result)
validate_pioproject(getcwd()) validate_pioproject(getcwd())
config = util.load_project_config() config = util.load_project_config()
expected_result = [ expected_result = [("platform", "teensy"), ("framework", "mbed"),
("platform", "teensy"), ("framework", "mbed"), ("board", "teensy31")]
("board", "teensy31")
]
assert config.has_section("env:teensy31") assert config.has_section("env:teensy31")
assert len( assert not set(expected_result).symmetric_difference(
set(expected_result).symmetric_difference( set(config.items("env:teensy31")))
set(config.items("env:teensy31")))) == 0
def test_init_incorrect_board(clirunner): def test_init_incorrect_board(clirunner):

View File

@ -148,8 +148,8 @@ def test_global_lib_list(clirunner, validate_cliresult):
items2 = [ items2 = [
"OneWire", "DHT22", "PJON", "ESPAsyncTCP", "ArduinoJson", "OneWire", "DHT22", "PJON", "ESPAsyncTCP", "ArduinoJson",
"PubSubClient", "rs485-nodeproto", "Adafruit ST7735 Library", "PubSubClient", "rs485-nodeproto", "Adafruit ST7735 Library",
"RadioHead-1.62", "DallasTemperature", "NeoPixelBus", "RadioHead-1.62", "DallasTemperature", "NeoPixelBus", "RFcontrol",
"RFcontrol", "platformio-libmirror" "platformio-libmirror"
] ]
assert set(items1) == set(items2) assert set(items1) == set(items2)

View File

@ -24,27 +24,25 @@ def test_search_json_output(clirunner, validate_cliresult, isolated_pio_home):
validate_cliresult(result) validate_cliresult(result)
search_result = json.loads(result.output) search_result = json.loads(result.output)
assert isinstance(search_result, list) assert isinstance(search_result, list)
assert len(search_result) assert search_result
platforms = [item['name'] for item in search_result] platforms = [item['name'] for item in search_result]
assert "atmelsam" in platforms 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"]) result = clirunner.invoke(cli_platform.platform_search, ["arduino"])
validate_cliresult(result) validate_cliresult(result)
assert "teensy" in result.output assert "teensy" in result.output
def test_install_unknown_version(clirunner, validate_cliresult, def test_install_unknown_version(clirunner):
isolated_pio_home):
result = clirunner.invoke(cli_platform.platform_install, result = clirunner.invoke(cli_platform.platform_install,
["atmelavr@99.99.99"]) ["atmelavr@99.99.99"])
assert result.exit_code == -1 assert result.exit_code == -1
assert isinstance(result.exception, exception.UndefinedPackageVersion) assert isinstance(result.exception, exception.UndefinedPackageVersion)
def test_install_unknown_from_registry(clirunner, validate_cliresult, def test_install_unknown_from_registry(clirunner):
isolated_pio_home):
result = clirunner.invoke(cli_platform.platform_install, result = clirunner.invoke(cli_platform.platform_install,
["unknown-platform"]) ["unknown-platform"])
assert result.exit_code == -1 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 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, [ result = clirunner.invoke(cli_platform.platform_install, [
"https://github.com/platformio/" "https://github.com/platformio/"
"platform-espressif8266.git#feature/stage", "--skip-default-package" "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 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"]) result = clirunner.invoke(cli_platform.platform_list, ["--json-output"])
validate_cliresult(result) validate_cliresult(result)
list_result = json.loads(result.output) list_result = json.loads(result.output)
assert isinstance(list_result, list) assert isinstance(list_result, list)
assert len(list_result) assert list_result
platforms = [item['name'] for item in list_result] platforms = [item['name'] for item in list_result]
assert set(["atmelavr", "espressif8266"]) == set(platforms) 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) result = clirunner.invoke(cli_platform.platform_list)
validate_cliresult(result) validate_cliresult(result)
assert all( assert all(
@ -111,4 +109,4 @@ def test_uninstall(clirunner, validate_cliresult, isolated_pio_home):
result = clirunner.invoke(cli_platform.platform_uninstall, result = clirunner.invoke(cli_platform.platform_uninstall,
["atmelavr", "espressif8266"]) ["atmelavr", "espressif8266"])
validate_cliresult(result) validate_cliresult(result)
assert len(isolated_pio_home.join("platforms").listdir()) == 0 assert not isolated_pio_home.join("platforms").listdir()

View File

@ -19,6 +19,6 @@ from platformio.commands.settings import cli
def test_settings_check(clirunner, validate_cliresult): def test_settings_check(clirunner, validate_cliresult):
result = clirunner.invoke(cli, ["get"]) result = clirunner.invoke(cli, ["get"])
validate_cliresult(result) validate_cliresult(result)
assert len(result.output) assert result.output
for item in app.DEFAULT_SETTINGS.items(): for item in app.DEFAULT_SETTINGS.items():
assert item[0] in result.output assert item[0] in result.output

View File

@ -16,11 +16,7 @@ from platformio.commands.update import cli as cmd_update
def test_update(clirunner, validate_cliresult): def test_update(clirunner, validate_cliresult):
matches = ( matches = ("Platform Manager", "Up-to-date", "Library Manager")
"Platform Manager",
"Up-to-date",
"Library Manager"
)
result = clirunner.invoke(cmd_update, ["--only-check"]) result = clirunner.invoke(cmd_update, ["--only-check"])
validate_cliresult(result) validate_cliresult(result)
assert all([m in result.output for m in matches]) assert all([m in result.output for m in matches])

View File

@ -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)]) assert board_ids == set([b['id'] for b in json.loads(result.output)])
def test_after_upgrade_silence(clirunner, validate_cliresult, def test_after_upgrade_silence(clirunner, validate_cliresult):
isolated_pio_home):
app.set_state_item("last_version", "2.11.2") app.set_state_item("last_version", "2.11.2")
result = clirunner.invoke(cli_pio, ["boards", "--json-output"]) result = clirunner.invoke(cli_pio, ["boards", "--json-output"])
validate_cliresult(result) validate_cliresult(result)
@ -66,7 +65,7 @@ def test_after_upgrade_silence(clirunner, validate_cliresult,
assert any([b['id'] == "uno" for b in boards]) 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): def _patch_pio_version(version):
maintenance.__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) _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 # install obsolete library
result = clirunner.invoke(cli_pio, result = clirunner.invoke(cli_pio,
["lib", "-g", "install", "ArduinoJson@<5.7"]) ["lib", "-g", "install", "ArduinoJson@<5.7"])
@ -113,8 +112,7 @@ def test_check_lib_updates(clirunner, validate_cliresult, isolated_pio_home):
result.output) result.output)
def test_check_and_update_libraries(clirunner, validate_cliresult, def test_check_and_update_libraries(clirunner, validate_cliresult):
isolated_pio_home):
# enable library auto-updates # enable library auto-updates
result = clirunner.invoke( result = clirunner.invoke(
cli_pio, ["settings", "set", "auto_update_libraries", "Yes"]) 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 assert "There are the new updates for platforms (native)" in result.output
def test_check_and_update_platforms(clirunner, validate_cliresult, def test_check_and_update_platforms(clirunner, validate_cliresult):
isolated_pio_home):
# enable library auto-updates # enable library auto-updates
result = clirunner.invoke( result = clirunner.invoke(
cli_pio, ["settings", "set", "auto_update_platforms", "Yes"]) cli_pio, ["settings", "set", "auto_update_platforms", "Yes"])
@ -190,8 +187,7 @@ def test_check_and_update_platforms(clirunner, validate_cliresult,
validate_cliresult(result) validate_cliresult(result)
assert "There are the new updates for platforms (native)" in result.output assert "There are the new updates for platforms (native)" in result.output
assert "Please wait while updating platforms" in result.output assert "Please wait while updating platforms" in result.output
assert re.search(r"Updating native\s+@ 0.0.0\s+\[[\d\.]+\]", assert re.search(r"Updating native\s+@ 0.0.0\s+\[[\d\.]+\]", result.output)
result.output)
# check updated version # check updated version
result = clirunner.invoke(cli_pio, ["platform", "list", "--json-output"]) result = clirunner.invoke(cli_pio, ["platform", "list", "--json-output"])

View File

@ -186,7 +186,7 @@ def test_install_packages(isolated_pio_home, tmpdir):
"packages").listdir()]) == set(pkg_dirnames) "packages").listdir()]) == set(pkg_dirnames)
def test_get_package(isolated_pio_home): def test_get_package():
tests = [ tests = [
[("unknown", ), None], [("unknown", ), None],
[("1", ), None], [("1", ), None],

View File

@ -23,6 +23,7 @@ deps =
yapf yapf
pylint pylint
pytest pytest
pytest-xdist
commands = python --version commands = python --version
[testenv:docs] [testenv:docs]