コード例 #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
ファイル: test_local.py プロジェクト: KOLANICH-libs/plumbum
 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
ファイル: test_local.py プロジェクト: adamchainz/plumbum
 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
ファイル: test_local.py プロジェクト: adamchainz/plumbum
    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()