/
test_options.py
47 lines (37 loc) · 1.2 KB
/
test_options.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
"""
Test basic command-line handling of the Plugin class.
"""
import sys
from nose import with_setup
from NagAconda import Plugin
from test import PlugTest
from optparse import OptionError
class TestOptions(PlugTest):
"""
Test optparse integration with the Plugin class.
Since our class did not actually extend OptionParser or Option, there's
a chance something we did damaged the environment. This class ensures
basic functionality still exists.
"""
def test_required(self):
"""
Test that required options are actually required.
"""
self.plugin.add_option("t", "test", "Test required parameter",
required=True)
try:
self.plugin.start()
except SystemExit as e:
print(dir(e))
assert True
else:
assert False
def test_parameter(self):
"""
Test that a specified parameter actually reaches our option list.
"""
self.plugin.add_option("t", "test", "Test required parameter",
required=True)
sys.argv.extend(['-t', 'this.is.a.test'])
self.plugin.start()
assert self.plugin.options.test == 'this.is.a.test'