+# "no" converter
+# --------------
+
+class TestNoGermanConverter(unittest.TestCase):
+ def test_from_str(self):
+ self.assertEqual((True, 'abc'), no_german_from_str('abc', req_str_from_str))
+ self.assertEqual((False, None), no_german_from_str('Nein', req_str_from_str))
+ with self.assertRaises(ValueError):
+ no_german_from_str('', req_str_from_str)
+
+ def test_to_str(self):
+ self.assertEqual('abc', no_german_to_str((True, 'abc'), str_to_str))
+ self.assertEqual('Nein', no_german_to_str((False, None), str_to_str))
+
+
+# "optional"/"no" converter
+# -------------------------
+
+class TestOptNoGerman(unittest.TestCase):
+ def test_from_str(self):
+ self.assertEqual((True, 'abc'), opt_no_german_from_str('abc', str_from_str))
+ self.assertEqual((False, None), opt_no_german_from_str('Nein', str_from_str))
+ self.assertEqual((None, None), opt_no_german_from_str('', str_from_str))
+
+ def test_to_str(self):
+ self.assertEqual('abc', opt_no_german_to_str((True, 'abc'), str_to_str))
+ self.assertEqual('Nein', opt_no_german_to_str((False, None), str_to_str))
+ self.assertEqual('', opt_no_german_to_str((None, None), str_to_str))
+
+
+# choice converter
+# ----------------
+
+class TestCoice(unittest.TestCase):
+ def setUp(self):
+ self.choices = ['abc', 'def', 'ghi']
+
+ def test_from_str(self):
+ self.assertEqual('abc', choice_from_str('abc', self.choices))
+ self.assertEqual('ghi', choice_from_str('ghi', self.choices))
+ with self.assertRaises(ValueError):
+ choice_from_str('jkl', self.choices)
+
+
+# dictkey converter
+# -----------------
+
+class TestDictkey(unittest.TestCase):
+ def setUp(self):
+ self.choices = {'abc': '1', 'def': '2', 'ghi': '3'}
+
+ def test_from_str(self):
+ self.assertEqual('abc', dictkey_from_str('1', self.choices))
+ self.assertEqual('ghi', dictkey_from_str('3', self.choices))
+ with self.assertRaises(ValueError):
+ dictkey_from_str('4', self.choices)
+
+ def test_to_str(self):
+ self.assertEqual('1', dictkey_to_str('abc', self.choices))
+ self.assertEqual('3', dictkey_to_str('ghi', self.choices))
+
+
+# enum/"list" converter
+# ---------------------
+
+class TestEnumConverter(unittest.TestCase):
+ def test_from_str(self):
+ self.assertEqual([], enum_from_str('', str_from_str))
+ self.assertEqual(['abc'], enum_from_str('abc', str_from_str))
+ self.assertEqual(['abc', 'def'], enum_from_str('abc; def', str_from_str))
+ self.assertEqual(['abc', 'def', 'ghi'], enum_from_str('abc; def;ghi', str_from_str))
+
+ def test_to_str(self):
+ self.assertEqual('abc; def; ghi', enum_to_str(['abc', 'def', 'ghi'], str_to_str))
+ self.assertEqual('abc', enum_to_str(['abc'], str_to_str))
+ self.assertEqual('', enum_to_str([''], str_to_str))
+ self.assertEqual('', enum_to_str([], str_to_str))
+
+
+# value/comment converter
+# -----------------------
+
+class TestValueCommentConverter(unittest.TestCase):
+ def test_from_str(self):
+ self.assertEqual(('abc', 'defg'), value_comment_from_str('abc (defg)', str_from_str, str_from_str))
+ self.assertEqual(('abc', ''), value_comment_from_str('abc ()', str_from_str, str_from_str))
+ self.assertEqual(('', 'def'), value_comment_from_str('(def)', str_from_str, str_from_str))
+ self.assertEqual(('ab', '(cd)'), value_comment_from_str('ab ((cd))', str_from_str, str_from_str))
+ self.assertEqual(('ab', '(c(d)[(]))'), value_comment_from_str('ab ((c(d)[(])))', str_from_str, str_from_str))
+ self.assertEqual(('ab(', 'cd'), value_comment_from_str('ab( (cd)', str_from_str, str_from_str))
+ self.assertEqual(('abcd ', 'ef'), value_comment_from_str('abcd (ef)', str_from_str, str_from_str))
+ self.assertEqual(('abc', ''), value_comment_from_str('abc', str_from_str, str_from_str, comment_optional=True))
+ self.assertEqual(('a(bc)de', 'fg'), value_comment_from_str('a(bc)de (fg)', str_from_str, str_from_str))
+ self.assertEqual(('a(bc)de', 'fg'), value_comment_from_str('a(bc)de (fg)', str_from_str, str_from_str, comment_optional=True))
+ self.assertEqual(('a(bc)de', 'f(g)'), value_comment_from_str('a(bc)de (f(g))', str_from_str, str_from_str))
+ self.assertEqual(('a(bc)de', 'f(g)'), value_comment_from_str('a(bc)de (f(g))', str_from_str, str_from_str, comment_optional=True))
+ self.assertEqual(('a(bc)de', None), value_comment_from_str('a(bc)de', str_from_str, opt_str_from_str, comment_optional=True))
+ with self.assertRaises(ValueError):
+ value_comment_from_str('abc (', str_from_str, str_from_str)
+ with self.assertRaises(ValueError):
+ value_comment_from_str('abc )', str_from_str, str_from_str)
+ with self.assertRaises(ValueError):
+ value_comment_from_str('abc (def)g', str_from_str, str_from_str)
+ with self.assertRaises(ValueError):
+ value_comment_from_str('abc (b))', str_from_str, str_from_str)
+ with self.assertRaises(ValueError):
+ value_comment_from_str('abc', str_from_str, str_from_str)
+ with self.assertRaises(ValueError):
+ value_comment_from_str('abc(def)', str_from_str, str_from_str)
+
+ def test_to_str(self):
+ self.assertEqual('abc (defg)', value_comment_to_str(('abc', 'defg'), str_to_str, str_to_str))
+ self.assertEqual('abc ()', value_comment_to_str(('abc', ''), str_to_str, str_to_str))
+ self.assertEqual('(def)', value_comment_to_str(('', 'def'), str_to_str, str_to_str))
+ self.assertEqual('ab ((cd))', value_comment_to_str(('ab', '(cd)'), str_to_str, str_to_str))
+ self.assertEqual('ab ((c(d)[(])))', value_comment_to_str(('ab', '(c(d)[(]))'), str_to_str, str_to_str))
+ self.assertEqual('ab( (cd)', value_comment_to_str(('ab(', 'cd'), str_to_str, str_to_str))
+ self.assertEqual('abcd (ef)', value_comment_to_str(('abcd', 'ef'), str_to_str, str_to_str))
+ self.assertEqual('abc', value_comment_to_str(('abc', ''), str_to_str, str_to_str, comment_optional=True))
+ self.assertEqual('a(bc)de (fg)', value_comment_to_str(('a(bc)de', 'fg'), str_to_str, str_to_str))
+ self.assertEqual('a(bc)de (fg)', value_comment_to_str(('a(bc)de', 'fg'), str_to_str, str_to_str, comment_optional=True))
+ self.assertEqual('a(bc)de (f(g))', value_comment_to_str(('a(bc)de', 'f(g)'), str_to_str, str_to_str))
+ self.assertEqual('a(bc)de (f(g))', value_comment_to_str(('a(bc)de', 'f(g)'), str_to_str, str_to_str, comment_optional=True))
+ self.assertEqual('a(bc)de', value_comment_to_str(('a(bc)de', None), str_to_str, opt_str_to_str, comment_optional=True))
+
+
+# string converter
+# ----------------
+
+class TestStr(unittest.TestCase):
+ def test_from_str(self):
+ self.assertEqual('', str_from_str(''))
+ self.assertEqual('abc', str_from_str('abc'))
+
+ def test_to_str(self):
+ self.assertEqual('', str_to_str(''))
+ self.assertEqual('abc', str_to_str('abc'))
+
+
+class TestReqStr(unittest.TestCase):
+ def test_from_str(self):
+ self.assertEqual('abc', req_str_from_str('abc'))
+ self.assertEqual(' ', req_str_from_str(' '))
+ with self.assertRaises(ValueError):
+ req_str_from_str('')
+
+
+class TestOptStr(unittest.TestCase):
+ def test_from_str(self):
+ self.assertEqual('abc', opt_str_from_str('abc'))
+ self.assertEqual(' ', opt_str_from_str(' '))
+ self.assertEqual(None, opt_str_from_str(''))
+
+ def test_to_str(self):
+ self.assertEqual('abc', opt_str_to_str('abc'))
+ self.assertEqual(' ', opt_str_to_str(' '))
+ self.assertEqual('', opt_str_to_str(None))
+
+
+# optional no or string converter
+# -------------------------------
+
+class TestOptNoOrStr(unittest.TestCase):
+ def test_from_str(self):
+ self.assertEqual((False, None), opt_no_or_str_from_str('Nein'))
+ self.assertEqual((True, 'Nur Wochenende'), opt_no_or_str_from_str('Nur Wochenende'))
+ self.assertEqual((True, 'Ja'), opt_no_or_str_from_str('Ja'))
+ self.assertEqual((None, None), opt_no_or_str_from_str(''))
+
+ def test_to_str(self):
+ self.assertEqual('Nein', opt_no_or_str_to_str((False, None)))
+ self.assertEqual('Nur Wochenende', opt_no_or_str_to_str((True, 'Nur Wochenende')))
+ self.assertEqual('Ja', opt_no_or_str_to_str((True, 'Ja')))
+ self.assertEqual('', opt_no_or_str_to_str((None, None)))
+
+
+# integer converter
+# -----------------
+