def test_init_custom_framework(clirunner, validate_cliresult): with clirunner.isolated_filesystem(): result = clirunner.invoke( cmd_init, ["-b", "teensy31", "--project-option", "framework=mbed"]) validate_cliresult(result) validate_pioproject(getcwd()) config = ProjectConfig(join(getcwd(), "platformio.ini")) config.validate() expected_result = dict(platform="teensy", board="teensy31", framework=["mbed"]) assert config.has_section("env:teensy31") assert sorted(config.items(env="teensy31", as_dict=True).items()) == sorted( expected_result.items())
def test_init_enable_auto_uploading(clirunner, validate_cliresult): with clirunner.isolated_filesystem(): result = clirunner.invoke( cmd_init, ["-b", "uno", "--project-option", "targets=upload"]) validate_cliresult(result) validate_pioproject(getcwd()) config = ProjectConfig(join(getcwd(), "platformio.ini")) config.validate() expected_result = dict(targets=["upload"], platform="atmelavr", board="uno", framework=["arduino"]) assert config.has_section("env:uno") assert sorted(config.items(env="uno", as_dict=True).items()) == sorted( expected_result.items())
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())
def test_real_config(tmpdir): tmpdir.join("platformio.ini").write(BASE_CONFIG) tmpdir.join("extra_envs.ini").write(EXTRA_ENVS_CONFIG) tmpdir.join("extra_debug.ini").write(EXTRA_DEBUG_CONFIG) config = None with tmpdir.as_cwd(): config = ProjectConfig(tmpdir.join("platformio.ini").strpath) assert config assert len(config.warnings) == 2 assert "lib_install" in config.warnings[1] config.validate(["extra_2", "base"], silent=True) with pytest.raises(UnknownEnvNames): config.validate(["non-existing-env"]) # unknown section with pytest.raises(ConfigParser.NoSectionError): config.getraw("unknown_section", "unknown_option") # unknown option with pytest.raises(ConfigParser.NoOptionError): config.getraw("custom", "unknown_option") # unknown option even if exists in [env] with pytest.raises(ConfigParser.NoOptionError): config.getraw("platformio", "monitor_speed") # sections assert config.sections() == [ "platformio", "env", "custom", "env:base", "env:extra_1", "env:extra_2" ] # envs assert config.envs() == ["base", "extra_1", "extra_2"] assert config.default_envs() == ["base", "extra_2"] # options assert config.options(env="base") == [ "build_flags", "targets", "monitor_speed", "lib_deps", "lib_ignore" ] # has_option assert config.has_option("env:base", "monitor_speed") assert not config.has_option("custom", "monitor_speed") assert not config.has_option("env:extra_1", "lib_install") # sysenv assert config.get("custom", "extra_flags") is None assert config.get("env:base", "build_flags") == ["-D DEBUG=1"] assert config.get("env:base", "upload_port") is None assert config.get("env:extra_2", "upload_port") == "/dev/extra_2/port" os.environ["PLATFORMIO_BUILD_FLAGS"] = "-DSYSENVDEPS1 -DSYSENVDEPS2" os.environ["PLATFORMIO_UPLOAD_PORT"] = "/dev/sysenv/port" os.environ["__PIO_TEST_CNF_EXTRA_FLAGS"] = "-L /usr/local/lib" assert config.get("custom", "extra_flags") == "-L /usr/local/lib" assert config.get("env:base", "build_flags") == [ "-D DEBUG=1 -L /usr/local/lib", "-DSYSENVDEPS1 -DSYSENVDEPS2" ] assert config.get("env:base", "upload_port") == "/dev/sysenv/port" assert config.get("env:extra_2", "upload_port") == "/dev/extra_2/port" # getraw assert config.getraw("env:base", "targets") == "" assert config.getraw("env:extra_1", "lib_deps") == "574" assert config.getraw("env:extra_1", "build_flags") == "-lc -lm -D DEBUG=1" # get assert config.get("custom", "debug_flags") == "-D DEBUG=1" assert config.get("env:extra_1", "build_flags") == [ "-lc -lm -D DEBUG=1", "-DSYSENVDEPS1 -DSYSENVDEPS2" ] assert config.get("env:extra_2", "build_flags") == ["-Og", "-DSYSENVDEPS1 -DSYSENVDEPS2"] assert config.get("env:extra_2", "monitor_speed") == "115200" assert config.get("env:base", "build_flags") == ([ "-D DEBUG=1 -L /usr/local/lib", "-DSYSENVDEPS1 -DSYSENVDEPS2" ]) # items assert config.items("custom") == [ ("debug_flags", "-D DEBUG=1"), ("lib_flags", "-lc -lm"), ("extra_flags", "-L /usr/local/lib"), ("lib_ignore", "LibIgnoreCustom") ] # yapf: disable assert config.items(env="base") == [ ("build_flags", [ "-D DEBUG=1 -L /usr/local/lib", "-DSYSENVDEPS1 -DSYSENVDEPS2"]), ("targets", []), ("monitor_speed", "115200"), ("lib_deps", ["Lib1", "Lib2"]), ("lib_ignore", ["LibIgnoreCustom"]), ("upload_port", "/dev/sysenv/port") ] # yapf: disable assert config.items(env="extra_1") == [ ("build_flags", ["-lc -lm -D DEBUG=1", "-DSYSENVDEPS1 -DSYSENVDEPS2"]), ("lib_deps", ["574"]), ("monitor_speed", "115200"), ("lib_ignore", ["LibIgnoreCustom"]), ("upload_port", "/dev/sysenv/port") ] # yapf: disable assert config.items(env="extra_2") == [ ("build_flags", ["-Og", "-DSYSENVDEPS1 -DSYSENVDEPS2"]), ("lib_ignore", ["LibIgnoreCustom", "Lib3"]), ("upload_port", "/dev/extra_2/port"), ("monitor_speed", "115200"), ("lib_deps", ["Lib1", "Lib2"]) ] # yapf: disable # cleanup system environment variables del os.environ["PLATFORMIO_BUILD_FLAGS"] del os.environ["PLATFORMIO_UPLOAD_PORT"] del os.environ["__PIO_TEST_CNF_EXTRA_FLAGS"]