-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathddar_test.py
54 lines (46 loc) · 2.55 KB
/
ddar_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
import unittest
import ddar
class TestArgParser(unittest.TestCase):
def check_result(self, cmdline, result):
test_result = ddar.parse_args(cmdline.split(), **ddar.ddar_arg_spec)
# Remove anything that is not set (None) for brevity in individual
# tests. We check the None behaviour in test_none.
test_result = dict(((k,v) for k,v in test_result.iteritems()
if v is not None))
if test_result['member'] == []:
del test_result['member']
self.assertEquals(test_result, result)
def test_none(self):
result = ddar.parse_args([], **ddar.ddar_arg_spec)
self.assert_(all((result[v] is None for v in 'ctxdf')))
self.assertEqual(result['member'], [])
def test_args(self):
self.check_result('c', { 'c': True })
self.check_result('-c', { 'c': True })
self.check_result('-c', { 'c': True })
self.check_result('--fsck', { 'fsck': True } )
self.check_result('c foo', { 'c': True, 'member': [ 'foo' ] })
self.check_result('c foo bar', { 'c': True,
'member': [ 'foo', 'bar' ]})
self.check_result('c foo bar -f baz', { 'c': True, 'f': 'baz',
'member': [ 'foo', 'bar' ]})
self.check_result('c foo bar -- -f baz', { 'c': True,
'member': [ 'foo', 'bar',
'-f', 'baz' ]})
self.check_result('cfbar', { 'c': True, 'f': 'bar' })
self.check_result('-cfbar', { 'c': True, 'f': 'bar' })
self.check_result('-c -fbar', { 'c': True, 'f': 'bar' })
self.check_result('-c -- -fbar', { 'c': True,
'member': [ '-fbar' ] })
self.check_result('--fsck foo', { 'fsck': True, 'member': [ 'foo' ] })
self.check_result('cfbar --rsh ssh', { 'c': True, 'f': 'bar',
'rsh': 'ssh' })
self.check_result('cfbar --rsh=ssh', { 'c': True, 'f': 'bar',
'rsh': 'ssh' })
self.assertRaises(ddar.OptionError, ddar.parse_args,
'--fsck=foo foo'.split())
self.assertRaises(ddar.OptionError, ddar.parse_args, 'ct'.split())
self.assertRaises(ddar.OptionError, ddar.parse_args, '-ct'.split())
self.assertRaises(ddar.OptionError, ddar.parse_args, '-c -t'.split())
# vim: set ts=8 sts=4 sw=4 ai et :