当前位置: 首页>>代码示例>>Python>>正文


Python ProfileManager.delete方法代码示例

本文整理汇总了Python中freeseer.framework.config.profile.ProfileManager.delete方法的典型用法代码示例。如果您正苦于以下问题:Python ProfileManager.delete方法的具体用法?Python ProfileManager.delete怎么用?Python ProfileManager.delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在freeseer.framework.config.profile.ProfileManager的用法示例。


在下文中一共展示了ProfileManager.delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestProfileManager

# 需要导入模块: from freeseer.framework.config.profile import ProfileManager [as 别名]
# 或者: from freeseer.framework.config.profile.ProfileManager import delete [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')
开发者ID:Blakstar26,项目名称:freeseer,代码行数:65,代码来源:test_profile.py


注:本文中的freeseer.framework.config.profile.ProfileManager.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。