Commit d39787aa authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[trac610] added tests for --csv-file-dir

For testing purpose I also renamed bindctl-source.py to bindctl_main.py.
I needed to replace dash with underscore to use it in an import statement,
and _main seemed to better explain what it is than _source, so I also
renamed that part.
parent 86d0ba90
......@@ -723,7 +723,7 @@ AC_OUTPUT([doc/version.ent
src/bin/bind10/tests/bind10_test.py
src/bin/bind10/run_bind10.sh
src/bin/bindctl/run_bindctl.sh
src/bin/bindctl/bindctl-source.py
src/bin/bindctl/bindctl_main.py
src/bin/bindctl/tests/bindctl_test
src/bin/loadzone/run_loadzone.sh
src/bin/loadzone/tests/correct/correct_test.sh
......
......@@ -19,8 +19,8 @@ bindctl.1: bindctl.xml
endif
bindctl: bindctl-source.py
bindctl: bindctl_main.py
$(SED) -e "s|@@PYTHONPATH@@|@pyexecdir@|" \
-e "s|@@SYSCONFDIR@@|@sysconfdir@|" \
-e "s|@@LIBEXECDIR@@|$(pkglibexecdir)|" bindctl-source.py >$@
-e "s|@@LIBEXECDIR@@|$(pkglibexecdir)|" bindctl_main.py >$@
chmod a+x $@
......@@ -19,8 +19,10 @@ import isc.cc.data
import os
import pwd
import getpass
from optparse import OptionParser
from isc.config.config_data import ConfigData, MultiConfigData
from isc.config.module_spec import ModuleSpec
from bindctl.bindctl_source import set_bindctl_options
from bindctl import cmdparse
from bindctl import bindcmd
from bindctl.moduleinfo import *
......@@ -368,6 +370,40 @@ class TestBindCmdInterpreter(unittest.TestCase):
self.assertEqual([], users)
os.remove(csvfilename)
class TestCommandLineOptions(unittest.TestCase):
class FakeParserError(Exception):
"""An exception thrown from FakeOptionParser on parser error.
"""
pass
class FakeOptionParser(OptionParser):
"""This fake class emulates the OptionParser class with customized
error handling for the convenient of tests.
"""
def __init__(self):
OptionParser.__init__(self)
def error(self, msg):
raise TestCommandLineOptions.FakeParserError
def setUp(self):
self.parser = self.FakeOptionParser()
set_bindctl_options(self.parser)
def test_csv_file_dir(self):
# by default the option is "undefined"
(options, _) = self.parser.parse_args([])
self.assertEqual(None, options.csv_file_dir)
# specify the option, valid case.
(options, _) = self.parser.parse_args(['--csv-file-dir', 'some_dir'])
self.assertEqual('some_dir', options.csv_file_dir)
# missing option arg; should trigger parser error.
self.assertRaises(self.FakeParserError, self.parser.parse_args,
['--csv-file-dir'])
if __name__== "__main__":
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment