Fix more tests on Python 3

* Fix test_get_connection: max_bytes and backup_count parameters of the
  logging module must be int, not None.
* Fix test_query on Python 3: ast.literal_eval("1+1") now returns 2 on
  Python 3, whereas it raises a ValueError on Python 2. Use a string
  invalid in Python 2 and Python 3 based on the original bug report
  #1221736
* test_swift: fix url_for() mock, it now returns a string for the
  endpoint
* storage.test_get_connection: skip test_three_urls_no_default()
  if the happybase module is missing (it's not compatible with Python 3
  yet)

Enable more tests on Python 3.4:

*  ceilometer.tests.api.v2.test_query
*  ceilometer.tests.dispatcher.test_db
*  ceilometer.tests.dispatcher.test_file
*  ceilometer.tests.dispatcher.test_http
*  ceilometer.tests.objectstore.test_swift
*  ceilometer.tests.storage.test_get_connection

Change-Id: I1d9bdd73bd21ec5dc8ee9823352f6dfe818b8d6b
This commit is contained in:
Victor Stinner
2015-05-28 00:47:50 +02:00
parent b56b252d44
commit b47c2cd85e
5 changed files with 14 additions and 6 deletions

View File

@@ -124,8 +124,8 @@ class TestQuery(base.BaseTestCase):
# bug 1221736
query = v2_base.Query(field='should_be_a_string',
op='eq',
value='123-1')
expected = '123-1'
value='WWW-Layer-4a80714f')
expected = 'WWW-Layer-4a80714f'
self.assertEqual(expected, query._get_value_as_type())
def test_get_value_as_type_boolean_expression_without_type(self):

View File

@@ -67,8 +67,8 @@ class TestDispatcherFile(base.BaseTestCase):
tf.close()
self.CONF.dispatcher_file.file_path = filename
self.CONF.dispatcher_file.max_bytes = None
self.CONF.dispatcher_file.backup_count = None
self.CONF.dispatcher_file.max_bytes = 0
self.CONF.dispatcher_file.backup_count = 0
dispatcher = file.FileDispatcher(self.CONF)
# The number of the handlers should be 1

View File

@@ -189,7 +189,8 @@ class TestSwiftPollster(testscenarios.testcase.WithScenarios,
self.assertEqual(expected, mock_method.call_args_list)
def test_get_endpoint_only_once(self):
mock_url_for = mock.MagicMock()
endpoint = 'end://point/'
mock_url_for = mock.MagicMock(return_value=endpoint)
api_method = '%s_account' % self.pollster.METHOD
with mockpatch.PatchObject(swift_client, api_method,
new=mock.MagicMock()):

View File

@@ -90,7 +90,7 @@ class ConnectionConfigTest(base.BaseTestCase):
conn = storage.get_connection_from_config(self.CONF, 'alarm')
self.assertIsInstance(conn, impl_sqlalchemy_alarm.Connection)
@unittest.skipIf(impl_hbase_event is None, 'need hbase implementation')
@unittest.skipUnless(impl_hbase_event, 'need hbase implementation')
def test_three_urls(self):
self.CONF.set_override("connection", "log://", group="database")
self.CONF.set_override("alarm_connection", "sqlite://",
@@ -106,6 +106,7 @@ class ConnectionConfigTest(base.BaseTestCase):
conn = storage.get_connection_from_config(self.CONF, 'event')
self.assertIsInstance(conn, impl_hbase_event.Connection)
@unittest.skipUnless(impl_hbase_event, 'need hbase implementation')
def test_three_urls_no_default(self):
self.CONF.set_override("connection", None, group="database")
self.CONF.set_override("metering_connection", "log://",

View File

@@ -49,9 +49,13 @@ commands =
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements-py3.txt
commands = python -m testtools.run \
ceilometer.tests.api.v2.test_query \
ceilometer.tests.compute.virt.libvirt.test_inspector \
ceilometer.tests.compute.virt.vmware.test_vsphere_operations \
ceilometer.tests.data_processing.test_notifications \
ceilometer.tests.dispatcher.test_db \
ceilometer.tests.dispatcher.test_file \
ceilometer.tests.dispatcher.test_http \
ceilometer.tests.energy.test_kwapi \
ceilometer.tests.network.services.test_fwaas \
ceilometer.tests.network.services.test_lbaas \
@@ -59,6 +63,7 @@ commands = python -m testtools.run \
ceilometer.tests.network.test_floatingip \
ceilometer.tests.network.test_notifications \
ceilometer.tests.objectstore.test_swift_middleware \
ceilometer.tests.objectstore.test_swift \
ceilometer.tests.orchestration.test_notifications \
ceilometer.tests.profiler.test_notifications \
ceilometer.tests.publisher.test_direct \
@@ -66,6 +71,7 @@ commands = python -m testtools.run \
ceilometer.tests.publisher.test_kafka_broker_publisher \
ceilometer.tests.publisher.test_messaging_publisher \
ceilometer.tests.publisher.test_utils \
ceilometer.tests.storage.test_get_connection \
ceilometer.tests.storage.test_impl_sqlalchemy \
ceilometer.tests.test_bin \
ceilometer.tests.test_collector \