From 3146ab5d12274512f7d5bbe9a216dc469271dc6a Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 30 Oct 2019 19:09:32 +0200 Subject: [PATCH] Allow export project config data as Tuple --- platformio/project/config.py | 3 ++ tests/test_projectconf.py | 93 ++++++++++++++++++++++++++++++++++-- 2 files changed, 91 insertions(+), 5 deletions(-) diff --git a/platformio/project/config.py b/platformio/project/config.py index fdc00124..170ec766 100644 --- a/platformio/project/config.py +++ b/platformio/project/config.py @@ -412,6 +412,9 @@ class ProjectConfig(ProjectConfigBase, ProjectConfigDirsMixin): def as_dict(self): return {s: self.items(s, as_dict=True) for s in self.sections()} + def as_tuple(self): + return [(s, self.items(s)) for s in self.sections()] + def to_json(self): return json.dumps(self.as_dict()) diff --git a/tests/test_projectconf.py b/tests/test_projectconf.py index 2ec24521..8b4d3445 100644 --- a/tests/test_projectconf.py +++ b/tests/test_projectconf.py @@ -242,27 +242,27 @@ def test_items(config): ("lib_flags", "-lc -lm"), ("extra_flags", None), ("lib_ignore", "LibIgnoreCustom"), - ] # yapf: disable + ] assert config.items(env="base") == [ ("build_flags", ["-D DEBUG=1"]), ("targets", []), ("monitor_speed", "115200"), ("lib_deps", ["Lib1", "Lib2"]), ("lib_ignore", ["LibIgnoreCustom"]), - ] # yapf: disable + ] assert config.items(env="extra_1") == [ ("build_flags", ["-lc -lm -D DEBUG=1"]), ("lib_deps", ["574"]), ("monitor_speed", "115200"), ("lib_ignore", ["LibIgnoreCustom"]), - ] # yapf: disable + ] assert config.items(env="extra_2") == [ ("build_flags", ["-Og"]), ("lib_ignore", ["LibIgnoreCustom", "Lib3"]), ("upload_port", "/dev/extra_2/port"), ("monitor_speed", "115200"), ("lib_deps", ["Lib1", "Lib2"]), - ] # yapf: disable + ] assert config.items(env="test_extends") == [ ("extends", ["strict_settings"]), ("build_flags", ["-D RELEASE"]), @@ -271,4 +271,87 @@ def test_items(config): ("monitor_speed", "9600"), ("lib_deps", ["Lib1", "Lib2"]), ("lib_ignore", ["LibIgnoreCustom"]), - ] # yapf: disable + ] + + +def test_as_tuple(config): + assert config.as_tuple() == [ + ( + "platformio", + [ + ("extra_configs", ["extra_envs.ini", "extra_debug.ini"]), + ("default_envs", ["base", "extra_2"]), + ("workspace_dir", "/tmp/pio-workspaces/$PROJECT_HASH"), + ], + ), + ( + "env", + [ + ("monitor_speed", "115200"), + ("lib_deps", ["Lib1", "Lib2"]), + ("lib_ignore", ["LibIgnoreCustom"]), + ], + ), + ("strict_ldf", [("lib_ldf_mode", "chain+"), ("lib_compat_mode", "strict")]), + ("monitor_custom", [("monitor_speed", "9600")]), + ( + "strict_settings", + [ + ("extends", "strict_ldf, monitor_custom"), + ("build_flags", "-D RELEASE"), + ("lib_ldf_mode", "chain+"), + ("lib_compat_mode", "strict"), + ("monitor_speed", "9600"), + ], + ), + ( + "custom", + [ + ("debug_flags", "-D DEBUG=1"), + ("lib_flags", "-lc -lm"), + ("extra_flags", None), + ("lib_ignore", "LibIgnoreCustom"), + ], + ), + ( + "env:base", + [ + ("build_flags", ["-D DEBUG=1"]), + ("targets", []), + ("monitor_speed", "115200"), + ("lib_deps", ["Lib1", "Lib2"]), + ("lib_ignore", ["LibIgnoreCustom"]), + ], + ), + ( + "env:test_extends", + [ + ("extends", ["strict_settings"]), + ("build_flags", ["-D RELEASE"]), + ("lib_ldf_mode", "chain+"), + ("lib_compat_mode", "strict"), + ("monitor_speed", "9600"), + ("lib_deps", ["Lib1", "Lib2"]), + ("lib_ignore", ["LibIgnoreCustom"]), + ], + ), + ( + "env:extra_1", + [ + ("build_flags", ["-lc -lm -D DEBUG=1"]), + ("lib_deps", ["574"]), + ("monitor_speed", "115200"), + ("lib_ignore", ["LibIgnoreCustom"]), + ], + ), + ( + "env:extra_2", + [ + ("build_flags", ["-Og"]), + ("lib_ignore", ["LibIgnoreCustom", "Lib3"]), + ("upload_port", "/dev/extra_2/port"), + ("monitor_speed", "115200"), + ("lib_deps", ["Lib1", "Lib2"]), + ], + ), + ]