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