From: Jens Steinhauser Date: Sun, 27 Sep 2015 12:38:45 +0000 (+0200) Subject: Add unit tests for the driver string parsing. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=51b4b975652548b0e2ab14d6328c5840a24b985b;p=sigrok-meter.git Add unit tests for the driver string parsing. --- diff --git a/test.py b/test.py new file mode 100755 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 +## +## 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()