Beispiel #1
0
 def test_value(self, mocker: MockerFixture) -> None:
     """Test value."""
     mock_literal = MagicMock(value="value")
     mocker.patch.object(VariableValueList,
                         "parse_obj",
                         return_value=mock_literal)
     obj = VariableValueList(["val0"])
     assert obj.value == ["value"]
Beispiel #2
0
 def test_setitem(self) -> None:
     """Test __setitem__."""
     obj = VariableValueList(["val0", "val1"])
     obj[0] = "val0"  # type: ignore
     assert obj[0] == "val0"
     assert obj[1] != "val1"
     obj[:2] = ["val0", "val1"]  # type: ignore
     assert obj[1] == "val1"
Beispiel #3
0
 def test_simplified(self, mocker: MockerFixture) -> None:
     """Test simplified."""
     mock_literal = MagicMock(simplified="simplified")
     mocker.patch.object(VariableValueList,
                         "parse_obj",
                         return_value=mock_literal)
     obj = VariableValueList(["val0"])
     assert obj.simplified == ["simplified"]
Beispiel #4
0
 def test_resolved(self, mocker: MockerFixture, resolved: bool) -> None:
     """Test resolved."""
     mock_literal = MagicMock(resolved=resolved)
     mocker.patch.object(VariableValueList,
                         "parse_obj",
                         return_value=mock_literal)
     obj = VariableValueList(["val0"])
     assert obj.resolved is resolved
Beispiel #5
0
 def test_dependencies(self, mocker: MockerFixture) -> None:
     """Test dependencies."""
     mock_literal = MagicMock(dependencies=set("test"))
     mocker.patch.object(VariableValueList,
                         "parse_obj",
                         return_value=mock_literal)
     obj = VariableValueList(["val0"])
     assert obj.dependencies == set("test")
Beispiel #6
0
 def test_init(self, mocker: MockerFixture) -> None:
     """Test __init__."""
     mock_parse_obj = mocker.patch.object(VariableValueList,
                                          "parse_obj",
                                          return_value="parsed_val")
     obj = VariableValueList(["val"])
     assert obj._data == ["parsed_val"]
     mock_parse_obj.assert_called_once_with("val", variable_type="cfngin")
     assert obj.variable_type == "cfngin"
Beispiel #7
0
 def test_resolve(self, cfngin_context: MockCFNginContext,
                  mocker: MockerFixture) -> None:
     """Test resolve."""
     mock_literal = MagicMock()
     mock_provider = MagicMock()
     mocker.patch.object(VariableValueList,
                         "parse_obj",
                         return_value=mock_literal)
     obj = VariableValueList(["val0"])
     assert not obj.resolve(
         cfngin_context,
         provider=mock_provider,
         variables={"var": "something"},  # type: ignore
         kwarg="test",
     )
     mock_literal.resolve.assert_called_once_with(
         cfngin_context,
         provider=mock_provider,
         variables={"var": "something"},
         kwarg="test",
     )
Beispiel #8
0
 def test_repr(self) -> None:
     """Test __repr__."""
     obj = VariableValueList(["val0", "val1"])
     assert repr(obj) == "List[Literal[val0], Literal[val1]]"
Beispiel #9
0
 def test_len(self) -> None:
     """Test __len__."""
     obj = VariableValueList(["val0", "val1"])
     assert len(obj) == 2
Beispiel #10
0
 def test_iter(self) -> None:
     """Test __iter__."""
     obj = VariableValueList(["val0", "val1"])
     assert [i.value for i in iter(obj)] == ["val0", "val1"]
Beispiel #11
0
 def test_insert(self) -> None:
     """Test insert."""
     obj = VariableValueList(["val0", "val1"])
     obj.insert(1, VariableValueLiteral("val2"))
     assert [i.value for i in obj] == ["val0", "val2", "val1"]
Beispiel #12
0
 def test_getitem(self) -> None:
     """Test __getitem__."""
     obj = VariableValueList(["val0", "val1"])
     assert obj[1].value == "val1"
     assert [i.value for i in obj[:2]] == ["val0", "val1"]
Beispiel #13
0
 def test_delitem(self) -> None:
     """Test __delitem__."""
     obj = VariableValueList(["val0", "val1"])
     assert "val1" in [i._data for i in obj]
     del obj[1]
     assert "val1" not in [i._data for i in obj]
Beispiel #14
0
 def test_simplified_list(self) -> None:
     """Test simplified list."""
     assert [
         i.value for i in VariableValueConcatenation(
             [VariableValueList(["foo", "bar"])]).simplified
     ] == ["foo", "bar"]