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


Python ConfigFileBackingStore.set方法代码示例

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


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

示例1: test_save_raises_ioerror_when_cant_make_new_file

# 需要导入模块: from ice.persistence.config_file_backing_store import ConfigFileBackingStore [as 别名]
# 或者: from ice.persistence.config_file_backing_store.ConfigFileBackingStore import set [as 别名]
 def test_save_raises_ioerror_when_cant_make_new_file(self):
   temppath = os.path.join(self.tempdir, "extra", "directories", "test.ini")
   cfbs = ConfigFileBackingStore(temppath)
   cfbs.add_identifier("Iron Man")
   cfbs.set("Iron Man", "identity", "Tony Stark")
   with self.assertRaises(IOError):
     cfbs.save()
开发者ID:Christopotamus,项目名称:Ice,代码行数:9,代码来源:config_file_backing_store_tests.py

示例2: test_save_creates_new_file_when_path_originally_dne

# 需要导入模块: from ice.persistence.config_file_backing_store import ConfigFileBackingStore [as 别名]
# 或者: from ice.persistence.config_file_backing_store.ConfigFileBackingStore import set [as 别名]
 def test_save_creates_new_file_when_path_originally_dne(self):
   self.assertFalse(os.path.isfile(self.tempfile))
   cfbs = ConfigFileBackingStore(self.tempfile)
   cfbs.add_identifier("Iron Man")
   cfbs.set("Iron Man", "identity", "Tony Stark")
   cfbs.save()
   self.assertTrue(os.path.isfile(self.tempfile))
开发者ID:Christopotamus,项目名称:Ice,代码行数:9,代码来源:config_file_backing_store_tests.py

示例3: test_raises_ioerror_when_permission_denied

# 需要导入模块: from ice.persistence.config_file_backing_store import ConfigFileBackingStore [as 别名]
# 或者: from ice.persistence.config_file_backing_store.ConfigFileBackingStore import set [as 别名]
 def test_raises_ioerror_when_permission_denied(self):
   self.create_config_file(self.tempfile, {})
   mode = os.stat(self.tempfile)[stat.ST_MODE]
   new_mode = mode & ~stat.S_IWUSR & ~stat.S_IWGRP & ~stat.S_IWOTH
   os.chmod(self.tempfile, new_mode)
   cfbs = ConfigFileBackingStore(self.tempfile)
   cfbs.add_identifier("Iron Man")
   cfbs.set("Iron Man", "identity", "Tony Stark")
   with self.assertRaises(IOError):
     cfbs.save()
开发者ID:Christopotamus,项目名称:Ice,代码行数:12,代码来源:config_file_backing_store_tests.py

示例4: create_backing_store

# 需要导入模块: from ice.persistence.config_file_backing_store import ConfigFileBackingStore [as 别名]
# 或者: from ice.persistence.config_file_backing_store.ConfigFileBackingStore import set [as 别名]
 def create_backing_store(self, data):
   bs = ConfigFileBackingStore(self.tempfile)
   for ident in data.keys():
     bs.add_identifier(ident)
     ident_data = data[ident]
     for key in ident_data.keys():
       value = ident_data[key]
       bs.set(ident, key, value)
   bs.save()
   return bs
开发者ID:fpiesche,项目名称:Ice,代码行数:12,代码来源:backed_object_tests.py

示例5: test_config_file_backing_store_can_read_saved_file

# 需要导入模块: from ice.persistence.config_file_backing_store import ConfigFileBackingStore [as 别名]
# 或者: from ice.persistence.config_file_backing_store.ConfigFileBackingStore import set [as 别名]
 def test_config_file_backing_store_can_read_saved_file(self):
   cfbs = ConfigFileBackingStore(self.tempfile)
   cfbs.add_identifier("Iron Man")
   cfbs.set("Iron Man", "alignment", "good")
   cfbs.add_identifier("Whiplash")
   cfbs.set("Whiplash", "alignment", "evil")
   cfbs.save()
   new_cfbs = ConfigFileBackingStore(self.tempfile)
   self.assertIn("Iron Man", new_cfbs.identifiers())
   self.assertIn("Whiplash", new_cfbs.identifiers())
   self.assertEquals("good", new_cfbs.get("Iron Man", "alignment"))
   self.assertEquals("evil", new_cfbs.get("Whiplash", "alignment"))
开发者ID:Christopotamus,项目名称:Ice,代码行数:14,代码来源:config_file_backing_store_tests.py

示例6: test_save_modifies_contents_of_file

# 需要导入模块: from ice.persistence.config_file_backing_store import ConfigFileBackingStore [as 别名]
# 或者: from ice.persistence.config_file_backing_store.ConfigFileBackingStore import set [as 别名]
 def test_save_modifies_contents_of_file(self):
   self.create_config_file(self.tempfile, {
       "Iron Man": {"identity": "Tony Stark"}
   })
   old_contents = self.file_contents(self.tempfile)
   cfbs = ConfigFileBackingStore(self.tempfile)
   cfbs.set("Iron Man", "alignment", "good")
   cfbs.add_identifier("Whiplash")
   cfbs.set("Whiplash", "alignment", "evil")
   cfbs.save()
   new_contents = self.file_contents(self.tempfile)
   self.assertNotIn("Whiplash", old_contents)
   self.assertIn("Whiplash", new_contents)
   self.assertNotIn("alignment", old_contents)
   self.assertIn("alignment", new_contents)
   self.assertIn("good", new_contents)
   self.assertIn("evil", new_contents)
开发者ID:Christopotamus,项目名称:Ice,代码行数:19,代码来源:config_file_backing_store_tests.py

示例7: test_set_keys_are_case_insensitive

# 需要导入模块: from ice.persistence.config_file_backing_store import ConfigFileBackingStore [as 别名]
# 或者: from ice.persistence.config_file_backing_store.ConfigFileBackingStore import set [as 别名]
 def test_set_keys_are_case_insensitive(self):
   self.create_config_file(self.tempfile, {"Iron Man": {}})
   cfbs = ConfigFileBackingStore(self.tempfile)
   cfbs.set("Iron Man", "identity", "Tony Stark")
   self.assertEqual(cfbs.get("Iron Man", "IDENTITY", ""), "Tony Stark")
开发者ID:Christopotamus,项目名称:Ice,代码行数:7,代码来源:config_file_backing_store_tests.py

示例8: BackedObjectManagerTests

# 需要导入模块: from ice.persistence.config_file_backing_store import ConfigFileBackingStore [as 别名]
# 或者: from ice.persistence.config_file_backing_store.ConfigFileBackingStore import set [as 别名]
class BackedObjectManagerTests(unittest.TestCase):

  def setUp(self):
    self.tempdir = tempfile.mkdtemp()
    self.tempfile = os.path.join(self.tempdir, "test.ini")
    self.backing_store = ConfigFileBackingStore(self.tempfile)
    self.adapter = BackedObjectBackedObjectAdapter()
    self.manager = BackedObjectManager(self.backing_store, self.adapter)

  def tearDown(self):
    shutil.rmtree(self.tempdir)

  def populate_backing_store(self, data):
    for ident in data.keys():
      self.backing_store.add_identifier(ident)
      ident_data = data[ident]
      for key in ident_data.keys():
        value = ident_data[key]
        self.backing_store.set(ident, key, value)
    self.backing_store.save()

  def test_reading_data_from_store(self):
    self.populate_backing_store({
        "Iron Man": {
            "identity": "Tony Stark",
        },
        "War Machine": {
            "identity": "James Rhodes",
            "alias": "Rhodey",
        },
    })
    iron_man = self.manager.find("Iron Man")
    war_machine = self.manager.find("War Machine")

    self.assertIsNotNone(iron_man)
    self.assertEquals(iron_man.identifier, "Iron Man")
    self.assertEquals(iron_man.backed_value("identity"), "Tony Stark")

    self.assertIsNotNone(war_machine)
    self.assertEquals(war_machine.identifier, "War Machine")
    self.assertEquals(war_machine.backed_value("identity"), "James Rhodes")
    self.assertEquals(war_machine.backed_value("alias"), "Rhodey")

  def test_all(self):
    self.populate_backing_store({
        "Iron Man": {},
        "War Machine": {},
    })
    all_objects = self.manager.all()
    self.assertIs(len(all_objects), 2)
    obj1 = all_objects[0]
    obj2 = all_objects[1]
    self.assertFalse(obj1.identifier == obj2.identifier)
    self.assertIn(obj1.identifier, ["Iron Man", "War Machine"])
    self.assertIn(obj2.identifier, ["Iron Man", "War Machine"])

  def test_find_returns_none_with_invalid_identifier(self):
    im = self.manager.find("Iron Man")
    self.assertIsNone(self.manager.find("Iron Man"))

  def test_find_returns_non_none_with_valid_identifier(self):
    self.populate_backing_store({"Iron Man": {}})
    self.assertIsNotNone(self.manager.find("Iron Man"))

  def test_find_returns_same_object_between_calls(self):
    self.populate_backing_store({"Iron Man": {}})
    first_result = self.manager.find("Iron Man")
    self.assertIsNotNone(first_result)
    second_result = self.manager.find("Iron Man")
    self.assertIsNotNone(second_result)
    self.assertIs(first_result, second_result)

  def test_find_after_set_object_for_identifier_returns_same_object_that_was_set(self):
    war_machine = BackedObject(self.backing_store, "War Machine")
    self.manager.set_object_for_identifier(war_machine, "War Machine")
    self.assertEquals(self.manager.find("War Machine"), war_machine)

  def test_all_doesnt_include_objects_where_verification_fails(self):
    self.populate_backing_store({
        "Iron Man":     {},
        "War Machine":  {},
        "Whiplash":     {},
    })
    self.adapter.verifier = lambda obj: obj.identifier.startswith("W")
    identifiers = map(lambda obj: obj.identifier, self.manager.all())
    self.assertEqual(len(identifiers), 2)
    self.assertIn("War Machine", identifiers)
    self.assertIn("Whiplash", identifiers)

  def test_find_returns_none_for_object_where_verification_fails(self):
    self.populate_backing_store({"Iron Man": {}})
    self.adapter.verifier = lambda obj: False
    self.assertIsNone(self.manager.find("Iron Man"))
开发者ID:Christopotamus,项目名称:Ice,代码行数:95,代码来源:backed_object_manager_tests.py


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