doc: update IRC reference to Libera.Chat
[sigrok-meter/gsi.git] / test.py
blob451587097debf6821b07de57fa545a1c419d53ec
1 #!/usr/bin/env python
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.
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.
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
22 import sigrok.core as sr
23 import unittest
25 if __name__ == '__main__':
26 import qtcompat
27 qtcompat.load_modules(False)
28 import acquisition
30 class TestDriverstringParsing(unittest.TestCase):
31 def setUp(self):
32 self.context = sr.Context_create()
33 self.a = acquisition.Acquisition(self.context)
35 def test_valid_driverstring(self):
36 self.assertEqual(
37 self.a._parse_driverstring('demo'),
38 ('demo', {}))
39 self.assertEqual(
40 self.a._parse_driverstring('demo:samplerate=1'),
41 ('demo', {'samplerate': 1}))
42 self.assertEqual(
43 self.a._parse_driverstring('demo:samplerate=1:analog_channels=1'),
44 ('demo', {'samplerate': 1, 'analog_channels': 1}))
46 def test_invalid_driverstring(self):
47 self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
48 self.a._parse_driverstring, '')
49 self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
50 self.a._parse_driverstring, ':')
51 self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
52 self.a._parse_driverstring, ':a')
53 self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
54 self.a._parse_driverstring, 'd:a')
55 self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
56 self.a._parse_driverstring, 'd:a=')
57 self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
58 self.a._parse_driverstring, 'd:a=:')
59 self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
60 self.a._parse_driverstring, 'd:a=b:')
61 self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
62 self.a._parse_driverstring, 'd:=b:')
63 self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
64 self.a._parse_driverstring, 'd:=:')
65 self.assertRaisesRegexp(ValueError, 'is not a valid driver string',
66 self.a._parse_driverstring, 'd:=')
68 if __name__ == '__main__':
69 unittest.main()