本文整理汇总了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')