]> arthur.barton.de Git - bup.git/blob - lib/bup/t/toptions.py
Move t/*.py to lib/bup/t/*.py.
[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     WVPASSEQ(d.x, 5)
12     WVPASSEQ(d.y, 4)
13     WVPASSEQ(d.z, 99)
14     try:
15         print d.p
16     except:
17         WVPASS("invalid args don't match")
18     else:
19         WVFAIL("exception expected")
20
21
22 optspec = """
23 prog <optionset> [stuff...]
24 prog [-t] <boggle>
25 --
26 t       test
27 q,quiet   quiet
28 l,longoption=   long option with parameters and a really really long description that will require wrapping
29 p= short option with parameters
30 onlylong  long option with no short
31 neveropt never called options
32 """
33
34 @wvtest
35 def test_options():
36     o = options.Options('exename', optspec)
37     (opt,flags,extra) = o.parse(['-tttqp', 7, '--longoption', '19',
38                                  'hanky', '--onlylong'])
39     WVPASSEQ(flags[0], ('-t', ''))
40     WVPASSEQ(flags[1], ('-t', ''))
41     WVPASSEQ(flags[2], ('-t', ''))
42     WVPASSEQ(flags[3], ('-q', ''))
43     WVPASSEQ(flags[4], ('-p', 7))
44     WVPASSEQ(flags[5], ('--longoption', '19'))
45     WVPASSEQ(extra, ['hanky'])
46     WVPASSEQ((opt.t, opt.q, opt.p, opt.l, opt.onlylong,
47               opt.neveropt), (3,1,7,19,1,None))
48     (opt,flags,extra) = o.parse(['--onlylong', '-t', '--no-onlylong'])
49     WVPASSEQ((opt.t, opt.q, opt.onlylong), (1, None, 0))