mirror of
https://github.com/lutris/lutris
synced 2024-10-06 15:59:39 +00:00
Add tests for WineRegistry
This commit is contained in:
parent
dda8db1e35
commit
c01f2c9ccc
|
@ -71,9 +71,7 @@ class WineRegistry(object):
|
|||
self.arch = line.split('=')[1]
|
||||
continue
|
||||
if line.startswith('['):
|
||||
key, timestamp = line.strip().rsplit(' ', 1)
|
||||
current_key = WineRegistryKey(key)
|
||||
current_key.timestamp = timestamp
|
||||
current_key = WineRegistryKey(line)
|
||||
self.keys.append(current_key)
|
||||
self.key_map[current_key.name] = key_index
|
||||
key_index += 1
|
||||
|
@ -114,8 +112,9 @@ class WineRegistry(object):
|
|||
|
||||
|
||||
class WineRegistryKey(object):
|
||||
def __init__(self, key):
|
||||
self.timestamp = None
|
||||
def __init__(self, key_def):
|
||||
key, timestamp = key_def.strip().rsplit(' ', 1)
|
||||
self.timestamp = int(timestamp)
|
||||
self.values = {}
|
||||
self.name = key.replace('\\\\', '/').strip("[]")
|
||||
|
||||
|
|
22
tests/test_registry.py
Normal file
22
tests/test_registry.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
import os
|
||||
from unittest import TestCase
|
||||
from lutris.util.wineregistry import WineRegistry
|
||||
|
||||
FIXTURES_PATH = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
|
||||
|
||||
class TestWineRegistry(TestCase):
|
||||
def setUp(self):
|
||||
registry_path = os.path.join(FIXTURES_PATH, 'user.reg')
|
||||
self.registry = WineRegistry(registry_path)
|
||||
|
||||
def test_can_load_registry(self):
|
||||
self.assertTrue(len(self.registry.keys) > 10)
|
||||
|
||||
def test_can_query_registry(self):
|
||||
value = self.registry.query('Control Panel/Keyboard', 'KeyboardSpeed')
|
||||
self.assertEqual(value, '31')
|
||||
|
||||
def test_can_get_timestamp_as_int(self):
|
||||
key = self.registry.get_key('Control Panel/Keyboard')
|
||||
self.assertEqual(key.timestamp, 1477412318)
|
Loading…
Reference in a new issue