Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Kodi version getting safer #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/aussieaddonscommon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,26 @@ def get_kodi_build():
try:
return xbmc.getInfoLabel("System.BuildVersion")
except Exception:
return
return ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning None is usually best if you're going to later test it with if build: for example. As you've done here, an empty string also evaluates to False. Does this necessarily need to be a string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - the changes in get_kodi_version make this redundant, I'll make it None.



def get_kodi_version():
"""Return the version number of Kodi"""
build = get_kodi_build()
version = build.split(' ')[0]
return version
if build:
version = build.split(' ')[0]
return version
else:
return '0'


def get_kodi_major_version():
"""Return the major version number of Kodi"""
version = get_kodi_version().split('.')[0]
return int(version)
if version:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like version should never evaluate to False from get_kodi_version(), so this change might not be that useful?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I worked from this function upwards, should have come back to look at it again!

return int(version)
else:
return 0


def log_kodi_platform_version():
Expand Down
10 changes: 10 additions & 0 deletions lib/tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,21 @@ def test_get_kodi_version(self, mock_info_label):
mock_info_label.return_value = fakes.BUILD_VERSION
self.assertEqual('18.2', utils.get_kodi_version())

@mock.patch('xbmc.getInfoLabel')
def test_get_kodi_version_none(self, mock_info_label):
mock_info_label.return_value = None
self.assertEqual('0', utils.get_kodi_version())

@mock.patch('xbmc.getInfoLabel')
def test_get_kodi_major_version(self, mock_info_label):
mock_info_label.return_value = fakes.BUILD_VERSION
self.assertEqual(18, utils.get_kodi_major_version())

@mock.patch('xbmc.getInfoLabel')
def test_get_kodi_major_version_blank(self, mock_info_label):
mock_info_label.return_value = ''
self.assertEqual(0, utils.get_kodi_major_version())

@mock.patch('xbmcaddon.Addon', fakes.FakeAddon)
@mock.patch('xbmc.log')
@mock.patch('xbmc.getCondVisibility')
Expand Down