]> sigrok.org Git - sigrok-meter.git/commitdiff
Add unit tests for the driver string parsing.
authorJens Steinhauser <redacted>
Sun, 27 Sep 2015 12:38:45 +0000 (14:38 +0200)
committerJens Steinhauser <redacted>
Sun, 27 Sep 2015 12:38:45 +0000 (14:38 +0200)
test.py [new file with mode: 0755]

diff --git a/test.py b/test.py
new file mode 100755 (executable)
index 0000000..2adb108
--- /dev/null
+++ b/test.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+
+##
+## This file is part of the sigrok-meter project.
+##
+## Copyright (C) 2015 Jens Steinhauser <jens.steinhauser@gmail.com>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+##
+
+import unittest
+
+if __name__ == '__main__':
+    import qtcompat
+    qtcompat.load_modules(False)
+    import samplingthread
+
+class TestDriverstringParsing(unittest.TestCase):
+    def setUp(self):
+        self.w = samplingthread.SamplingThread.Worker(None, None)
+
+    def test_valid_driverstring(self):
+        self.assertEqual(
+            self.w.parse_driverstring('demo'),
+            ('demo', {}))
+        self.assertEqual(
+            self.w.parse_driverstring('demo:samplerate=1'),
+            ('demo', {'samplerate': 1}))
+        self.assertEqual(
+            self.w.parse_driverstring('demo:samplerate=1:analog_channels=1'),
+            ('demo', {'samplerate': 1, 'analog_channels': 1}))
+
+    def test_invalid_driverstring(self):
+        self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
+            self.w.parse_driverstring, '')
+        self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
+            self.w.parse_driverstring, ':')
+        self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
+            self.w.parse_driverstring, ':a')
+        self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
+            self.w.parse_driverstring, 'd:a')
+        self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
+            self.w.parse_driverstring, 'd:a=')
+        self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
+            self.w.parse_driverstring, 'd:a=:')
+        self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
+            self.w.parse_driverstring, 'd:a=b:')
+        self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
+            self.w.parse_driverstring, 'd:=b:')
+        self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
+            self.w.parse_driverstring, 'd:=:')
+        self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
+            self.w.parse_driverstring, 'd:=')
+
+if __name__ == '__main__':
+    unittest.main()