-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
88 lines (68 loc) · 2.15 KB
/
test.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import driver
import hashlib
import ksh
import os
import psutil
import pytest
import subprocess
import winreg
MD5SUM = "d8a9e839260c00e65cc91be886638871"
TEST_REG_KEY = r"Software\TestKey"
TEST_REG_VALUE = "TestValue"
def get_file_path(file):
return os.path.abspath(".") + "\\" + file
@pytest.fixture(scope="session", autouse=True)
def teardown_all():
yield
# Cleanup files
if os.path.exists("hund"):
os.remove("hund")
# Cleanup registry
try:
with winreg.OpenKey(
winreg.HKEY_CURRENT_USER, TEST_REG_KEY, 0, winreg.KEY_ALL_ACCESS
) as key:
winreg.DeleteKey(key, TEST_REG_VALUE)
winreg.DeleteKey(winreg.HKEY_CURRENT_USER, TEST_REG_KEY)
except (FileNotFoundError, PermissionError):
pass
def test_driver_test():
ksh.test()
def test_driver_cp():
from_file = "LICENSE"
to_file = "hund"
ksh.cp(get_file_path(from_file), get_file_path(to_file))
assert os.path.exists(to_file)
assert hashlib.md5(open(to_file, "rb").read()).hexdigest() == MD5SUM
def test_driver_mv():
from_file = "hund"
to_file = "katze"
ksh.mv(get_file_path(from_file), get_file_path(to_file))
assert os.path.exists(to_file)
assert not os.path.exists(from_file)
assert hashlib.md5(open(to_file, "rb").read()).hexdigest() == MD5SUM
def test_driver_rm():
path = get_file_path("katze")
ksh.rm(path)
assert not os.path.exists(path)
def test_driver_pkill():
notepad = "notepad.exe"
process = subprocess.Popen([notepad])
pid = process.pid
ksh.pkill(pid)
for proc in psutil.process_iter():
if proc.name() == notepad:
assert pid != proc.pid
def test_driver_regedit():
reg_path = rf"HKEY_CURRENT_USER\{TEST_REG_KEY}"
for k, v in (
(driver.RegType.REG_DWORD, 1234),
(driver.RegType.REG_QWORD, 12345443232),
(driver.RegType.REG_SZ, "hund"),
):
ksh.regedit(k.name, v, reg_path, TEST_REG_VALUE)
with winreg.OpenKey(
winreg.HKEY_CURRENT_USER, TEST_REG_KEY, 0, winreg.KEY_READ
) as key:
res = winreg.QueryValueEx(key, TEST_REG_VALUE)
assert res[0] == v