summaryrefslogtreecommitdiffstats
path: root/tests/unit/test_version.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-12-05 21:16:32 +0000
committerGerrit Code Review <review@openstack.org>2012-12-05 21:16:32 +0000
commitea7ced276d2f080718cd89f3a77378cdf24fabf5 (patch)
tree8af04e6b8fb4a8fe952df20ab4dd0fa25a0454ae /tests/unit/test_version.py
parent2f7a7edc41d0e7b663877592aeda14e766a64241 (diff)
parentc67f2881a4bbe5958048610458180c3f9d914964 (diff)
downloadoslo-ea7ced276d2f080718cd89f3a77378cdf24fabf5.tar.gz
oslo-ea7ced276d2f080718cd89f3a77378cdf24fabf5.tar.xz
oslo-ea7ced276d2f080718cd89f3a77378cdf24fabf5.zip
Merge "Fix broken --version command"
Diffstat (limited to 'tests/unit/test_version.py')
-rw-r--r--tests/unit/test_version.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/unit/test_version.py b/tests/unit/test_version.py
new file mode 100644
index 0000000..8e60f51
--- /dev/null
+++ b/tests/unit/test_version.py
@@ -0,0 +1,68 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 Red Hat, Inc.
+#
+# 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 os
+import shutil
+import sys
+import StringIO
+import tempfile
+import unittest
+
+import stubout
+
+from openstack.common.cfg import *
+from openstack.common import version
+
+
+class BaseTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.stubs = stubout.StubOutForTesting()
+
+ def tearDown(self):
+ self.stubs.UnsetAll()
+
+
+class DeferredVersionTestCase(BaseTestCase):
+
+ def setUp(self):
+ super(DeferredVersionTestCase, self).setUp()
+ self.conf = ConfigOpts()
+
+ def test_deferred_version(self):
+ class MyVersionInfo(version.VersionInfo):
+ def _generate_version(self):
+ return "5.5.5.5"
+
+ deferred_string = MyVersionInfo("openstack").\
+ deferred_version_string()
+ self.conf([], project="project", prog="prog", version=deferred_string)
+ self.assertEquals("5.5.5.5", str(self.conf.version))
+
+ def test_print_deferred_version(self):
+ class MyVersionInfo(version.VersionInfo):
+ def _generate_version(self):
+ return "5.5.5.5"
+
+ deferred_string = MyVersionInfo("openstack")\
+ .deferred_version_string()
+ self.stubs.Set(sys, 'stderr', StringIO.StringIO())
+ self.assertRaises(SystemExit,
+ self.conf, ['--version'],
+ project="project",
+ prog="prog",
+ version=deferred_string)
+ self.assertEquals("5.5.5.5", sys.stderr.getvalue().strip())