diff options
| author | Andy Smith <code@term.ie> | 2010-10-15 22:04:14 +0000 |
|---|---|---|
| committer | Tarmac <> | 2010-10-15 22:04:14 +0000 |
| commit | c0f050c54fad7fd714402b592b97cdc1caf8a8b7 (patch) | |
| tree | fd2817c3bf103b7b620b31ab1dcce191f9f88f51 /nova/tests | |
| parent | 3b34b9f64c2f27cdc6203f8d5571246a92aa4386 (diff) | |
| parent | 8b2d1143f53bb029941a770e2611bb58a064c492 (diff) | |
Fix the --help flag for printing help on twistd-based services
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/flags_unittest.py | 12 | ||||
| -rw-r--r-- | nova/tests/twistd_unittest.py | 53 |
2 files changed, 65 insertions, 0 deletions
diff --git a/nova/tests/flags_unittest.py b/nova/tests/flags_unittest.py index d49d5dc43..714170e5e 100644 --- a/nova/tests/flags_unittest.py +++ b/nova/tests/flags_unittest.py @@ -20,6 +20,8 @@ from nova import exception from nova import flags from nova import test +FLAGS = flags.FLAGS +flags.DEFINE_string('flags_unittest', 'foo', 'for testing purposes only') class FlagsTestCase(test.TrialTestCase): def setUp(self): @@ -85,3 +87,13 @@ class FlagsTestCase(test.TrialTestCase): self.assert_('runtime_answer' in self.global_FLAGS) self.assertEqual(self.global_FLAGS.runtime_answer, 60) + + def test_flag_leak_left(self): + self.assertEqual(FLAGS.flags_unittest, 'foo') + FLAGS.flags_unittest = 'bar' + self.assertEqual(FLAGS.flags_unittest, 'bar') + + def test_flag_leak_right(self): + self.assertEqual(FLAGS.flags_unittest, 'foo') + FLAGS.flags_unittest = 'bar' + self.assertEqual(FLAGS.flags_unittest, 'bar') diff --git a/nova/tests/twistd_unittest.py b/nova/tests/twistd_unittest.py new file mode 100644 index 000000000..75007b9c8 --- /dev/null +++ b/nova/tests/twistd_unittest.py @@ -0,0 +1,53 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import StringIO +import sys + +from nova import twistd +from nova import exception +from nova import flags +from nova import test + + +FLAGS = flags.FLAGS + + +class TwistdTestCase(test.TrialTestCase): + def setUp(self): + super(TwistdTestCase, self).setUp() + self.Options = twistd.WrapTwistedOptions(twistd.TwistdServerOptions) + sys.stdout = StringIO.StringIO() + + def tearDown(self): + super(TwistdTestCase, self).tearDown() + sys.stdout = sys.__stdout__ + + def test_basic(self): + options = self.Options() + argv = options.parseOptions() + + def test_logfile(self): + options = self.Options() + argv = options.parseOptions(['--logfile=foo']) + self.assertEqual(FLAGS.logfile, 'foo') + + def test_help(self): + options = self.Options() + self.assertRaises(SystemExit, options.parseOptions, ['--help']) + self.assert_('pidfile' in sys.stdout.getvalue()) |
