]> arthur.barton.de Git - bup.git/blob - lib/bup/t/toptions.py
Merge remote branch 'origin/master' into meta
[bup.git] / lib / bup / t / toptions.py
1 from bup import options
2 from wvtest import *
3
4 @wvtest
5 def test_optdict():
6     d = options.OptDict()
7     WVPASS('foo')
8     d['x'] = 5
9     d['y'] = 4
10     d['z'] = 99
11     d['no_other_thing'] = 5
12     WVPASSEQ(d.x, 5)
13     WVPASSEQ(d.y, 4)
14     WVPASSEQ(d.z, 99)
15     WVPASSEQ(d.no_z, False)
16     WVPASSEQ(d.no_other_thing, True)
17     try:
18         print d.p
19     except:
20         WVPASS("invalid args don't match")
21     else:
22         WVFAIL("exception expected")
23
24
25 optspec = """
26 prog <optionset> [stuff...]
27 prog [-t] <boggle>
28 --
29 t       test
30 q,quiet   quiet
31 l,longoption=   long option with parameters and a really really long description that will require wrapping
32 p= short option with parameters
33 onlylong  long option with no short
34 neveropt never called options
35 deftest1=  a default option with default [1]
36 deftest2=  a default option with [1] default [2]
37 deftest3=  a default option with [3] no actual default
38 deftest4=  a default option with [[square]]
39 deftest5=  a default option with "correct" [[square]
40 no-stupid  disable stupidity
41 """
42
43 @wvtest
44 def test_options():
45     o = options.Options(optspec)
46     (opt,flags,extra) = o.parse(['-tttqp', 7, '--longoption', '19',
47                                  'hanky', '--onlylong'])
48     WVPASSEQ(flags[0], ('-t', ''))
49     WVPASSEQ(flags[1], ('-t', ''))
50     WVPASSEQ(flags[2], ('-t', ''))
51     WVPASSEQ(flags[3], ('-q', ''))
52     WVPASSEQ(flags[4], ('-p', 7))
53     WVPASSEQ(flags[5], ('--longoption', '19'))
54     WVPASSEQ(extra, ['hanky'])
55     WVPASSEQ((opt.t, opt.q, opt.p, opt.l, opt.onlylong,
56               opt.neveropt), (3,1,7,19,1,None))
57     WVPASSEQ((opt.deftest1, opt.deftest2, opt.deftest3, opt.deftest4,
58               opt.deftest5), (1,2,None,None,'[square'))
59     WVPASSEQ((opt.stupid, opt.no_stupid), (True, False))
60     (opt,flags,extra) = o.parse(['--onlylong', '-t', '--no-onlylong'])
61     WVPASSEQ((opt.t, opt.q, opt.onlylong), (1, None, 0))