]> sigrok.org Git - sigrok-meter.git/blob - test.py
Add unit tests for the driver string parsing.
[sigrok-meter.git] / test.py
1 #!/usr/bin/env python
2
3 ##
4 ## This file is part of the sigrok-meter project.
5 ##
6 ## Copyright (C) 2015 Jens Steinhauser <jens.steinhauser@gmail.com>
7 ##
8 ## This program is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; either version 2 of the License, or
11 ## (at your option) any later version.
12 ##
13 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ## GNU General Public License for more details.
17 ##
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; if not, write to the Free Software
20 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21 ##
22
23 import unittest
24
25 if __name__ == '__main__':
26     import qtcompat
27     qtcompat.load_modules(False)
28     import samplingthread
29
30 class TestDriverstringParsing(unittest.TestCase):
31     def setUp(self):
32         self.w = samplingthread.SamplingThread.Worker(None, None)
33
34     def test_valid_driverstring(self):
35         self.assertEqual(
36             self.w.parse_driverstring('demo'),
37             ('demo', {}))
38         self.assertEqual(
39             self.w.parse_driverstring('demo:samplerate=1'),
40             ('demo', {'samplerate': 1}))
41         self.assertEqual(
42             self.w.parse_driverstring('demo:samplerate=1:analog_channels=1'),
43             ('demo', {'samplerate': 1, 'analog_channels': 1}))
44
45     def test_invalid_driverstring(self):
46         self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
47             self.w.parse_driverstring, '')
48         self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
49             self.w.parse_driverstring, ':')
50         self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
51             self.w.parse_driverstring, ':a')
52         self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
53             self.w.parse_driverstring, 'd:a')
54         self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
55             self.w.parse_driverstring, 'd:a=')
56         self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
57             self.w.parse_driverstring, 'd:a=:')
58         self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
59             self.w.parse_driverstring, 'd:a=b:')
60         self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
61             self.w.parse_driverstring, 'd:=b:')
62         self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
63             self.w.parse_driverstring, 'd:=:')
64         self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
65             self.w.parse_driverstring, 'd:=')
66
67 if __name__ == '__main__':
68     unittest.main()