Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: tools/telemetry/catapult_base/dependency_manager/dependency_manager_unittest.py

Issue 1391403003: Add priority groups to local paths in the dependency manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 import stat 6 import stat
7 import unittest 7 import unittest
8 8
9 import mock 9 import mock
10 10
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 self.assertEqual('dep_info2d', dep_manager._GetDependencyInfo( 633 self.assertEqual('dep_info2d', dep_manager._GetDependencyInfo(
634 'dep2', 'missing_plat')) 634 'dep2', 'missing_plat'))
635 # Dependency and platform in the dependency manager. A default exists. 635 # Dependency and platform in the dependency manager. A default exists.
636 self.assertEqual('dep_info23', dep_manager._GetDependencyInfo( 636 self.assertEqual('dep_info23', dep_manager._GetDependencyInfo(
637 'dep2', 'plat3')) 637 'dep2', 'plat3'))
638 # Dependency and platform in the dependency manager. No default exists. 638 # Dependency and platform in the dependency manager. No default exists.
639 self.assertEqual('dep_info12', dep_manager._GetDependencyInfo( 639 self.assertEqual('dep_info12', dep_manager._GetDependencyInfo(
640 'dep1', 'plat2')) 640 'dep1', 'plat2'))
641 641
642 642
643 @mock.patch('os.path.exists')
644 def testLocalPathHelper(self, exists_mock):
645 dep_info = mock.MagicMock(spec=dependency_manager.DependencyInfo)
646 643
644 class TestLocalPath(fake_filesystem_unittest.TestCase):
645 def setUp(self):
646 self.setUpPyfakefs()
647 self.config_path = '/bar/test/dep_config.json'
648 # local_path0 doesn't exist locally.
649 self.local_path0 = '/foo/local_path0'
650 # local_path[1-4] exist locally and have been modified in increasing order.
651 self.local_path1 = '/foo/local_path1'
652 self.local_path2 = '/bar/local_path2'
653 self.local_path3 = '/baz/local_path3'
654 self.local_path4 = '/foo/local_path4'
655 self.fs.CreateFile(self.config_path, contents='{}')
656 file1 = self.fs.CreateFile(self.local_path1, contents='1010110',
657 st_mode=stat.S_IWOTH)
658 file2 = self.fs.CreateFile(self.local_path2, contents='1010110',
659 st_mode=stat.S_IWOTH)
660 file3 = self.fs.CreateFile(self.local_path3, contents='1010110',
661 st_mode=stat.S_IWOTH)
662 file4 = self.fs.CreateFile(self.local_path4, contents='1010110',
663 st_mode=stat.S_IWOTH)
664 file2.SetMTime(file1.st_mtime + 1)
665 file3.SetMTime(file1.st_mtime + 2)
666 file4.SetMTime(file1.st_mtime + 3)
667
668 def testLocalPathHelper(self):
647 # There is no local path for the given dependency. 669 # There is no local path for the given dependency.
eakuefner 2015/10/09 16:29:17 Can you put each of these cases into a separate un
648 dep_info.local_paths = {} 670 dep_info = dependency_manager.DependencyInfo('dep', 'plat', 'config')
671 self.assertFalse(dependency_manager.DependencyManager._LocalPath(dep_info))
672
673 # There is a local path for the given dependency, but it doesn't exist.
674 dep_info = dependency_manager.DependencyInfo(
675 'dep', 'plat', 'config', local_paths=[self.local_path0])
649 self.assertEqual(None, 676 self.assertEqual(None,
650 dependency_manager.DependencyManager._LocalPath(dep_info)) 677 dependency_manager.DependencyManager._LocalPath(dep_info))
651 678
652 # There is a local path for the given dependency, but it doesn't exist. 679 # There is a local path for the given dependency, and it does exist.
653 exists_mock.side_effect = [False] 680 dep_info = dependency_manager.DependencyInfo(
654 dep_info.local_paths = {'local_path0'} 681 'dep', 'plat', 'config', local_paths=[self.local_path1])
655 self.assertEqual(None, 682 self.assertEqual(self.local_path1,
656 dependency_manager.DependencyManager._LocalPath(dep_info)) 683 dependency_manager.DependencyManager._LocalPath(dep_info))
657 exists_mock.assert_called_once_with('local_path0')
658 exists_mock.reset_mock()
659
660 # There is a local path for the given dependency, and it does exist.
661 exists_mock.side_effect = [True]
662 dep_info.local_paths = {'local_path0'}
663 self.assertEqual('local_path0',
664 dependency_manager.DependencyManager._LocalPath(dep_info))
665 exists_mock.assert_called_once_with('local_path0')
666 exists_mock.reset_mock()
667 684
668 # There are multiple local paths for the given dependency, and the first one 685 # There are multiple local paths for the given dependency, and the first one
669 # exists. 686 # exists.
670 exists_mock.side_effect = [True] 687 local_paths = [self.local_path1, self.local_path2, self.local_path3]
671 dep_info.local_paths = {'local_path0', 'local_path1', 'local_path2'} 688 dep_info = dependency_manager.DependencyInfo(
672 self.assertEqual('local_path0', 689 'dep', 'plat', 'config', local_paths=local_paths)
690 self.assertEqual(self.local_path1,
673 dependency_manager.DependencyManager._LocalPath(dep_info)) 691 dependency_manager.DependencyManager._LocalPath(dep_info))
674 exists_mock.assert_called_once_with('local_path0')
675 exists_mock.reset_mock()
676 692
677 # There are multiple local paths for the given dependency, and the first one 693 # There are multiple local paths for the given dependency, and the first one
678 # doesn't exist but the second one does. 694 # doesn't exist but the second and third do, created in order.
679 exists_mock.side_effect = [False, True] 695 local_paths = [self.local_path0, self.local_path1, self.local_path2]
680 dep_info.local_paths = {'local_path0', 'local_path1', 'local_path2'} 696 dep_info = dependency_manager.DependencyInfo(
681 self.assertEqual('local_path1', 697 'dep', 'plat', 'config', local_paths=local_paths)
698 self.assertEqual(self.local_path1,
682 dependency_manager.DependencyManager._LocalPath(dep_info)) 699 dependency_manager.DependencyManager._LocalPath(dep_info))
683 expected_calls = [mock.call('local_path0'), mock.call('local_path1')] 700
684 exists_mock.assert_has_calls(expected_calls, any_order=False) 701 # There are multiple local paths for the given dependency, and the first one
685 exists_mock.reset_mock() 702 # doesn't exist but the second and third do, created in reverse order.
703 local_paths = [self.local_path0, self.local_path3, self.local_path2,
704 self.local_path1]
705 dep_info = dependency_manager.DependencyInfo(
706 'dep', 'plat', 'config', local_paths=local_paths)
707 self.assertEqual(self.local_path3,
708 dependency_manager.DependencyManager._LocalPath(dep_info))
686 709
687 # There are multiple local paths for the given dependency, and the first and 710 # There are multiple local paths for the given dependency, and the first and
688 # second ones don't exist but the third one does. 711 # second ones don't exist but the third one does.
689 exists_mock.side_effect = [False, False, True] 712 local_paths = ['/nope/local_path0', '/nope/local_path1', self.local_path2]
690 dep_info.local_paths = {'local_path0', 'local_path1', 'local_path2'} 713 dep_info = dependency_manager.DependencyInfo(
691 self.assertEqual('local_path2', 714 'dep', 'plat', 'config', local_paths=local_paths)
715 self.assertEqual(self.local_path2,
692 dependency_manager.DependencyManager._LocalPath(dep_info)) 716 dependency_manager.DependencyManager._LocalPath(dep_info))
693 expected_calls = [mock.call('local_path0'), mock.call('local_path1'),
694 mock.call('local_path2')]
695 exists_mock.assert_has_calls(expected_calls, any_order=False)
696 exists_mock.reset_mock()
697 717
698 # There are multiple local paths for the given dependency, but none of them 718 # There are multiple local paths for the given dependency, but none of them
699 # exist. 719 # exist.
700 exists_mock.side_effect = [False, False, False] 720 local_paths = ['/nope/local_path0', '/nope/local_path1',
701 dep_info.local_paths = {'local_path0', 'local_path1', 'local_path2'} 721 '/nope/local_path2']
722 dep_info = dependency_manager.DependencyInfo(
723 'dep', 'plat', 'config', local_paths=local_paths)
702 self.assertEqual(None, 724 self.assertEqual(None,
703 dependency_manager.DependencyManager._LocalPath(dep_info)) 725 dependency_manager.DependencyManager._LocalPath(dep_info))
704 expected_calls = [mock.call('local_path0'), mock.call('local_path1'), 726
705 mock.call('local_path2')] 727 def testLocalPathHelperWithPriorityGroups(self):
706 exists_mock.assert_has_calls(expected_calls, any_order=False) 728 # There is a local path in a priority group for the given dependency, but it
707 exists_mock.reset_mock() 729 # doesn't exist.
730 dep_info = dependency_manager.DependencyInfo(
731 'dep', 'plat', 'config', local_paths=[[self.local_path0]])
732 self.assertEqual(None,
733 dependency_manager.DependencyManager._LocalPath(dep_info))
734
735 # There is a local path in a priority group for the given dependency, and it
736 # does exist.
737 dep_info = dependency_manager.DependencyInfo(
738 'dep', 'plat', 'config', local_paths=[[self.local_path1]])
739 self.assertEqual(self.local_path1,
740 dependency_manager.DependencyManager._LocalPath(dep_info))
741
742 local_paths = [self.local_path1, [self.local_path2, self.local_path3]]
743 dep_info = dependency_manager.DependencyInfo(
744 'dep', 'plat', 'config', local_paths=local_paths)
745 self.assertEqual(self.local_path1,
746 dependency_manager.DependencyManager._LocalPath(dep_info))
747
748 local_paths = [self.local_path0, [self.local_path2, self.local_path3]]
749 dep_info = dependency_manager.DependencyInfo(
750 'dep', 'plat', 'config', local_paths=local_paths)
751 self.assertEqual(self.local_path3,
752 dependency_manager.DependencyManager._LocalPath(dep_info))
753
754 local_paths = [[self.local_path1, self.local_path2], self.local_path3]
755 dep_info = dependency_manager.DependencyInfo(
756 'dep', 'plat', 'config', local_paths=local_paths)
757 self.assertEqual(self.local_path2,
758 dependency_manager.DependencyManager._LocalPath(dep_info))
759
760 local_paths = [[self.local_path2, self.local_path1, self.local_path4],
761 self.local_path3]
762 dep_info = dependency_manager.DependencyInfo(
763 'dep', 'plat', 'config', local_paths=local_paths)
764 self.assertEqual(self.local_path4,
765 dependency_manager.DependencyManager._LocalPath(dep_info))
766
767 local_paths = ['/nope/local_path0', ['/nope/local_path1', self.local_path2],
768 self.local_path3]
769 dep_info = dependency_manager.DependencyInfo(
770 'dep', 'plat', 'config', local_paths=local_paths)
771 self.assertEqual(self.local_path2,
772 dependency_manager.DependencyManager._LocalPath(dep_info))
773
774 local_paths = [['/nope/local_path0', '/nope/local_path1'], self.local_path2]
775 dep_info = dependency_manager.DependencyInfo(
776 'dep', 'plat', 'config', local_paths=local_paths)
777 self.assertEqual(self.local_path2,
778 dependency_manager.DependencyManager._LocalPath(dep_info))
779
780 local_paths = [['/nope/local_path0', '/nope/local_path1'],
781 '/nope/local_path2']
782 dep_info = dependency_manager.DependencyInfo(
783 'dep', 'plat', 'config', local_paths=local_paths)
784 self.assertEqual(None,
785 dependency_manager.DependencyManager._LocalPath(dep_info))
708 786
709 787
710 class TestCloudStoragePath(fake_filesystem_unittest.TestCase): 788 class TestCloudStoragePath(fake_filesystem_unittest.TestCase):
711 def setUp(self): 789 def setUp(self):
712 self.setUpPyfakefs() 790 self.setUpPyfakefs()
713 self.config_path = '/test/dep_config.json' 791 self.config_path = '/test/dep_config.json'
714 self.fs.CreateFile(self.config_path, contents='{}') 792 self.fs.CreateFile(self.config_path, contents='{}')
715 self.download_path = '/foo/download_path' 793 self.download_path = '/foo/download_path'
716 self.fs.CreateFile( 794 self.fs.CreateFile(
717 self.download_path, contents='1010110', st_mode=stat.S_IWOTH) 795 self.download_path, contents='1010110', st_mode=stat.S_IWOTH)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 853
776 cs_get_mock.side_effect = cloud_storage.PermissionError 854 cs_get_mock.side_effect = cloud_storage.PermissionError
777 self.assertRaises( 855 self.assertRaises(
778 cloud_storage.PermissionError, 856 cloud_storage.PermissionError,
779 dependency_manager.DependencyManager._CloudStoragePath, self.dep_info) 857 dependency_manager.DependencyManager._CloudStoragePath, self.dep_info)
780 858
781 cs_get_mock.side_effect = cloud_storage.CredentialsError 859 cs_get_mock.side_effect = cloud_storage.CredentialsError
782 self.assertRaises( 860 self.assertRaises(
783 cloud_storage.CredentialsError, 861 cloud_storage.CredentialsError,
784 dependency_manager.DependencyManager._CloudStoragePath, self.dep_info) 862 dependency_manager.DependencyManager._CloudStoragePath, self.dep_info)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698