Example #1
0
 def test_simplified_literal_str(self) -> None:
     """Test simplified literal str."""
     assert (VariableValueConcatenation([VariableValueLiteral("foo")
                                         ]).simplified.value == "foo")
     assert (VariableValueConcatenation(
         [VariableValueLiteral("foo"),
          VariableValueLiteral("bar")]).simplified.value == "foobar")
Example #2
0
 def test_simplified_concat(self) -> None:
     """Test simplified concatenation."""
     assert (VariableValueConcatenation([
         VariableValueLiteral("foo"),
         VariableValueConcatenation(
             [VariableValueLiteral("bar"),
              VariableValueLiteral("foo")]),
     ]).simplified.value == "foobarfoo")
Example #3
0
 def test_resolved(self) -> None:
     """Test resolved."""
     assert VariableValueConcatenation([MagicMock(resolved=True)
                                        ]).resolved is True
     assert VariableValueConcatenation([MagicMock(resolved=False)
                                        ]).resolved is False
     assert (VariableValueConcatenation(
         [MagicMock(resolved=True),
          MagicMock(resolved=False)]).resolved is False)
Example #4
0
 def test_value_multiple(self) -> None:
     """Test multiple."""
     assert (VariableValueConcatenation(
         [VariableValueLiteral("foo"),
          VariableValueLiteral("bar")]).value == "foobar")
     assert (VariableValueConcatenation(
         [VariableValueLiteral(13),
          VariableValueLiteral("/test")]  # type: ignore
     ).value == "13/test")
     assert (VariableValueConcatenation(
         [VariableValueLiteral(5),
          VariableValueLiteral(13)]).value == "513")
     with pytest.raises(InvalidLookupConcatenation):
         VariableValueConcatenation(
             [VariableValueLiteral(True),
              VariableValueLiteral("test")]  # type: ignore
         ).value
Example #5
0
 def test_setitem(self) -> None:
     """Test __setitem__."""
     obj = VariableValueConcatenation(["test-val0",
                                       "test-val1"])  # type: ignore
     obj[0] = "val0"  # type: ignore
     assert obj[0] == "val0"
     obj[:2] = ["val0", "val1"]  # type: ignore
     assert obj[1] == "val1"
Example #6
0
 def test_resolve(self, cfngin_context: MockCFNginContext,
                  mocker: MockerFixture) -> None:
     """Test resolve."""
     mock_provider = MagicMock()
     mock_resolve = mocker.patch.object(VariableValueLiteral,
                                        "resolve",
                                        return_value=None)
     obj = VariableValueConcatenation([VariableValueLiteral("val0")])
     assert not obj.resolve(
         cfngin_context,
         provider=mock_provider,
         variables={"var": "something"},  # type: ignore
         kwarg="test",
     )
     mock_resolve.assert_called_once_with(
         cfngin_context,
         provider=mock_provider,
         variables={"var": "something"},
         kwarg="test",
     )
Example #7
0
 def test_simplified_literal_int(self) -> None:
     """Test simplified literal int."""
     assert (VariableValueConcatenation([VariableValueLiteral(13)
                                         ]).simplified.value == 13)
Example #8
0
 def test_simplified_literal_empty(self) -> None:
     """Test simplified literal empty."""
     assert (VariableValueConcatenation([VariableValueLiteral("")
                                         ]).simplified.value == "")
Example #9
0
 def test_simplified_literal_bool(self) -> None:
     """Test simplified literal bool."""
     assert (VariableValueConcatenation([VariableValueLiteral(True)
                                         ]).simplified.value is True)
     assert (VariableValueConcatenation([VariableValueLiteral(False)
                                         ]).simplified.value is False)
Example #10
0
 def test_simplified_list(self) -> None:
     """Test simplified list."""
     assert [
         i.value for i in VariableValueConcatenation(
             [VariableValueList(["foo", "bar"])]).simplified
     ] == ["foo", "bar"]
Example #11
0
 def test_dependencies(self) -> None:
     """Test dependencies."""
     data = [MagicMock(dependencies={"test"})]
     obj = VariableValueConcatenation(data)
     assert obj.dependencies == {"test"}
Example #12
0
 def test_repr(self) -> None:
     """Test __repr__."""
     obj = VariableValueConcatenation(["val0", "val1"])  # type: ignore
     assert repr(obj) == "Concatenation['val0', 'val1']"  # type: ignore
Example #13
0
 def test_len(self) -> None:
     """Test __len__."""
     obj = VariableValueConcatenation(["val0", "val1"])  # type: ignore
     assert len(obj) == 2  # type: ignore
Example #14
0
 def test_iter(self) -> None:
     """Test __iter__."""
     obj = VariableValueConcatenation(["val0", "val1"])  # type: ignore
     assert list(iter(obj)) == ["val0", "val1"]  # type: ignore
Example #15
0
 def test_init(self) -> None:
     """Test __init__."""
     data = [VariableValueLiteral("test")]
     obj = VariableValueConcatenation(data)
     assert obj._data == data
     assert obj.variable_type == "cfngin"
Example #16
0
 def test_getitem(self) -> None:
     """Test __getitem__."""
     obj = VariableValueConcatenation(["val0", "val1"])  # type: ignore
     assert obj[1] == "val1"
     assert obj[:2] == ["val0", "val1"]
Example #17
0
 def test_value_single(self) -> None:
     """Test value single."""
     assert VariableValueConcatenation([VariableValueLiteral("foo")
                                        ]).value == "foo"
     assert VariableValueConcatenation([VariableValueLiteral(13)
                                        ]).value == 13
Example #18
0
 def test_delitem(self) -> None:
     """Test __delitem__."""
     obj = VariableValueConcatenation(["val0", "val1"])  # type: ignore
     assert "val1" in obj._data
     del obj[1]
     assert "val1" not in obj._data