Esempio n. 1
0
 def test_copy_to_destination(self):
     with TemporaryDirectory() as tmpdir:
         tempfile = tempbackupfile.TemporaryBackupFile("tmpname", tmpdir)
         tempfile.write(b"This is my file")
         tempfile.close()
         final_file = Path(tmpdir) / "tmpname"
         assert final_file.exists()
Esempio n. 2
0
 def test_context_manager(self):
     with TemporaryDirectory() as tmpdir:
         with tempbackupfile.TemporaryBackupFile("tmpname",
                                                 tmpdir) as tempfile:
             tempfile.write(b'Hello\n my friend')
         final_file = Path(tmpdir) / "tmpname"
         assert final_file.exists()
Esempio n. 3
0
 def test_read_size_with_seek(self):
     with TemporaryDirectory() as tmpdir:
         tempfile = tempbackupfile.TemporaryBackupFile("tmpname", tmpdir)
         tempfile.write(b"This is my file")
         tempfile.seek(0)
         buf = tempfile.read(1)
         assert buf == b'T'
Esempio n. 4
0
 def test_readlines_hint(self):
     with TemporaryDirectory() as tmpdir:
         tempfile = tempbackupfile.TemporaryBackupFile("tmpname", tmpdir)
         tempfile.write(b"Hello\n")
         tempfile.write(b"my friend")
         tempfile.seek(0)
         assert tempfile.readlines(10) == [b'Hello\n', b'my friend']
Esempio n. 5
0
 def test_compress(self):
     with TemporaryDirectory() as tmpdir:
         tempfile = tempbackupfile.TemporaryBackupFile("tmpname",
                                                       tmpdir,
                                                       compress=True)
         tempfile.write(b"This is my file")
         tempfile.close()
         final_file = Path(tmpdir) / "tmpname.gz"
         assert final_file.exists()
Esempio n. 6
0
 def test_readinto(self):
     with TemporaryDirectory() as tmpdir:
         tempfile = tempbackupfile.TemporaryBackupFile("tmpname", tmpdir)
         tempfile.write(b'Hello\n')
         tempfile.write(b'my friend')
         tempfile.seek(0)
         b = bytearray(10)
         bytes_read = tempfile.readinto(b)
         assert bytes_read == 10
Esempio n. 7
0
 def test_tell(self):
     with TemporaryDirectory() as tmpdir:
         tempfile = tempbackupfile.TemporaryBackupFile("tmpname", tmpdir)
         assert tempfile.tell() == 0
         tempfile.write(b'H')
         assert tempfile.tell() == 1
         tempfile.write(b'ello')
         assert tempfile.tell() == 5
         tempfile.seek(0)
         assert tempfile.tell() == 0
Esempio n. 8
0
 def test_readline_limit_one(self):
     with TemporaryDirectory() as tmpdir:
         tempfile = tempbackupfile.TemporaryBackupFile("tmpname", tmpdir)
         tempfile.write(b"Hello\n")
         tempfile.write(b"my friend")
         tempfile.seek(0)
         assert tempfile.readline(1) == b'H'
         assert tempfile.readline(1) == b'e'
         assert tempfile.readline(1) == b'l'
         assert tempfile.readline(1) == b'l'
         assert tempfile.readline(1) == b'o'
         assert tempfile.readline(1) == b'\n'
         assert tempfile.readline(1) == b'm'
         assert tempfile.readline(1) == b'y'
         assert tempfile.readline(1) == b' '
         assert tempfile.readline(1) == b'f'
         assert tempfile.readline(1) == b'r'
         assert tempfile.readline(1) == b'i'
         assert tempfile.readline(1) == b'e'
         assert tempfile.readline(1) == b'n'
         assert tempfile.readline(1) == b'd'
         assert tempfile.readline(1) == b''
Esempio n. 9
0
 def test_readable(self):
     with TemporaryDirectory() as tmpdir:
         tempfile = tempbackupfile.TemporaryBackupFile("tmpname", tmpdir)
         assert tempfile.readable() is True
Esempio n. 10
0
 def test_isatty(self):
     with TemporaryDirectory() as tmpdir:
         tempfile = tempbackupfile.TemporaryBackupFile("tmpname", tmpdir)
         assert tempfile.isatty() is False
Esempio n. 11
0
 def test_fileno(self):
     with TemporaryDirectory() as tmpdir:
         tempfile = tempbackupfile.TemporaryBackupFile("tmpname", tmpdir)
         assert isinstance(tempfile.fileno(), int)
Esempio n. 12
0
 def test_writelines(self):
     with TemporaryDirectory() as tmpdir:
         tempfile = tempbackupfile.TemporaryBackupFile("tmpname", tmpdir)
         tempfile.writelines([b'Hello\n', b'my friend'])
         tempfile.seek(0)
         assert tempfile.read() == b'Hello\nmy friend'