import unittest
from wrpylib.wrvalidators import *
-# TODO: optional converter
+# optional converter
# ------------------
+class TestOpt(unittest.TestCase):
+ def test_from_str(self):
+ self.assertEqual(None, opt_from_str('', str_from_str))
+ self.assertEqual('abc', opt_from_str('abc', str_from_str))
+ self.assertEqual(None, opt_from_str('', int_from_str))
+ self.assertEqual(4, opt_from_str('4', int_from_str))
+
+ def test_to_str(self):
+ self.assertEqual('', opt_to_str(None, str_to_str))
+ self.assertEqual('abc', opt_to_str('abc', str_to_str))
+ self.assertEqual('', opt_to_str(None, int_to_str))
+ self.assertEqual('4', opt_to_str(4, int_to_str))
+
+
# "no" converter
# --------------
self.assertEqual('', opt_no_german_to_str((None, None), str_to_str))
-# TODO: choice converter
+# choice converter
# ----------------
+class TestCoice(unittest.TestCase):
+ def setUp(self):
+ self.choices = ['abc', 'def', 'ghi']
-# TODO: dict converter
-# --------------
+ def 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
self.assertEqual(self.value, rodelbahnbox_to_str(value))
-# TODO: Gasthausbox converter
+# Gasthausbox converter
# ---------------------
class TestGasthausbox(unittest.TestCase):