예제 #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()