Skip to content

Commit

Permalink
feat(config): implement 'get()' for GraphConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
ahal committed Sep 24, 2024
1 parent 2c50d44 commit 2bcd574
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/taskgraph/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def __getitem__(self, name):
def __contains__(self, name):
return name in self._config

def get(self, name):
return self._config.get(name)

def register(self):
"""
Add the project's taskgraph directory to the python path, and register
Expand Down
28 changes: 28 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import pytest

from taskgraph.config import GraphConfig


def test_graph_config_basic():
graph_config = GraphConfig({"foo": "bar"}, "root")

assert "foo" in graph_config
assert graph_config["foo"] == "bar"
assert graph_config.get("foo") == "bar"

assert "missing" not in graph_config
assert graph_config.get("missing") is None

with pytest.raises(KeyError):
graph_config["missing"]

# does not support assignment
with pytest.raises(TypeError):
graph_config["foo"] = "different"

with pytest.raises(TypeError):
graph_config["baz"] = 2

0 comments on commit 2bcd574

Please sign in to comment.