subprocess-util/test.py

53 lines
1.4 KiB
Python
Raw Normal View History

2023-01-10 17:24:35 +01:00
from pathlib import Path
from rsync_inform import rsync_inform
2023-01-10 15:42:33 +01:00
from subprocess_util import execute_print_capture
from subprocess_util1 import execute_capture
from subprocess_util_2 import execute_print_transfer_chunks
2023-01-10 15:42:33 +01:00
def test():
test1()
test2()
test3()
test4()
def test1():
print("TEST ZERO")
returncode, out, err = execute_capture(['ls', '-la'])
print(f'stdout:\n{out}\nstderr:\n{err}')
print()
returncode, out, err = execute_capture(['ls', '/foo/bar'])
print(f'stdout:\n{out}\nstderr:\n{err}')
2023-01-10 17:24:35 +01:00
def test2():
print("TEST ONE")
2023-01-10 15:42:33 +01:00
returncode, out, err = execute_print_capture(['ls', '-la'])
print()
returncode, out, err = execute_print_capture(['ls', '/foo/bar'])
def test3():
2023-01-10 17:24:35 +01:00
print("TEST TWO-1")
execute_print_capture(['rm', '-rf', 'test/1', 'test/2', 'test/3'])
returncode = execute_print_transfer_chunks(['ls', '-la'], Path('test/1'))
2023-01-10 17:24:35 +01:00
print("TEST TWO-2")
returncode = execute_print_transfer_chunks(['ls', '/foo/bar'], Path('test/2'))
2023-01-10 17:24:35 +01:00
print("TEST TWO-3")
returncode = execute_print_transfer_chunks(['cat', 'subprocess_util.py'], Path('test/3'),
chunk_size=1024)
def test4():
rsync_inform(
['ls', 'test/rsync-error'], # rsync src to dst
['ls', 'test/ssh-error'], # ssh target-pc 'echo "OK" | nc -U "/path/to/unix-socket"'
Path('test/unix-socket')
)
2023-01-10 17:24:35 +01:00
2023-01-10 15:42:33 +01:00
if __name__ == '__main__':
test()