-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtests.py
132 lines (109 loc) · 3.62 KB
/
tests.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from G14Control import gaming_thread_impl, load_config
import unittest
import os
import re
from G14RunCommands import RunCommands
import yaml
import subprocess as sp
import subprocess
import sys
import time
config = {}
windows_plans = []
current_windows_plan = ""
app_GUID = ""
dpp_GUID = ""
active_plan_map = dict()
G14dir = ""
def get_power_plans():
global dpp_GUID, app_GUID
all_plans = subprocess.check_output(["powercfg", "/l"])
for i in str(all_plans).split("\\n"):
print(i)
if i.find(config["default_power_plan"]) != -1:
dpp_GUID = i.split(" ")[3]
if i.find(config["alt_power_plan"]) != -1:
app_GUID = i.split(" ")[3]
def get_windows_plans():
global config, active_plan_map, current_windows_plan
windows_power_options = re.findall(
r"([0-9a-f\-]{36}) *\((.*)\) *\*?\n", os.popen("powercfg /l").read()
)
active_plan_map = {x[1]: False for x in windows_power_options}
active_plan_map[current_windows_plan] = True
return windows_power_options
"""
Cannot be run before @get_windows_plans()
"""
def get_active_plan_map():
global windows_plans, active_plan_map
try:
active_plan_map["Balanced"]
return active_plan_map
except Exception:
active_plan_map = {x[1]: False for x in windows_plans}
active_plan_map[current_windows_plan] = True
return active_plan_map
def get_app_path():
global G14dir
G14Dir = ""
# Sets the path accordingly whether it is a python script or a frozen .exe
if getattr(sys, "frozen", False):
G14dir = os.path.dirname(os.path.realpath(sys.executable))
elif __file__:
G14dir = os.path.dirname(os.path.realpath(__file__))
def loadConfig():
config = {}
with open("data/config.yml") as file:
config = yaml.load(file.read())
return config
class RunCommandsTests(unittest.TestCase):
def setUp(self):
global config, windows_plans, active_plan_map, config, dpp_GUID, app_GUID, G14dir
self.config = loadConfig()
config = self.config
get_power_plans()
get_app_path()
get_windows_plans()
get_active_plan_map()
self.main_cmds = RunCommands(
self.config,
G14dir=G14dir,
app_GUID=app_GUID,
dpp_GUID=dpp_GUID,
notify=lambda x: print(x),
windows_plans=windows_plans,
active_plan_map=active_plan_map,
)
def boost_test(self):
startboost = self.main_cmds.get_boost()
self.main_cmds.do_boost(2)
boost = self.main_cmds.get_boost()
self.assertEqual(2, int(boost, 16), "Boost not equal to boost that was set (2)")
self.main_cmds.do_boost(4)
boost = self.main_cmds.get_boost()
self.assertEqual(4, int(boost, 16))
self.main_cmds.do_boost(0)
boost = self.main_cmds.get_boost()
self.assertEqual(0, int(boost, 16))
self.main_cmds.do_boost(int(startboost, 16))
def gamingthread_test(self):
config = load_config("C:/Users/alexa/Documents/G14ControlR3")
running = True
global auto_power_switch
auto_power_switch = True
gaming = gaming_thread_impl(config, running)
self.assertFalse(gaming.is_alive())
gaming.start()
self.assertTrue(gaming.is_alive())
gaming.kill()
while gaming.is_alive():
print("still alive...")
time.sleep(1)
def suite():
suite = unittest.TestSuite()
suite.addTest(RunCommandsTests("boost_test"))
return suite
if __name__ == "__main__":
runner = unittest.TextTestRunner()
runner.run(suite())