From 836b4106aeef9acd30a4fd4dbca00c5d90e9aef7 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Wed, 10 Feb 2021 09:32:37 +0100 Subject: Add the option to autoincrement integer values --- tests/test_types.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/test_types.py') diff --git a/tests/test_types.py b/tests/test_types.py index 260167c..1efcde1 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -82,6 +82,35 @@ class testTypes(unittest.TestCase): v = checker.update(10) self.assertEqual(v, 10) + def test_datetime_auto_increment(self): + field_def = self._get_field_def('integer') + field_def['auto'] = 'increment' + checker = types.LesanaInt(field_def, {}) + + v = checker.empty() + self.assertEqual(v, 0) + + v = checker.update(0) + self.assertEqual(v, 1) + + field_def['increment'] = -1 + checker = types.LesanaInt(field_def, {}) + v = checker.update(0) + self.assertEqual(v, -1) + + field_def['increment'] = 0.5 + checker = types.LesanaInt(field_def, {}) + with self.assertLogs() as cm: + v = checker.update(0) + self.assertIn('WARNING', cm.output[0]) + self.assertIn('Invalid configuration value', cm.output[0]) + self.assertEqual(v, 0) + + field_def['auto'] = 'false' + checker = types.LesanaInt(field_def, {}) + v = checker.update(0) + self.assertEqual(v, 0) + def test_float(self): checker = types.LesanaFloat(self._get_field_def('float'), {}) -- cgit v1.2.3