-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest_refresh.py
More file actions
52 lines (45 loc) · 2.44 KB
/
Copy pathtest_refresh.py
File metadata and controls
52 lines (45 loc) · 2.44 KB
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
# SPDX-License-Identifier: GPL-3.0-only
import json
import tempfile
import unittest
import zipfile
from pathlib import Path
from unittest.mock import patch
from bridge import Bridge, refresh_value, settings_text, check_refresh_adapter
import test_app
class RefreshTests(unittest.TestCase):
def test_rates(self):
for value in ('Default',0,72,80,90,120,144):
self.assertIn('refresh_rate='+str(refresh_value(value)),settings_text(refresh_rate=value))
for value in (-1,60,91,float('nan'),float('inf'),'90; reboot'):
with self.assertRaises(ValueError): refresh_value(value)
def test_old_build_default_and_explicit_rate(self):
with tempfile.TemporaryDirectory() as tmp:
with zipfile.ZipFile(Path(tmp)/'game.apk','w') as apk:
apk.writestr('lib/arm64-v8a/libopenxr_loader_generic.so',b'old')
check_refresh_adapter(tmp,0)
with self.assertRaisesRegex(ValueError,'reconversion'):check_refresh_adapter(tmp,90)
b=Bridge()
with patch.object(b,'remote') as remote,patch.object(b,'put_text') as put:
with self.assertRaises(ValueError):b.update_settings(tmp,None,100,True,True,90)
remote.assert_not_called();put.assert_not_called()
def test_update_settings(self):
with tempfile.TemporaryDirectory() as tmp:
folder=Path(tmp)
with zipfile.ZipFile(folder/'game.apk','w') as apk:
apk.writestr('lib/arm64-v8a/libopenxr_loader_generic.so',b'Q2F_REFRESH_RATE_V1')
(folder/'game.json').write_text('{}')
(folder/'deployment.json').write_text(json.dumps({'package':'com.example.game'}))
b=Bridge(lambda _:None)
with patch.object(b,'deployment_base',return_value='/safe/game'),patch.object(b,'put_text') as put:
b.update_settings(folder,None,100,True,True,90)
self.assertEqual(put.call_count,2)
for call in put.call_args_list:self.assertIn('refresh_rate=90\n',call.args[2])
self.assertEqual(json.loads((folder/'game.json').read_text())['refresh_rate'],90)
class RefreshUITests(unittest.TestCase):
setUp=test_app.ArtworkUITests.setUp
tearDown=test_app.ArtworkUITests.tearDown
def test_ui_selection(self):
self.assertEqual(self.app.options()['refresh_rate'],0)
self.app.vars['refresh_rate'].set('90')
self.assertEqual(self.app.options()['refresh_rate'],90)