Skip to content

Commit 9c985bd

Browse files
committed
Testsuite POC
1 parent 05df716 commit 9c985bd

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

testsuite/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.venv/

testsuite/Notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Implementation notes
2+
3+
- The `pyautogui` sends input to the process in focus, which is the `spf` subprocess.
4+
- If `spf` is not exited correcly via `q`, it causes wierd vertical tabs in print statements from python
5+
- There is some flakiness in sending of input. Many times, `Ctrl+C` is received as `C` in `spf`
6+
- If first key is `Ctrl+C`, its always received as `C`

testsuite/ReadMe.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Setup for MacOS / Linux
2+
3+
```
4+
# cd to this directory
5+
cd <path/to/here>
6+
python3 -m venv .venv
7+
.venv/bin/pip install --upgrade pip
8+
.venv/bin/pip install -r requirements.txt
9+
```

testsuite/main.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import os
2+
import subprocess
3+
import time
4+
import pyautogui
5+
import shutil
6+
import tempfile
7+
8+
def spf_input():
9+
pyautogui.hotkey('x') # Random key press. First key cant be Ctrl+C for some reason
10+
pyautogui.hotkey('ctrl', 'c') # Simulate Ctrl+C
11+
time.sleep(0.5) # Wait for copy action to complete
12+
pyautogui.hotkey('ctrl', 'v') # Simulate Ctrl+V
13+
time.sleep(0.5)
14+
pyautogui.hotkey('q')
15+
time.sleep(0.5)
16+
17+
def main():
18+
process = None # To make it accessible at all scopes
19+
try:
20+
with tempfile.TemporaryDirectory() as temp_dir:
21+
print(f'Temporary directory created at: {temp_dir}')
22+
23+
dir1 = os.path.join(temp_dir, "dir1")
24+
file1_path = os.path.join(dir1, "file1.txt")
25+
file1_cpy_path = os.path.join(dir1, "file1(1).txt")
26+
spf_out_filepath = os.path.join(temp_dir, "out.txt")
27+
spf_err_filepath = os.path.join(temp_dir, "err.txt")
28+
# setup
29+
os.makedirs(dir1, exist_ok=True)
30+
with open(file1_path, 'w') as f:
31+
f.write("This is a test file.")
32+
33+
with open(spf_out_filepath, 'w') as fout, open(spf_err_filepath, 'w') as ferr:
34+
# Start Superfile in a subprocess
35+
process = subprocess.Popen(
36+
['/Users/kuknitin/Workspace/kuknitin/superfile/bin/spf', dir1],
37+
stdout=fout,
38+
stderr=ferr,
39+
)
40+
# Wait for it to load.
41+
time.sleep(1)
42+
spf_input()
43+
44+
45+
if os.path.isfile(file1_cpy_path):
46+
print("File copied successfully!")
47+
else:
48+
print("File copy failed.")
49+
50+
if process.poll() is not None:
51+
print("spf process exited successfuly")
52+
else:
53+
print("spf process is still running")
54+
except Exception as e:
55+
print("Exception during test : ", e)
56+
finally:
57+
process.terminate()
58+
59+
main()
60+

testsuite/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pyautogui

0 commit comments

Comments
 (0)