summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngus Salkeld <asalkeld@redhat.com>2013-05-18 17:26:38 +1000
committerAngus Salkeld <asalkeld@redhat.com>2013-05-18 17:26:38 +1000
commit6693c9fb04722de9b911fd51a708d70158760178 (patch)
tree76455d78ed5a445b0dede6fd7a3fbdd564e66ba9
parentdea1ceb45aa0d4c6923195925b888491b9d92422 (diff)
downloadceilometer-6693c9fb04722de9b911fd51a708d70158760178.tar.gz
Use fixtures in the tests
TempDir() makes sure all files created under it are deleted at the end of the tests. FakeLogger() hides logs when the test passes and displays logs for failed tests. part of bug 1177924 Change-Id: I07acb66daa1932d7864a5431f1b64570b747ce5a
-rw-r--r--ceilometer/tests/base.py8
-rw-r--r--tests/api/v1/test_app.py3
-rw-r--r--tests/api/v2/test_app.py3
-rw-r--r--tests/test_bin.py17
-rw-r--r--tools/test-requires1
5 files changed, 14 insertions, 18 deletions
diff --git a/ceilometer/tests/base.py b/ceilometer/tests/base.py
index 9263c540..befe9b43 100644
--- a/ceilometer/tests/base.py
+++ b/ceilometer/tests/base.py
@@ -18,8 +18,10 @@
# under the License.
"""Test base classes.
"""
+import fixtures
import mox
from oslo.config import cfg
+import os.path
import stubout
import testtools
@@ -32,6 +34,9 @@ class TestCase(testtools.TestCase):
super(TestCase, self).setUp()
self.mox = mox.Mox()
self.stubs = stubout.StubOutForTesting()
+ self.tempdir = self.useFixture(fixtures.TempDir())
+ self.useFixture(fixtures.FakeLogger())
+
# Set a default location for the pipeline config file so the
# tests work even if ceilometer is not installed globally on
# the system.
@@ -40,6 +45,9 @@ class TestCase(testtools.TestCase):
'../etc/ceilometer/pipeline.yaml',
)
+ def temp_config_file_path(self, name='ceilometer.conf'):
+ return os.path.join(self.tempdir.path, name)
+
def tearDown(self):
self.mox.UnsetStubs()
self.stubs.UnsetAll()
diff --git a/tests/api/v1/test_app.py b/tests/api/v1/test_app.py
index f72b678a..69c908a7 100644
--- a/tests/api/v1/test_app.py
+++ b/tests/api/v1/test_app.py
@@ -18,7 +18,6 @@
"""Test basic ceilometer-api app
"""
import os
-import tempfile
from oslo.config import cfg
@@ -42,7 +41,7 @@ class TestApp(base.TestCase):
self.assertEqual(api_app.wsgi_app.auth_protocol, 'foottp')
def test_keystone_middleware_parse_conffile(self):
- tmpfile = tempfile.mktemp()
+ tmpfile = self.temp_config_file_path()
with open(tmpfile, "w") as f:
f.write("[%s]\nauth_protocol = barttp" % acl.OPT_GROUP_NAME)
f.write("\nauth_version = v2.0")
diff --git a/tests/api/v2/test_app.py b/tests/api/v2/test_app.py
index 908e8401..ede22be9 100644
--- a/tests/api/v2/test_app.py
+++ b/tests/api/v2/test_app.py
@@ -18,7 +18,6 @@
"""Test basic ceilometer-api app
"""
import os
-import tempfile
from oslo.config import cfg
@@ -46,7 +45,7 @@ class TestApp(base.TestCase):
self.assertEqual(api_app.auth_protocol, 'foottp')
def test_keystone_middleware_parse_conffile(self):
- tmpfile = tempfile.mktemp()
+ tmpfile = self.temp_config_file_path()
with open(tmpfile, "w") as f:
f.write("[DEFAULT]\n")
f.write("pipeline_cfg_file = ../etc/ceilometer/pipeline.yaml\n")
diff --git a/tests/test_bin.py b/tests/test_bin.py
index 8e5ae2e2..396b3973 100644
--- a/tests/test_bin.py
+++ b/tests/test_bin.py
@@ -19,11 +19,9 @@
import httplib2
import json
-import os
import random
import socket
import subprocess
-import tempfile
import time
from ceilometer.tests import base
@@ -32,7 +30,7 @@ from ceilometer.tests import base
class BinDbsyncTestCase(base.TestCase):
def setUp(self):
super(BinDbsyncTestCase, self).setUp()
- self.tempfile = tempfile.mktemp()
+ self.tempfile = self.temp_config_file_path()
with open(self.tempfile, 'w') as tmp:
tmp.write("[DEFAULT]\n")
tmp.write("database_connection=log://localhost\n")
@@ -42,15 +40,11 @@ class BinDbsyncTestCase(base.TestCase):
"--config-file=%s" % self.tempfile])
self.assertEqual(subp.wait(), 0)
- def tearDown(self):
- super(BinDbsyncTestCase, self).tearDown()
- os.unlink(self.tempfile)
-
class BinSendCounterTestCase(base.TestCase):
def setUp(self):
super(BinSendCounterTestCase, self).setUp()
- self.tempfile = tempfile.mktemp()
+ self.tempfile = self.temp_config_file_path()
with open(self.tempfile, 'w') as tmp:
tmp.write("[DEFAULT]\n")
tmp.write(
@@ -65,10 +59,6 @@ class BinSendCounterTestCase(base.TestCase):
"--counter-name=mycounter"])
self.assertEqual(subp.wait(), 0)
- def tearDown(self):
- super(BinSendCounterTestCase, self).tearDown()
- os.unlink(self.tempfile)
-
class BinApiTestCase(base.TestCase):
@@ -76,7 +66,7 @@ class BinApiTestCase(base.TestCase):
super(BinApiTestCase, self).setUp()
self.api_port = random.randint(10000, 11000)
self.http = httplib2.Http()
- self.tempfile = tempfile.mktemp()
+ self.tempfile = self.temp_config_file_path()
with open(self.tempfile, 'w') as tmp:
tmp.write("[DEFAULT]\n")
tmp.write(
@@ -95,7 +85,6 @@ class BinApiTestCase(base.TestCase):
def tearDown(self):
super(BinApiTestCase, self).tearDown()
- os.unlink(self.tempfile)
self.subp.kill()
self.subp.wait()
diff --git a/tools/test-requires b/tools/test-requires
index 66a4bb5d..47dfc659 100644
--- a/tools/test-requires
+++ b/tools/test-requires
@@ -2,6 +2,7 @@ nose
coverage
mock
mox
+fixtures>=0.3.12
Babel>=0.9.6
# NOTE(dhellmann): Ming is necessary to provide the Mongo-in-memory
# implementation of MongoDB.