示例#1
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()
示例#2
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()
示例#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_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()
示例#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_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()
示例#7
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()