예제 #1
0
 def test_del_key(self):
     key = RegistryKey(self.SET_TEST_KEY_PATH)
     if not key.is_key():
         key.create()
     key.flush()
     key.delete()
     assert not key.is_key()
예제 #2
0
 def test_create(self):
     key = RegistryKey(self.SET_TEST_KEY_PATH)
     if key.is_key():
         key.delete()
     key.create()
     assert key.is_key()
     key.delete()
예제 #3
0
 def test_get_fail(self):
     key = RegistryKey(self.SET_TEST_KEY_PATH)
     if not key.is_key():
         key.create()
     with pytest.raises(KeyError):
         key['InvalidKey']
     key.delete()
예제 #4
0
    def test_key_len(self):
        key = RegistryKey(self.SET_TEST_KEY_PATH)

        for i in range(10):
            key[f'test{i}'] = Dword(i)

        assert len(key) == 10

        key.delete()
예제 #5
0
    def test_subkeys(self):
        key = RegistryKey(r'HKEY_CURRENT_USER\harmless_key')
        if not key.is_key():
            key.create()

        (key / 'test1').create()
        (key / 'test2').create()

        assert len(key.subkeys()) == 2

        key.delete()
예제 #6
0
    def test_default_value(self):
        key = RegistryKey(self.SET_TEST_KEY_PATH)

        key.default_value = Dword(42)
        assert key.has_default_value()
        assert key.default_value == key[''] == 42

        del key.default_value
        assert not key.has_default_value()
        assert '' not in key.values()

        key.delete()
예제 #7
0
    def test_values_iter(self):
        import re

        key = RegistryKey(self.SET_TEST_KEY_PATH)

        for i in range(10):
            key[f'test{i}'] = Dword(i)
        key.flush()

        values = key.values()
        assert len(values) > 0
        for name, value in values.items():
            assert re.match(r'test([0-9])+', name) and isinstance(value, int)

        key.delete()
예제 #8
0
    def test_rename(self):
        key = RegistryKey(r'HKCU\harmless_key')
        key2 = RegistryKey(r'HKCU\harmless2')

        key['valuetest'] = Dword(7)
        (key / 'test1').create()
        (key / 'test1')['valuetest'] = Dword(42)

        key.rename(key2)

        assert not key.is_key()
        assert key2.is_key()

        with pytest.raises(ValueError):
            key2.rename(key2 / 'subkey')

        key2.delete()
예제 #9
0
    def test_copy(self):
        key = RegistryKey(r'HKCU\harmless_key')
        if not key.is_key():
            key.create()

        key['valuetest'] = Dword(7)
        (key / 'test1').create()
        (key / 'test1')['valuetest'] = Dword(42)

        new_key = key.parent / 'harmless2'
        key.copy(new_key)

        assert new_key['valuetest'] == 7
        assert (new_key / 'test1')['valuetest'] == 42

        key.delete()
        new_key.delete()
예제 #10
0
    def test_walk(self):
        key = RegistryKey(r'HKCU\harmless_key')
        if not key.is_key():
            key.create()

        (key / 'test1').create()
        (key / 'test1/test11').create()
        (key / 'test1/test12').create()
        (key / 'test2').create()
        (key / 'test2/test21').create()

        walk_results = list(key.walk())
        expected_results = [
            (key, ['test1', 'test2']),
            (key / 'test1', ['test11', 'test12']),
            (key / 'test2', ['test21']),
        ]

        for actual, expected in zip(walk_results, expected_results):
            assert actual == expected

        key.delete()
예제 #11
0
 def test_set_get_none(self):
     key = RegistryKey(self.SET_TEST_KEY_PATH)
     key['TestNone'] = None
     assert key['TestNone'] is None
     key.delete()