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