From c4363aa6eaa2a5ea8e7dc686291591536a46bc19 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Tue, 29 Jan 2019 03:19:35 +0100 Subject: [PATCH] Python3: Fix test/unit/common/test_container_sync_realms.py Change-Id: I9bb6e55691821891172d375d0bf097148d66010d --- swift/common/container_sync_realms.py | 4 ++-- test/unit/common/test_container_sync_realms.py | 17 +++++++++++++---- tox.ini | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/swift/common/container_sync_realms.py b/swift/common/container_sync_realms.py index b10758b8bd..fc0bee8f1c 100644 --- a/swift/common/container_sync_realms.py +++ b/swift/common/container_sync_realms.py @@ -101,7 +101,7 @@ class ContainerSyncRealms(object): def realms(self): """Returns a list of realms.""" self._reload() - return self.data.keys() + return list(self.data.keys()) def key(self, realm): """Returns the key for the realm.""" @@ -126,7 +126,7 @@ class ContainerSyncRealms(object): if result: result = result.get('clusters') if result: - result = result.keys() + result = list(result.keys()) return result or [] def endpoint(self, realm, cluster): diff --git a/test/unit/common/test_container_sync_realms.py b/test/unit/common/test_container_sync_realms.py index ae487c259b..f1c5127ade 100644 --- a/test/unit/common/test_container_sync_realms.py +++ b/test/unit/common/test_container_sync_realms.py @@ -18,6 +18,8 @@ import os import unittest import uuid +import six + from mock import patch from swift.common.container_sync_realms import ContainerSyncRealms from test.unit import FakeLogger, temptree @@ -77,12 +79,19 @@ class TestUtils(unittest.TestCase): logger = FakeLogger() fpath = os.path.join(tempdir, fname) csr = ContainerSyncRealms(fpath, logger) + if six.PY2: + fmt = "Could not load '%s': " \ + "File contains no section headers.\n" \ + "file: %s, line: 1\n" \ + "'invalid'" + else: + fmt = "Could not load '%s': " \ + "File contains no section headers.\n" \ + "file: '%s', line: 1\n" \ + "'invalid'" self.assertEqual( logger.all_log_lines(), - {'error': [ - "Could not load '%s': File contains no section headers.\n" - "file: %s, line: 1\n" - "'invalid'" % (fpath, fpath)]}) + {'error': [fmt % (fpath, fpath)]}) self.assertEqual(csr.mtime_check_interval, 300) self.assertEqual(csr.realms(), []) diff --git a/tox.ini b/tox.ini index 6b4fef2397..7cebc03537 100644 --- a/tox.ini +++ b/tox.ini @@ -65,6 +65,7 @@ commands = test/unit/common/test_base_storage_server.py \ test/unit/common/test_bufferedhttp.py \ test/unit/common/test_constraints.py \ + test/unit/common/test_container_sync_realms.py \ test/unit/common/test_daemon.py \ test/unit/common/test_db.py \ test/unit/common/test_db_replicator.py \