本文整理匯總了Python中freeseer.framework.config.profile.ProfileManager.list_profiles方法的典型用法代碼示例。如果您正苦於以下問題:Python ProfileManager.list_profiles方法的具體用法?Python ProfileManager.list_profiles怎麽用?Python ProfileManager.list_profiles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類freeseer.framework.config.profile.ProfileManager
的用法示例。
在下文中一共展示了ProfileManager.list_profiles方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestProfileManager
# 需要導入模塊: from freeseer.framework.config.profile import ProfileManager [as 別名]
# 或者: from freeseer.framework.config.profile.ProfileManager import list_profiles [as 別名]
class TestProfileManager(unittest.TestCase):
"""Tests the ProfileManager."""
def setUp(self):
self.profiles_path = tempfile.mkdtemp()
self.profile_manager = ProfileManager(self.profiles_path)
def tearDown(self):
shutil.rmtree(self.profiles_path)
def test_get(self):
"""Tests that get returns a Profile instance."""
profile = self.profile_manager.get('testing')
self.assertIsInstance(profile, Profile)
def test_get_non_existent(self):
"""Test for non-existent profile."""
self.assertRaises(ProfileDoesNotExist, self.profile_manager.get, 'non-existent_profile', create_if_needed=False)
def test_get_non_existent_creates(self):
"""Test that get creates non-existent profile if create_if_needed=True."""
self.assertRaises(ProfileDoesNotExist, self.profile_manager.get, 'non-existent_profile', create_if_needed=False)
profile = self.profile_manager.get('non_existent_profile')
self.assertIsInstance(profile, Profile)
def test_get_cache(self):
"""Tests that get caching is working as expected."""
profile1 = self.profile_manager.get('testing')
profile2 = self.profile_manager.get('testing')
self.assertEqual(profile1, profile2)
def test_list_profiles(self):
"""Tests that list_profiles returns all profiles on file."""
self.profile_manager.create('testing1')
self.profile_manager.create('testing2')
profiles = self.profile_manager.list_profiles()
self.assertItemsEqual(['testing1', 'testing2'], profiles)
def test_create_profile(self):
"""Tests that create_profile returns an instance of Profile.."""
profile = self.profile_manager.create('testing1')
self.assertIsInstance(profile, Profile)
def test_create_profile_existing(self):
"""Tests that exception is raised if trying to overwrite existing profile."""
self.profile_manager.create('testing1')
self.assertRaises(ProfileAlreadyExists, self.profile_manager.create, 'testing1')
def test_create_profile_caches(self):
"""Tests that create_profile adds the new Profile instance to cache."""
self.assertNotIn('testing1', self.profile_manager._cache)
self.profile_manager.create('testing1')
self.assertIn('testing1', self.profile_manager._cache)
def test_delete_profile_existing(self):
"""Tests that delete_profile deletes the profile from cache and file."""
self.profile_manager.create('testing1')
self.profile_manager.delete('testing1')
self.assertRaises(ProfileDoesNotExist, self.profile_manager.get, 'testing1', create_if_needed=False)
def test_delete_profile_non_existing(self):
"""Non-existent profiles can't be deleted."""
self.assertRaises(ProfileDoesNotExist, self.profile_manager.delete, 'testing')