2019-07-10 07:00:44 +00:00
|
|
|
import unittest
|
|
|
|
|
2021-03-08 11:20:46 +00:00
|
|
|
import click
|
|
|
|
|
2019-07-10 07:00:44 +00:00
|
|
|
from tutor import serialize
|
|
|
|
|
|
|
|
|
|
|
|
class SerializeTests(unittest.TestCase):
|
2021-02-25 08:09:14 +00:00
|
|
|
def test_parse_str(self) -> None:
|
2019-07-10 07:00:44 +00:00
|
|
|
self.assertEqual("abcd", serialize.parse("abcd"))
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def test_parse_int(self) -> None:
|
2019-07-10 07:00:44 +00:00
|
|
|
self.assertEqual(1, serialize.parse("1"))
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def test_parse_bool(self) -> None:
|
2019-07-10 07:00:44 +00:00
|
|
|
self.assertEqual(True, serialize.parse("true"))
|
|
|
|
self.assertEqual(False, serialize.parse("false"))
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def test_parse_null(self) -> None:
|
2019-07-10 07:00:44 +00:00
|
|
|
self.assertIsNone(serialize.parse("null"))
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def test_parse_invalid_format(self) -> None:
|
2019-07-10 07:00:44 +00:00
|
|
|
self.assertEqual('["abcd"', serialize.parse('["abcd"'))
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def test_parse_list(self) -> None:
|
2019-07-10 07:00:44 +00:00
|
|
|
self.assertEqual(["abcd"], serialize.parse('["abcd"]'))
|
2019-07-11 02:31:23 +00:00
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def test_parse_weird_chars(self) -> None:
|
2019-07-11 02:31:23 +00:00
|
|
|
self.assertEqual("*@google.com", serialize.parse("*@google.com"))
|
2020-01-21 16:09:58 +00:00
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def test_parse_empty_string(self) -> None:
|
2020-01-21 16:09:58 +00:00
|
|
|
self.assertEqual("", serialize.parse("''"))
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def test_yaml_param_type(self) -> None:
|
2021-03-08 11:20:46 +00:00
|
|
|
param = serialize.YamlParamType()
|
|
|
|
self.assertEqual(("name", True), param.convert("name=true", "param", {}))
|
|
|
|
self.assertEqual(("name", "abcd"), param.convert("name=abcd", "param", {}))
|
|
|
|
self.assertEqual(("name", ""), param.convert("name=", "param", {}))
|
|
|
|
with self.assertRaises(click.exceptions.BadParameter):
|
|
|
|
param.convert("name", "param", {})
|
|
|
|
self.assertEqual(("x", "a=bcd"), param.convert("x=a=bcd", "param", {}))
|