From f302ff1173ba5e452debe0d8d7eecb386ad68693 Mon Sep 17 00:00:00 2001 From: junboli Date: Mon, 8 Jan 2018 12:32:20 +0800 Subject: [PATCH] Remove ordering attempts of 'unorderable types' Python 3 is more strict in ordering container elements and raises errors when attempted to order unorderable types like dicts. So, fix such places and replace them with proper things. Ref: https://review.openstack.org/#/c/210252/ Change-Id: I47f2e61d0721ec2759427dd0be0e22c15b21e1a6 Partially-Implements: bp py3-compatibility --- manila/tests/db/sqlalchemy/test_api.py | 7 +++++-- manila/tests/scheduler/test_host_manager.py | 4 +++- manila/tests/share/test_access.py | 14 ++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/manila/tests/db/sqlalchemy/test_api.py b/manila/tests/db/sqlalchemy/test_api.py index 4e3725a33b..f84c5827c8 100644 --- a/manila/tests/db/sqlalchemy/test_api.py +++ b/manila/tests/db/sqlalchemy/test_api.py @@ -161,8 +161,11 @@ class ShareAccessDatabaseAPITestCase(test.TestCase): share_access_keys_present = True if with_share_access_data else False actual_access_ids = [r['access_id'] for r in rules] - self.assertEqual(sorted([access_1['id'], access_2['id']]), - sorted(actual_access_ids)) + self.assertTrue(isinstance(actual_access_ids, list)) + expected = [access_1['id'], access_2['id']] + self.assertEqual(len(expected), len(actual_access_ids)) + for pool in expected: + self.assertIn(pool, actual_access_ids) for rule in rules: for key in share_access_keys: self.assertEqual(share_access_keys_present, key in rule) diff --git a/manila/tests/scheduler/test_host_manager.py b/manila/tests/scheduler/test_host_manager.py index 6bc2c5b6cc..2eb56f0534 100644 --- a/manila/tests/scheduler/test_host_manager.py +++ b/manila/tests/scheduler/test_host_manager.py @@ -589,8 +589,10 @@ class HostManagerTestCase(test.TestCase): }, }, ] + self.assertTrue(isinstance(res, list)) self.assertEqual(len(expected), len(res)) - self.assertEqual(sorted(expected), sorted(res)) + for pool in expected: + self.assertIn(pool, res) @ddt.data( None, diff --git a/manila/tests/share/test_access.py b/manila/tests/share/test_access.py index 900a9da3af..2c0f8f1447 100644 --- a/manila/tests/share/test_access.py +++ b/manila/tests/share/test_access.py @@ -454,8 +454,11 @@ class ShareInstanceAccessTestCase(test.TestCase): # Asserts self.assertIsNone(retval) self.assertEqual(share_instance_id, call_args[1]['id']) - self.assertEqual(sorted(expected_rules_to_be_on_share), - sorted(access_rules_to_be_on_share)) + self.assertTrue(isinstance(access_rules_to_be_on_share, list)) + self.assertEqual(len(expected_rules_to_be_on_share), + len(access_rules_to_be_on_share)) + for pool in expected_rules_to_be_on_share: + self.assertIn(pool, access_rules_to_be_on_share) self.assertEqual(1, len(call_kwargs['add_rules'])) self.assertEqual(rule_2['id'], call_kwargs['add_rules'][0]['id']) self.assertEqual(1, len(call_kwargs['delete_rules'])) @@ -659,8 +662,11 @@ class ShareInstanceAccessTestCase(test.TestCase): self.assertIsNone(retval) self.assertEqual(instance['id'], call_args[1]['id']) - self.assertEqual(sorted(expected_rules_to_be_on_share), - sorted(access_rules_to_be_on_share)) + self.assertTrue(isinstance(access_rules_to_be_on_share, list)) + self.assertEqual(len(expected_rules_to_be_on_share), + len(access_rules_to_be_on_share)) + for pool in expected_rules_to_be_on_share: + self.assertIn(pool, access_rules_to_be_on_share) self.assertEqual(['ro'] * len(expected_rules_to_be_on_share), access_levels) self.assertEqual(0, len(call_kwargs['add_rules']))