4 ## This file is part of the sigrok-meter project.
6 ## Copyright (C) 2015 Jens Steinhauser <jens.steinhauser@gmail.com>
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
25 if __name__
== '__main__':
27 qtcompat
.load_modules(False)
30 class TestDriverstringParsing(unittest
.TestCase
):
32 self
.context
= sr
.Context_create()
33 self
.a
= acquisition
.Acquisition(self
.context
)
35 def test_valid_driverstring(self
):
37 self
.a
._parse
_driverstring
('demo'),
40 self
.a
._parse
_driverstring
('demo:samplerate=1'),
41 ('demo', {'samplerate': 1}))
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__':