Пример #1
0
  def testCannotOpenBogusPath(self):
    path = TempDir() + "/does not exist/ring"
    with self.assertRaises(IOError):
      Ringfile.create(path, 1000)

    with self.assertRaises(IOError):
      Ringfile(path, MODE_READ)

    with self.assertRaises(IOError):
      Ringfile(path, MODE_APPEND)

    path = TempDir() + "/ring"
    with self.assertRaises(IOError):
      Ringfile(path, MODE_READ)
    with self.assertRaises(IOError):
      Ringfile(path, MODE_APPEND)
Пример #2
0
  def testCanIterate(self):
    path = TempDir() + "/ring"

    ringfile = Ringfile.create(path, 1024)
    ringfile.write("Hello, World!")
    ringfile.close()

    ringfile = Ringfile(path, MODE_APPEND)
    ringfile.write("Goodbye, World!")
    ringfile.close()

    records = list(Ringfile(path, MODE_READ))
    self.assertEqual(["Hello, World!", "Goodbye, World!"], records)
Пример #3
0
  def testCanReadAndWriteBasics(self):
    path = TempDir() + "/ring"

    ringfile = Ringfile.create(path, 1024)
    ringfile.write("Hello, World!")
    ringfile.close()

    ringfile = Ringfile(path, MODE_APPEND)
    ringfile.write("Goodbye, World!")
    ringfile.close()

    ringfile = Ringfile(path, MODE_READ)
    self.assertEqual("Hello, World!", ringfile.read())
    self.assertEqual("Goodbye, World!", ringfile.read())
    self.assertEqual(None, ringfile.read())