-
Notifications
You must be signed in to change notification settings - Fork 1
/
unitTest.py
52 lines (40 loc) · 1.93 KB
/
unitTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import unittest
from unittest.mock import patch
from io import StringIO
import os
import json
from maCrow import record, replay, count_down_animation_config
class TestMouseKeyboardRecorder(unittest.TestCase):
def test_record_and_replay(self):
test_file = 'test_actions.json'
# Record actions
with patch('builtins.input', return_value='record'):
with patch('sys.argv', ['script_name.py', 'record', '--file', test_file]):
count_down_animation_config('record')
record(test_file)
# Replay actions
with patch('builtins.input', return_value='replay'):
with patch('sys.argv', ['script_name.py', 'replay', '--file', test_file]):
count_down_animation_config('replay')
replay(test_file)
# Assert that the test file is created and not empty
self.assertTrue(os.path.exists(test_file))
self.assertGreater(os.path.getsize(test_file), 0)
# Clean up the test file
os.remove(test_file)
def test_record_invalid_file(self):
# Attempt to record with an invalid file name
with patch('builtins.input', return_value='record'):
with patch('sys.argv', ['script_name.py', 'record', '--file', 'invalid file name']):
with self.assertRaises(SystemExit):
count_down_animation_config('record')
record('invalid file name')
def test_replay_invalid_file(self):
# Attempt to replay with an invalid file name
with patch('builtins.input', return_value='replay'):
with patch('sys.argv', ['script_name.py', 'replay', '--file', 'invalid file name']):
with self.assertRaises(SystemExit):
count_down_animation_config('replay')
replay('invalid file name')
if __name__ == '__main__':
unittest.main()