Пример #1
0
 def test_atomic_file(self):
     af1 = AtomicFile("tmp.txt")
     af2 = AtomicFile("tmp.txt")
     af1.write_atomic(six.b("foo"))
     af2.write_atomic(six.b("bar"))
     self.assertEqual(af1.read_atomic(), six.b("bar"))
     self.assertEqual(af2.read_atomic(), six.b("bar"))
     local.path("tmp.txt").delete()
Пример #2
0
 def test_atomic_file(self):
     af1 = AtomicFile("tmp.txt")
     af2 = AtomicFile("tmp.txt")
     af1.write_atomic(b"foo")
     af2.write_atomic(b"bar")
     assert af1.read_atomic() == b"bar"
     assert af2.read_atomic() == b"bar"
     local.path("tmp.txt").delete()
Пример #3
0
 def test_atomic_file(self):
     af1 = AtomicFile("tmp.txt")
     af2 = AtomicFile("tmp.txt")
     af1.write_atomic(six.b("foo"))
     af2.write_atomic(six.b("bar"))
     self.assertEqual(af1.read_atomic(), six.b("bar"))
     self.assertEqual(af2.read_atomic(), six.b("bar"))
     local.path("tmp.txt").delete()
Пример #4
0
    def test_atomic_file2(self):
        af = AtomicFile("tmp.txt")

        code = """from __future__ import with_statement
from plumbum.fs.atomic import AtomicFile
af = AtomicFile("tmp.txt")
try:
    with af.locked(blocking = False):
        raise ValueError("this should have failed")
except (OSError, IOError):
    print("already locked")
"""
        with af.locked():
            output = local.python("-c", code)
            self.assertEqual(output.strip(), "already locked")

        local.path("tmp.txt").delete()
Пример #5
0
    def test_atomic_file2(self):
        af = AtomicFile("tmp.txt")

        code = """from __future__ import with_statement
from plumbum.fs.atomic import AtomicFile
af = AtomicFile("tmp.txt")
try:
    with af.locked(blocking = False):
        raise ValueError("this should have failed")
except (OSError, IOError):
    print("already locked")
"""
        with af.locked():
            output = local.python("-c", code)
            self.assertEqual(output.strip(), "already locked")

        local.path("tmp.txt").delete()