]> arthur.barton.de Git - bup.git/blob - lib/bup/t/toptions.py
Use absolute_import from the __future__ everywhere
[bup.git] / lib / bup / t / toptions.py
1
2 from __future__ import absolute_import
3
4 from wvtest import *
5
6 from bup import options
7 from buptest import no_lingering_errors
8
9
10 @wvtest
11 def test_optdict():
12     with no_lingering_errors():
13         d = options.OptDict({
14             'x': ('x', False),
15             'y': ('y', False),
16             'z': ('z', False),
17             'other_thing': ('other_thing', False),
18             'no_other_thing': ('other_thing', True),
19             'no_z': ('z', True),
20             'no_smart': ('smart', True),
21             'smart': ('smart', False),
22             'stupid': ('smart', True),
23             'no_smart': ('smart', False),
24         })
25         WVPASS('foo')
26         d['x'] = 5
27         d['y'] = 4
28         d['z'] = 99
29         d['no_other_thing'] = 5
30         WVPASSEQ(d.x, 5)
31         WVPASSEQ(d.y, 4)
32         WVPASSEQ(d.z, 99)
33         WVPASSEQ(d.no_z, False)
34         WVPASSEQ(d.no_other_thing, True)
35         WVEXCEPT(KeyError, lambda: d.p)
36
37
38 invalid_optspec0 = """
39 """
40
41
42 invalid_optspec1 = """
43 prog <whatever>
44 """
45
46
47 invalid_optspec2 = """
48 --
49 x,y
50 """
51
52
53 @wvtest
54 def test_invalid_optspec():
55     with no_lingering_errors():
56         WVPASS(options.Options(invalid_optspec0).parse([]))
57         WVPASS(options.Options(invalid_optspec1).parse([]))
58         WVPASS(options.Options(invalid_optspec2).parse([]))
59
60
61 optspec = """
62 prog <optionset> [stuff...]
63 prog [-t] <boggle>
64 --
65 t       test
66 q,quiet   quiet
67 l,longoption=   long option with parameters and a really really long description that will require wrapping
68 p= short option with parameters
69 onlylong  long option with no short
70 neveropt never called options
71 deftest1=  a default option with default [1]
72 deftest2=  a default option with [1] default [2]
73 deftest3=  a default option with [3] no actual default
74 deftest4=  a default option with [[square]]
75 deftest5=  a default option with "correct" [[square]
76 s,smart,no-stupid  disable stupidity
77 x,extended,no-simple   extended mode [2]
78 #,compress=  set compression level [5]
79 """
80
81 @wvtest
82 def test_options():
83     with no_lingering_errors():
84         o = options.Options(optspec)
85         (opt,flags,extra) = o.parse(['-tttqp', 7, '--longoption', '19',
86                                      'hanky', '--onlylong', '-7'])
87         WVPASSEQ(flags[0], ('-t', ''))
88         WVPASSEQ(flags[1], ('-t', ''))
89         WVPASSEQ(flags[2], ('-t', ''))
90         WVPASSEQ(flags[3], ('-q', ''))
91         WVPASSEQ(flags[4], ('-p', 7))
92         WVPASSEQ(flags[5], ('--longoption', '19'))
93         WVPASSEQ(extra, ['hanky'])
94         WVPASSEQ((opt.t, opt.q, opt.p, opt.l, opt.onlylong,
95                   opt.neveropt), (3,1,7,19,1,None))
96         WVPASSEQ((opt.deftest1, opt.deftest2, opt.deftest3, opt.deftest4,
97                   opt.deftest5), (1,2,None,None,'[square'))
98         WVPASSEQ((opt.stupid, opt.no_stupid), (True, None))
99         WVPASSEQ((opt.smart, opt.no_smart), (None, True))
100         WVPASSEQ((opt.x, opt.extended, opt.no_simple), (2,2,2))
101         WVPASSEQ((opt.no_x, opt.no_extended, opt.simple), (False,False,False))
102         WVPASSEQ(opt['#'], 7)
103         WVPASSEQ(opt.compress, 7)
104
105         (opt,flags,extra) = o.parse(['--onlylong', '-t', '--no-onlylong',
106                                      '--smart', '--simple'])
107         WVPASSEQ((opt.t, opt.q, opt.onlylong), (1, None, 0))
108         WVPASSEQ((opt.stupid, opt.no_stupid), (False, True))
109         WVPASSEQ((opt.smart, opt.no_smart), (True, False))
110         WVPASSEQ((opt.x, opt.extended, opt.no_simple), (0,0,0))
111         WVPASSEQ((opt.no_x, opt.no_extended, opt.simple), (True,True,True))