def test_getas__with_known_param_and_preconverted_value(self):
        userdata = UserData(param=42)
        assert "param" in userdata, "ENSURE: known param"

        value = userdata.getas(int, "param")
        assert isinstance(value, int)
        self.assertEqual(value, 42)
    def test_getas__with_known_param_and_preconverted_value(self):
        userdata = UserData(param=42)
        assert "param" in userdata, "ENSURE: known param"

        value = userdata.getas(int, "param")
        assert isinstance(value, int)
        self.assertEqual(value, 42)
    def test_getas__with_unknown_param_returns_default_value(self):
        userdata = UserData()
        assert "param" not in userdata, "ENSURE: unknown param"

        value = userdata.getas(int, "param", 123)
        assert isinstance(value, int)
        self.assertEqual(value, 123)
    def test_getas__with_unknown_param_returns_default_value(self):
        userdata = UserData()
        assert "param" not in userdata, "ENSURE: unknown param"

        value = userdata.getas(int, "param", 123)
        assert isinstance(value, int)
        self.assertEqual(value, 123)
Exemple #5
0
    def test_getas__with_known_param_and_valid_text(self):
        userdata = UserData(param="42")
        assert "param" in userdata, "ENSURE: known param"

        value = userdata.getas(int, "param")
        assert isinstance(value, int)
        assert value == 42
Exemple #6
0
    def test_getas__with_known_param_and_valid_text(self):
        userdata = UserData(param="42")
        assert "param" in userdata, "ENSURE: known param"

        value = userdata.getas(int, "param")
        assert isinstance(value, int)
        assert value == 42
    def test_getas__with_known_param_and_preconverted_value_and_valuetype(self):
        userdata = UserData(param=42)
        assert "param" in userdata, "ENSURE: known param"

        def parse_int(text):
            return int(text)

        value = userdata.getas(parse_int, "param", valuetype=int)
        assert isinstance(value, int)
        self.assertEqual(value, 42)
    def test_getas__with_known_param_and_preconverted_value_and_valuetype(
            self):
        userdata = UserData(param=42)
        assert "param" in userdata, "ENSURE: known param"

        def parse_int(text):
            return int(text)

        value = userdata.getas(parse_int, "param", valuetype=int)
        assert isinstance(value, int)
        self.assertEqual(value, 42)
    def test_getas__with_unknown_param_without_default_returns_none(self):
        userdata = UserData()
        assert "param" not in userdata, "ENSURE: unknown param"

        value = userdata.getas(int, "param")
        assert value is None
Exemple #10
0
    def test_getas__with_unknown_param_without_default_returns_none(self):
        userdata = UserData()
        assert "param" not in userdata, "ENSURE: unknown param"

        value = userdata.getas(int, "param")
        assert value is None
Exemple #11
0
 def test_getas__with_known_param_and_invalid_text_raises_ValueError(self):
     userdata = UserData(param="__BAD_NUMBER__")
     assert "param" in userdata, "ENSURE: known param"
     with pytest.raises(ValueError):
         userdata.getas(int, "param")
Exemple #12
0
 def test_getas__with_known_param_and_invalid_text_raises_ValueError(self):
     userdata = UserData(param="__BAD_NUMBER__")
     assert "param" in userdata, "ENSURE: known param"
     with pytest.raises(ValueError):
         userdata.getas(int, "param")