mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Move "strip_ansi_codes" to the util
This commit is contained in:
@ -287,3 +287,7 @@ def humanize_duration_time(duration):
|
|||||||
tokens.append(int(round(duration) if multiplier == 1 else fraction))
|
tokens.append(int(round(duration) if multiplier == 1 else fraction))
|
||||||
duration -= fraction * multiplier
|
duration -= fraction * multiplier
|
||||||
return "{:02d}:{:02d}:{:02d}.{:03d}".format(*tokens)
|
return "{:02d}:{:02d}:{:02d}.{:03d}".format(*tokens)
|
||||||
|
|
||||||
|
|
||||||
|
def strip_ansi_codes(text):
|
||||||
|
return re.sub(r"\x1B\[\d+(;\d+){0,2}m", "", text)
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from platformio.package.commands.exec import package_exec_cmd
|
from platformio.package.commands.exec import package_exec_cmd
|
||||||
|
from platformio.util import strip_ansi_codes
|
||||||
|
|
||||||
|
|
||||||
def test_pkg_not_installed(clirunner, validate_cliresult, isolated_pio_core):
|
def test_pkg_not_installed(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
@ -31,7 +32,7 @@ def test_pkg_not_installed(clirunner, validate_cliresult, isolated_pio_core):
|
|||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
|
|
||||||
def test_pkg_specified(clirunner, validate_cliresult, isolated_pio_core, strip_ansi):
|
def test_pkg_specified(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
# with install
|
# with install
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
package_exec_cmd,
|
package_exec_cmd,
|
||||||
@ -39,14 +40,12 @@ def test_pkg_specified(clirunner, validate_cliresult, isolated_pio_core, strip_a
|
|||||||
obj=dict(force_click_stream=True),
|
obj=dict(force_click_stream=True),
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
output = strip_ansi(result.output)
|
output = strip_ansi_codes(result.output)
|
||||||
assert "Tool Manager: Installing platformio/tool-openocd" in output
|
assert "Tool Manager: Installing platformio/tool-openocd" in output
|
||||||
assert "Open On-Chip Debugger" in output
|
assert "Open On-Chip Debugger" in output
|
||||||
|
|
||||||
|
|
||||||
def test_unrecognized_options(
|
def test_unrecognized_options(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
clirunner, validate_cliresult, isolated_pio_core, strip_ansi
|
|
||||||
):
|
|
||||||
# unrecognized option
|
# unrecognized option
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
package_exec_cmd,
|
package_exec_cmd,
|
||||||
|
@ -20,6 +20,7 @@ import re
|
|||||||
from platformio.commands import PlatformioCLI
|
from platformio.commands import PlatformioCLI
|
||||||
from platformio.commands.lib.command import cli as cmd_lib
|
from platformio.commands.lib.command import cli as cmd_lib
|
||||||
from platformio.package.exception import UnknownPackageError
|
from platformio.package.exception import UnknownPackageError
|
||||||
|
from platformio.util import strip_ansi_codes
|
||||||
|
|
||||||
PlatformioCLI.leftover_args = ["--json-output"] # hook for click
|
PlatformioCLI.leftover_args = ["--json-output"] # hook for click
|
||||||
|
|
||||||
@ -237,7 +238,7 @@ def test_global_lib_update_check(clirunner, validate_cliresult):
|
|||||||
) == set(lib["name"] for lib in output)
|
) == set(lib["name"] for lib in output)
|
||||||
|
|
||||||
|
|
||||||
def test_global_lib_update(clirunner, validate_cliresult, strip_ansi):
|
def test_global_lib_update(clirunner, validate_cliresult):
|
||||||
# update library using package directory
|
# update library using package directory
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_lib, ["-g", "update", "NeoPixelBus", "--dry-run", "--json-output"]
|
cmd_lib, ["-g", "update", "NeoPixelBus", "--dry-run", "--json-output"]
|
||||||
@ -248,7 +249,7 @@ def test_global_lib_update(clirunner, validate_cliresult, strip_ansi):
|
|||||||
assert "__pkg_dir" in oudated[0]
|
assert "__pkg_dir" in oudated[0]
|
||||||
result = clirunner.invoke(cmd_lib, ["-g", "update", oudated[0]["__pkg_dir"]])
|
result = clirunner.invoke(cmd_lib, ["-g", "update", oudated[0]["__pkg_dir"]])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert "Removing NeoPixelBus @ 2.2.4" in strip_ansi(result.output)
|
assert "Removing NeoPixelBus @ 2.2.4" in strip_ansi_codes(result.output)
|
||||||
|
|
||||||
# update rest libraries
|
# update rest libraries
|
||||||
result = clirunner.invoke(cmd_lib, ["-g", "update"])
|
result = clirunner.invoke(cmd_lib, ["-g", "update"])
|
||||||
@ -262,9 +263,7 @@ def test_global_lib_update(clirunner, validate_cliresult, strip_ansi):
|
|||||||
assert isinstance(result.exception, UnknownPackageError)
|
assert isinstance(result.exception, UnknownPackageError)
|
||||||
|
|
||||||
|
|
||||||
def test_global_lib_uninstall(
|
def test_global_lib_uninstall(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
clirunner, validate_cliresult, isolated_pio_core, strip_ansi
|
|
||||||
):
|
|
||||||
# uninstall using package directory
|
# uninstall using package directory
|
||||||
result = clirunner.invoke(cmd_lib, ["-g", "list", "--json-output"])
|
result = clirunner.invoke(cmd_lib, ["-g", "list", "--json-output"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
@ -272,7 +271,7 @@ def test_global_lib_uninstall(
|
|||||||
items = sorted(items, key=lambda item: item["__pkg_dir"])
|
items = sorted(items, key=lambda item: item["__pkg_dir"])
|
||||||
result = clirunner.invoke(cmd_lib, ["-g", "uninstall", items[0]["__pkg_dir"]])
|
result = clirunner.invoke(cmd_lib, ["-g", "uninstall", items[0]["__pkg_dir"]])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert ("Removing %s" % items[0]["name"]) in strip_ansi(result.output)
|
assert ("Removing %s" % items[0]["name"]) in strip_ansi_codes(result.output)
|
||||||
|
|
||||||
# uninstall the rest libraries
|
# uninstall the rest libraries
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
|
@ -18,6 +18,7 @@ import json
|
|||||||
|
|
||||||
from platformio.commands import platform as cli_platform
|
from platformio.commands import platform as cli_platform
|
||||||
from platformio.package.exception import UnknownPackageError
|
from platformio.package.exception import UnknownPackageError
|
||||||
|
from platformio.util import strip_ansi_codes
|
||||||
|
|
||||||
|
|
||||||
def test_search_json_output(clirunner, validate_cliresult, isolated_pio_core):
|
def test_search_json_output(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
@ -66,15 +67,13 @@ def test_install_core_3_dev_platform(clirunner, validate_cliresult, isolated_pio
|
|||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
|
||||||
def test_install_known_version(
|
def test_install_known_version(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
clirunner, validate_cliresult, isolated_pio_core, strip_ansi
|
|
||||||
):
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cli_platform.platform_install,
|
cli_platform.platform_install,
|
||||||
["atmelavr@2.0.0", "--skip-default-package", "--with-package", "tool-avrdude"],
|
["atmelavr@2.0.0", "--skip-default-package", "--with-package", "tool-avrdude"],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
output = strip_ansi(result.output)
|
output = strip_ansi_codes(result.output)
|
||||||
assert "atmelavr @ 2.0.0" in output
|
assert "atmelavr @ 2.0.0" in output
|
||||||
assert "Installing tool-avrdude @" in output
|
assert "Installing tool-avrdude @" in output
|
||||||
assert len(isolated_pio_core.join("packages").listdir()) == 1
|
assert len(isolated_pio_core.join("packages").listdir()) == 1
|
||||||
@ -120,10 +119,10 @@ def test_update_check(clirunner, validate_cliresult, isolated_pio_core):
|
|||||||
assert len(isolated_pio_core.join("packages").listdir()) == 1
|
assert len(isolated_pio_core.join("packages").listdir()) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_update_raw(clirunner, validate_cliresult, isolated_pio_core, strip_ansi):
|
def test_update_raw(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
result = clirunner.invoke(cli_platform.platform_update)
|
result = clirunner.invoke(cli_platform.platform_update)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
output = strip_ansi(result.output)
|
output = strip_ansi_codes(result.output)
|
||||||
assert "Removing atmelavr @ 2.0.0" in output
|
assert "Removing atmelavr @ 2.0.0" in output
|
||||||
assert "Platform Manager: Installing platformio/atmelavr @" in output
|
assert "Platform Manager: Installing platformio/atmelavr @" in output
|
||||||
assert len(isolated_pio_core.join("packages").listdir()) == 2
|
assert len(isolated_pio_core.join("packages").listdir()) == 2
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
import email
|
import email
|
||||||
import imaplib
|
import imaplib
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -64,14 +63,6 @@ def clirunner(request, tmpdir_factory):
|
|||||||
return CliRunner()
|
return CliRunner()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
|
||||||
def strip_ansi():
|
|
||||||
def decorator(text):
|
|
||||||
return re.sub(r"\x1B\[\d+(;\d+){0,2}m", "", text)
|
|
||||||
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
|
|
||||||
def _isolated_pio_core(request, tmpdir_factory):
|
def _isolated_pio_core(request, tmpdir_factory):
|
||||||
core_dir = tmpdir_factory.mktemp(".platformio")
|
core_dir = tmpdir_factory.mktemp(".platformio")
|
||||||
os.environ["PLATFORMIO_CORE_DIR"] = str(core_dir)
|
os.environ["PLATFORMIO_CORE_DIR"] = str(core_dir)
|
||||||
|
Reference in New Issue
Block a user