Exemple #1
0
 def test_add_value_2(self):
     # Add a list value to a ListParameter with already a value set, expect
     # a list with both values.
     # The ListParameter is initialized with a list.
     add_value = ["foo"]
     list_param = ListParameter("list", value=["bar", "baz"])
     expected = ["bar", "baz", "foo"]
     list_param.add(add_value)
     self.assertEquals(expected, list_param.value)
    def test_save_list_param(self):
        # Tests that when saved to file, the ListParameter parameter is stored
        # correctly.
        param_values = ["foo", "more than one words", "bar"]
        list_param = ListParameter("list")
        list_param.set(param_values)

        self.config.put_parameter(list_param, param_values)
        self.config.save()

        expected = "[DEFAULT]\nlist = " + ",".join(param_values) + "\n\n"
        obtained = ""
        with open(self.temp_file.name, "r") as read_file:
            obtained = read_file.read()
        self.assertEqual(expected, obtained)
 def test_interactive_config_with_list_parameter(self, mocked_raw_input):
     # Tests that we get a list back in the Config class when using
     # ListParameter and that it contains the expected values.
     expected = ["foo", "bar"]
     mocked_raw_input.side_effect = expected + ["\n"]
     obtained = self.config.get(ListParameter("list"))
     self.assertIsInstance(obtained, list)
     self.assertEqual(expected, obtained)
Exemple #4
0
 def setUp(self):
     super(ListParameterTest, self).setUp()
     self.list_parameter = ListParameter("list")
Exemple #5
0
class ListParameterTest(GeneralParameterTest):
    """Tests for the specialized ListParameter class."""
    def setUp(self):
        super(ListParameterTest, self).setUp()
        self.list_parameter = ListParameter("list")

    def test_prompt_0(self):
        # Test that when pressing Enter, the prompt stops and the list is
        # returned.
        expected = []
        self.mocked_raw_input.return_value = "\n"
        obtained = self.list_parameter.prompt()
        self.assertEqual(expected, obtained)

    def test_prompt_1(self):
        # Tests that when passing 3 values, a list with those values
        # is returned
        expected = ["foo", "bar", "foobar"]
        self.mocked_raw_input.side_effect = expected + ["\n"]
        obtained = self.list_parameter.prompt()
        self.assertEqual(expected, obtained)

    def test_serialize_0(self):
        # Tests the serialize method of ListParameter passing a list.
        expected = "foo,bar,baz,1"
        to_serialize = ["foo", "bar", "baz", "", 1]

        obtained = self.list_parameter.serialize(to_serialize)
        self.assertEqual(expected, obtained)

    def test_serialize_1(self):
        # Tests the serialize method of ListParameter passing an int.
        expected = "1"
        to_serialize = 1

        obtained = self.list_parameter.serialize(to_serialize)
        self.assertEqual(expected, obtained)

    def test_deserialize_0(self):
        # Tests the deserialize method of ListParameter with a string
        # of values.
        expected = ["foo", "bar", "baz"]
        to_deserialize = "foo,bar,,baz,"
        obtained = self.list_parameter.deserialize(to_deserialize)
        self.assertEqual(expected, obtained)

    def test_deserialize_1(self):
        # Tests the deserialization method of ListParameter passing a list.
        expected = ["foo", 1, "", "bar"]
        obtained = self.list_parameter.deserialize(expected)
        self.assertEqual(expected, obtained)

    def test_set_value_0(self):
        # Pass a string to a ListParameter, expect a list.
        set_value = "foo"
        expected = [set_value]
        self.list_parameter.set(set_value)
        self.assertEquals(expected, self.list_parameter.value)

    def test_set_value_1(self):
        # Pass a list to a ListParameter, expect the same list.
        expected = ["foo", "bar"]
        self.list_parameter.set(expected)
        self.assertEquals(expected, self.list_parameter.value)

    def test_add_value_0(self):
        # Add a value to a ListParameter, expect a list back.
        add_value = "foo"
        expected = [add_value]
        self.list_parameter.add(add_value)
        self.assertEquals(expected, self.list_parameter.value)

    def test_add_value_1(self):
        # Add a list value to a ListParameter with already a value set, expect
        # a list with both values.
        # The ListParameter is initialized with a string.
        add_value = ["foo"]
        list_param = ListParameter("list", value="bar")
        expected = ["bar", "foo"]
        list_param.add(add_value)
        self.assertEquals(expected, list_param.value)

    def test_add_value_2(self):
        # Add a list value to a ListParameter with already a value set, expect
        # a list with both values.
        # The ListParameter is initialized with a list.
        add_value = ["foo"]
        list_param = ListParameter("list", value=["bar", "baz"])
        expected = ["bar", "baz", "foo"]
        list_param.add(add_value)
        self.assertEquals(expected, list_param.value)
#
# You should have received a copy of the GNU Lesser General Public License
# along with lava-tool.  If not, see <http://www.gnu.org/licenses/>.

from lava.parameter import (
    ListParameter,
    Parameter,
)

LAVA_TEST_SHELL_TAR_REPO_KEY = "tar-repo"
LAVA_TEST_SHELL_TESDEF_KEY = "testdef"

DEVICE_TYPE_PARAMETER = Parameter("device_type")
PREBUILT_IMAGE_PARAMETER = Parameter("image", depends=DEVICE_TYPE_PARAMETER)

TESTDEF_URLS_PARAMETER = ListParameter("testdef_urls")
TESTDEF_URLS_PARAMETER.store = False

BOOT_TEST = {
    "timeout":
    18000,
    "job_name":
    "Boot test",
    "device_type":
    DEVICE_TYPE_PARAMETER,
    "actions": [{
        "command": "deploy_linaro_image",
        "parameters": {
            "image": PREBUILT_IMAGE_PARAMETER
        }
    }, {