6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-11-16 18:15:09 +00:00
tutor/tests/test_serialize.py
Régis Behmo 0a670d7ead refactor: add type annotations
Annotations were generated with pyannotate:
https://github.com/dropbox/pyannotate

We are running in strict mode, which is awesome!

This affects a large part of the code base, which might be an issue for
people running a fork of Tutor. Nonetheless, the behavior should not be
affected. If anything, this process has helped find and resolve a few
type-related bugs. Thus, this is not considered as a breaking change.
2021-03-15 21:46:55 +01:00

42 lines
1.5 KiB
Python

import unittest
import click
from tutor import serialize
class SerializeTests(unittest.TestCase):
def test_parse_str(self) -> None:
self.assertEqual("abcd", serialize.parse("abcd"))
def test_parse_int(self) -> None:
self.assertEqual(1, serialize.parse("1"))
def test_parse_bool(self) -> None:
self.assertEqual(True, serialize.parse("true"))
self.assertEqual(False, serialize.parse("false"))
def test_parse_null(self) -> None:
self.assertIsNone(serialize.parse("null"))
def test_parse_invalid_format(self) -> None:
self.assertEqual('["abcd"', serialize.parse('["abcd"'))
def test_parse_list(self) -> None:
self.assertEqual(["abcd"], serialize.parse('["abcd"]'))
def test_parse_weird_chars(self) -> None:
self.assertEqual("*@google.com", serialize.parse("*@google.com"))
def test_parse_empty_string(self) -> None:
self.assertEqual("", serialize.parse("''"))
def test_yaml_param_type(self) -> None:
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", {}))