]>
Commit | Line | Data |
---|---|---|
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 sigrok.core as sr | |
24 | import unittest | |
25 | ||
26 | if __name__ == '__main__': | |
27 | import qtcompat | |
28 | qtcompat.load_modules(False) | |
29 | import acquisition | |
30 | ||
31 | class TestDriverstringParsing(unittest.TestCase): | |
32 | def setUp(self): | |
33 | self.context = sr.Context_create() | |
34 | self.a = acquisition.Acquisition(self.context) | |
35 | ||
36 | def test_valid_driverstring(self): | |
37 | self.assertEqual( | |
38 | self.a._parse_driverstring('demo'), | |
39 | ('demo', {})) | |
40 | self.assertEqual( | |
41 | self.a._parse_driverstring('demo:samplerate=1'), | |
42 | ('demo', {'samplerate': 1})) | |
43 | self.assertEqual( | |
44 | self.a._parse_driverstring('demo:samplerate=1:analog_channels=1'), | |
45 | ('demo', {'samplerate': 1, 'analog_channels': 1})) | |
46 | ||
47 | def test_invalid_driverstring(self): | |
48 | self.assertRaisesRegexp(ValueError, 'is not a valid driver string', | |
49 | self.a._parse_driverstring, '') | |
50 | self.assertRaisesRegexp(ValueError, 'is not a valid driver string', | |
51 | self.a._parse_driverstring, ':') | |
52 | self.assertRaisesRegexp(ValueError, 'is not a valid driver string', | |
53 | self.a._parse_driverstring, ':a') | |
54 | self.assertRaisesRegexp(ValueError, 'is not a valid driver string', | |
55 | self.a._parse_driverstring, 'd:a') | |
56 | self.assertRaisesRegexp(ValueError, 'is not a valid driver string', | |
57 | self.a._parse_driverstring, 'd:a=') | |
58 | self.assertRaisesRegexp(ValueError, 'is not a valid driver string', | |
59 | self.a._parse_driverstring, 'd:a=:') | |
60 | self.assertRaisesRegexp(ValueError, 'is not a valid driver string', | |
61 | self.a._parse_driverstring, 'd:a=b:') | |
62 | self.assertRaisesRegexp(ValueError, 'is not a valid driver string', | |
63 | self.a._parse_driverstring, 'd:=b:') | |
64 | self.assertRaisesRegexp(ValueError, 'is not a valid driver string', | |
65 | self.a._parse_driverstring, 'd:=:') | |
66 | self.assertRaisesRegexp(ValueError, 'is not a valid driver string', | |
67 | self.a._parse_driverstring, 'd:=') | |
68 | ||
69 | if __name__ == '__main__': | |
70 | unittest.main() |