Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_check_pio_upgrade(clirunner, isolated_pio_home, validate_cliresult):
def _patch_pio_version(version):
maintenance.__version__ = version
cmd_upgrade.VERSION = version.split(".", 3)
interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24
last_check = {"platformio_upgrade": time() - interval - 1}
origin_version = maintenance.__version__
# check development version
_patch_pio_version("3.0.0-a1")
app.set_state_item("last_check", last_check)
result = clirunner.invoke(cli_pio, ["platform", "list"])
validate_cliresult(result)
assert "There is a new version" in result.output
assert "Please upgrade" in result.output
# check stable version
_patch_pio_version("2.11.0")
app.set_state_item("last_check", last_check)
result = clirunner.invoke(cli_pio, ["platform", "list"])
validate_cliresult(result)
assert "__pkg_dir" in oudated[0]
result = clirunner.invoke(cmd_lib, ["-g", "update", oudated[0]["__pkg_dir"]])
validate_cliresult(result)
assert "Uninstalling NeoPixelBus @ 2.2.4" in result.output
# update rest libraries
result = clirunner.invoke(cmd_lib, ["-g", "update"])
validate_cliresult(result)
assert result.output.count("[Detached]") == 5
assert result.output.count("[Up-to-date]") == 10
assert "Uninstalling RFcontrol @ 77d4eb3f8a" in result.output
# update unknown library
result = clirunner.invoke(cmd_lib, ["-g", "update", "Unknown"])
assert result.exit_code != 0
assert isinstance(result.exception, exception.UnknownPackage)
def test_check_platform_updates(clirunner, isolated_pio_home,
validate_cliresult):
# install obsolete platform
result = clirunner.invoke(cli_pio, ["platform", "install", "native"])
validate_cliresult(result)
manifest_path = isolated_pio_home.join("platforms", "native",
"platform.json")
manifest = json.loads(manifest_path.read())
manifest['version'] = "0.0.0"
manifest_path.write(json.dumps(manifest))
# reset cached manifests
PlatformManager().cache_reset()
# reset check time
interval = int(app.get_setting("check_platforms_interval")) * 3600 * 24
last_check = {"platforms_update": time() - interval - 1}
app.set_state_item("last_check", last_check)
result = clirunner.invoke(cli_pio, ["platform", "list"])
validate_cliresult(result)
assert "There are the new updates for platforms (native)" in result.output
def test_settings_check(clirunner, validate_cliresult):
result = clirunner.invoke(cli, ["get"])
validate_cliresult(result)
assert result.output
for item in app.DEFAULT_SETTINGS.items():
assert item[0] in result.output
def test_check_and_update_libraries(clirunner, isolated_pio_home,
validate_cliresult):
# enable library auto-updates
result = clirunner.invoke(
cli_pio, ["settings", "set", "auto_update_libraries", "Yes"])
# reset check time
interval = int(app.get_setting("check_libraries_interval")) * 3600 * 24
last_check = {"libraries_update": time() - interval - 1}
app.set_state_item("last_check", last_check)
# fetch installed version
result = clirunner.invoke(cli_pio, ["lib", "-g", "list", "--json-output"])
validate_cliresult(result)
prev_data = json.loads(result.output)
assert len(prev_data) == 1
# initiate auto-updating
result = clirunner.invoke(cli_pio, ["lib", "-g", "show", "ArduinoJson"])
validate_cliresult(result)
assert ("There are the new updates for libraries (ArduinoJson)" in
result.output)
assert "Please wait while updating libraries" in result.output
assert re.search(r"Updating ArduinoJson\s+@ 5.6.7\s+\[[\d\.]+\]",
result.output)
def test_init_special_board(clirunner, validate_cliresult):
with clirunner.isolated_filesystem():
result = clirunner.invoke(cmd_init, ["-b", "uno"])
validate_cliresult(result)
validate_pioproject(getcwd())
result = clirunner.invoke(cmd_boards, ["Arduino Uno", "--json-output"])
validate_cliresult(result)
boards = json.loads(result.output)
config = ProjectConfig(join(getcwd(), "platformio.ini"))
config.validate()
expected_result = dict(
platform=str(boards[0]["platform"]),
board="uno",
framework=[str(boards[0]["frameworks"][0])],
)
assert config.has_section("env:uno")
assert sorted(config.items(env="uno", as_dict=True).items()) == sorted(
expected_result.items()
)
self._verbose_level = int(verbose)
if "clean" in targets:
targets.remove("clean")
targets.append("-c")
if "build_script" not in envoptions:
variables.append("BUILD_SCRIPT=%s" % self.get_build_script())
for v in variables:
if not v.startswith("BUILD_SCRIPT="):
continue
_, path = v.split("=", 1)
if not isfile(path):
raise exception.BuildScriptNotFound(path)
# append aliases of the installed packages
installed_packages = PackageManager.get_installed()
for name, options in self.get_packages().items():
if "alias" not in options or name not in installed_packages:
continue
variables.append(
"PIOPACKAGE_%s=%s" % (options['alias'].upper(), name))
self._found_error = False
args = []
try:
args = [os.path.relpath(PathsManager.EXECUTABLE_FILE), # [JORGE_GARCIA] modified for scons compatibility
"-Q",
"-j %d" % self.get_job_nums(),
"--warn=no-no-parallel-support",
def _rules_to_set(rules_path):
return set(
l.strip()
for l in get_file_contents(rules_path).split("\n")
if l.strip() and not l.startswith("#")
)
if "linux" not in get_systype():
return None
installed_rules = [
"/etc/udev/rules.d/99-platformio-udev.rules",
"/lib/udev/rules.d/99-platformio-udev.rules",
]
if not any(os.path.isfile(p) for p in installed_rules):
raise exception.MissedUdevRules
origin_path = os.path.realpath(
os.path.join(get_source_dir(), "..", "scripts", "99-platformio-udev.rules")
)
if not os.path.isfile(origin_path):
return None
origin_rules = _rules_to_set(origin_path)
for rules_path in installed_rules:
if not os.path.isfile(rules_path):
continue
current_rules = _rules_to_set(rules_path)
if not origin_rules <= current_rules:
raise exception.OutdatedUdevRules(rules_path)
return True
if s.name.startswith("_Z"):
mangled_names.append(s.name)
symbol_addrs.append(hex(symbol_addr))
symbols.append(symbol)
symbol_locations = _get_symbol_locations(env, elf_path, symbol_addrs)
demangled_names = _get_demangled_names(env, mangled_names)
for symbol in symbols:
if symbol["name"].startswith("_Z"):
symbol["demangled_name"] = demangled_names.get(symbol["name"])
location = symbol_locations.get(hex(symbol["addr"]))
if not location or "?" in location:
continue
if "windows" in get_systype():
drive, tail = splitdrive(location)
location = join(drive.upper(), tail)
symbol["file"] = location
symbol["line"] = 0
if ":" in location:
file_, line = location.rsplit(":", 1)
if line.isdigit():
symbol["file"] = file_
symbol["line"] = int(line)
return symbols
def pioplus_call(args, **kwargs):
if WINDOWS and sys.version_info < (2, 7, 6):
raise exception.PlatformioException(
"PlatformIO Core Plus v%s does not run under Python version %s.\n"
"Minimum supported version is 2.7.6, please upgrade Python.\n"
"Python 3 is not yet supported.\n" % (__version__, sys.version)
)
pioplus_path = join(get_core_package_dir("tool-pioplus"), "pioplus")
pythonexe_path = get_pythonexe_path()
os.environ["PYTHONEXEPATH"] = pythonexe_path
os.environ["PYTHONPYSITEDIR"] = get_core_package_dir("contrib-pysite")
os.environ["PIOCOREPYSITEDIR"] = dirname(fs.get_source_dir() or "")
if dirname(pythonexe_path) not in os.environ["PATH"].split(os.pathsep):
os.environ["PATH"] = (os.pathsep).join(
[dirname(pythonexe_path), os.environ["PATH"]]
)
copy_pythonpath_to_osenv()
code = subprocess.call([pioplus_path] + args, **kwargs)