Skip to content

Commit

Permalink
Readded path tests with fixes to the registry path detection
Browse files Browse the repository at this point in the history
  • Loading branch information
thatsIch committed Dec 12, 2016
1 parent 844209b commit 95deb76
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 62 deletions.
47 changes: 33 additions & 14 deletions path/program_path_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,39 @@ def _get_rainmeter_path_from_registry():
"""
Registry
"""
regkey = _get_rainmeter_registry_key()
if regkey:
keyval = winreg.QueryValueEx(regkey, "Personal")

for i in range(1024):
try:
asubkey_name = winreg.EnumKey(keyval, i)
asubkey = winreg.OpenKey(keyval, asubkey_name)
rainmeterpath = winreg.QueryValueEx(asubkey, "DisplayName")
logger.info(__file__, "get_cached_program_path()", "found rainmeter path through registry: " + rainmeterpath)
if rainmeterpath:
return rainmeterpath
except EnvironmentError:
break
rainmeter_key = _get_rainmeter_registry_key()
if rainmeter_key:
rainmeter_path = winreg.QueryValue(rainmeter_key, None)

return rainmeter_path

# sub_key_size and last_modified not required
# _, value_size, _ = winreg.QueryInfoKey(regkey)
# print("---", value_size)
# print("---", winreg.EnumKey(regkey, 0))
# for entry_index in range(0, entry_size):
# key_name = winreg.EnumKey(regkey, entry_index)
# key = winreg.OpenKey(regkey, key_name)
# try:
# print(winreg.QueryValueEx(key, 'DisplayName')[0])
# except OSError as e:
# print(e)
# pass
# finally:
# key.close()

# keyval = winreg.QueryValueEx(regkey, "Personal")

# for i in range(1024):
# try:
# asubkey_name = winreg.EnumKey(keyval, i)
# asubkey = winreg.OpenKey(keyval, asubkey_name)
# rainmeterpath = winreg.QueryValueEx(asubkey, "DisplayName")
# logger.info(__file__, "get_cached_program_path()", "found rainmeter path through registry: " + rainmeterpath)
# if rainmeterpath:
# return rainmeterpath
# except EnvironmentError:
# break

return None

Expand Down
2 changes: 1 addition & 1 deletion tests/test_completion_skin_rainmeter_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TestSkinRainmeterSectionCompletion(TestCase):
Testing the skin/rainmeter section completion
"""

def not_rainmeter_should_return_none(self):
def test_wrong_section_return_none(self):
"""
The given section is 'Different' but we are moving in the Rainmeter section
thus only 'Rainmeter' is allowed
Expand Down
8 changes: 4 additions & 4 deletions tests/test_levenshtein.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ class TestLevenShtein(TestCase):
Test for the levenshtein module
"""

def same_word_should_equal_zero(self):
def test_same_word_should_zero(self):
"""
if we use the same word there should be no difference required
"""
diff = levenshtein.levenshtein("hello", "hello")

self.assertEqual(diff, 0)

def zero_words_should_equal_zero(self):
def test_zero_words_should_zero(self):
"""
special case with same word but both are empty
"""
diff = levenshtein.levenshtein("", "")

self.assertEqual(diff, 0)

def first_word_one_longer_should_equal_one(self):
def test_first_longer_equal_one(self):
"""
try with same word base but missing characters
"""
diff = levenshtein.levenshtein("hello", "hell")

self.assertEqual(diff, 1)

def second_word_one_longer_should_equal_one(self):
def test_second_longer_equal_one(self):
"""
reversed case of the missing character.
method should work in both ways and not return a negative difference
Expand Down
20 changes: 10 additions & 10 deletions tests/test_path_program_drive_provider.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# import sys
import sys

# from unittest import TestCase
from unittest import TestCase

# program_drive_provider = sys.modules["Rainmeter.path.program_drive_provider"]
program_drive_provider = sys.modules["Rainmeter.path.program_drive_provider"]


# class TestFunctions(TestCase):
class TestFunctions(TestCase):

# def test_path_program_drive_with_rainmeter_installed_return_drive(self):
# """
# Per default we install it onto c:/
# """
# program_drive = program_drive_provider.get_cached_program_drive()
def test_default_drive(self):
"""
Per default we install it onto c:/
"""
program_drive = program_drive_provider.get_cached_program_drive()

# self.assertEqual(program_drive, "C:")
self.assertEqual(program_drive, "C:")
60 changes: 27 additions & 33 deletions tests/test_path_program_path_provider.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
# import sys
import sys

# from unittest import TestCase
from unittest import TestCase

# program_path_provider = sys.modules["Rainmeter.path.program_path_provider"]
program_path_provider = sys.modules["Rainmeter.path.program_path_provider"]


# class TestProgramPathProvider(TestCase):
class TestProgramPathProvider(TestCase):

# def test_path_program_path_with_rainmeter_from_default_path(self):
# """
# If the user installed the application into the default directory
# it is in "C:/Program Files/Rainmeter"
# """
# default_program_path = program_path_provider._get_rainmeter_path_from_default_path()
def test_default_path(self):
"""
If the user installed the application into the default directory
it is in "C:/Program Files/Rainmeter"
"""
default_program_path = program_path_provider._get_rainmeter_path_from_default_path()

# self.assertEqual(default_program_path, "C:\\Program Files\\Rainmeter")
self.assertEqual(default_program_path, "C:\\Program Files\\Rainmeter")

# def test_get_rainmeter_registry_key(self):
# """
# test
# """
# key = program_path_provider._get_rainmeter_registry_key()
def test_from_registry(self):
"""
Upon normal installation it will leave a registry entry to detect.
We can use this to find the actual Rainmeter.
Since we use the default installation path, there should no difference
"""
registry_program_path = program_path_provider._get_rainmeter_path_from_registry()

# self.assertEqual(key, "test")
self.assertEqual(registry_program_path, "C:\\Program Files\\Rainmeter")

# def test_path_program_path_with_rainmeter_from_registry(self):
# """
# Upon normal installation it will leave a registry entry to detect.
# We can use this to find the actual Rainmeter.
# Since we use the default installation path, there should no difference
# """
# registry_program_path = program_path_provider._get_rainmeter_path_from_registry()
def test_overall(self):
"""
Per default we install it onto "C:/Program Files/Rainmeter"
but since we use the path internally we already add / to it
and python internal path uses \\ instead windows /
"""
program_path = program_path_provider.get_cached_program_path()

# self.assertEqual(registry_program_path, "C:\\Program Files\\Rainmeter")

# def test_path_program_path_with_rainmeter_installed_return_drive(self):
# """
# Per default we install it onto "C:/Program Files/Rainmeter"
# """
# program_path = program_path_provider.get_cached_program_path()

# self.assertEqual(program_path, "C:\\Program Files\\Rainmeter")
self.assertEqual(program_path, "C:\\Program Files\\Rainmeter\\")

0 comments on commit 95deb76

Please sign in to comment.