import collections
from mock import patch
import os
import unittest
import shard_util
_EXAMPLE_FETCH_TEST_NAMES_RESPONSE = [
('CacheTestCase', 'testA'),
('CacheTestCase', 'testB'),
('CacheTestCase', 'testC'),
('TabUITestCase', 'testD'),
('TabUITestCase', 'testE'),
('KeyboardTestCase', 'testF'),
('PasswordManagerTestCase', 'testG'),
('ToolBarTestCase', 'testH'),
('PasswordManagerPasswordCheckupDisabledTestCase', 'testI'),
('PasswordManagerPasswordCheckupDisabledTestCase', 'testG'),
]
class TestShardUtil(unittest.TestCase):
"""Test cases for shard_util.py"""
def test_balance_into_sublists_debug(self):
"""Ensure the balancing algorithm works"""
test_cases = [
test_case for (test_case, _) in _EXAMPLE_FETCH_TEST_NAMES_RESPONSE
]
test_counts = collections.Counter(test_cases)
sublists_1 = shard_util.balance_into_sublists(test_counts, 1)
self.assertEqual(len(sublists_1), 1)
self.assertEqual(len(sublists_1[0]), 6)
sublists_3 = shard_util.balance_into_sublists(test_counts, 3)
self.assertEqual(len(sublists_3), 3)
self.assertEqual(
sorted([len(sublists_3[0]),
len(sublists_3[1]),
len(sublists_3[2])]), [2, 2, 2])
if __name__ == '__main__':
unittest.main()