-
Notifications
You must be signed in to change notification settings - Fork 128
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
Fix platform check for Debian 12 #880
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# | ||
# Copyright (C) 2024 Canonical Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
try: | ||
import unittest.mock as mock | ||
except ImportError: | ||
import mock | ||
|
||
from charmhelpers import osplatform | ||
|
||
|
||
class TestPlatform(unittest.TestCase): | ||
|
||
@mock.patch.object(osplatform, "_get_current_platform") | ||
def test_get_platform_ubuntu(self, _platform): | ||
_platform.return_value = "Ubuntu" | ||
self.assertEqual("ubuntu", osplatform.get_platform()) | ||
|
||
@mock.patch.object(osplatform, "_get_current_platform") | ||
def test_get_platform_centos(self, _platform): | ||
_platform.return_value = "CentOS" | ||
self.assertEqual("centos", osplatform.get_platform()) | ||
|
||
@mock.patch.object(osplatform, "_get_current_platform") | ||
def test_get_platform_debian(self, _platform): | ||
_platform.return_value = "debian gnu/linux" | ||
self.assertEqual("ubuntu", osplatform.get_platform()) | ||
|
||
_platform.return_value = "Debian GNU/Linux" | ||
self.assertEqual("ubuntu", osplatform.get_platform()) | ||
|
||
@mock.patch.object(osplatform, "_get_current_platform") | ||
def test_get_platform_elementary(self, _platform): | ||
_platform.return_value = "elementary linux" | ||
self.assertEqual("ubuntu", osplatform.get_platform()) | ||
|
||
@mock.patch.object(osplatform, "_get_current_platform") | ||
def test_get_platform_pop_os(self, _platform): | ||
_platform.return_value = "Pop!_OS" | ||
self.assertEqual("ubuntu", osplatform.get_platform()) | ||
|
||
@mock.patch.object(osplatform, "_get_current_platform") | ||
def test_get_platform_unknown(self, _platform): | ||
_platform.return_value = "crazy custom flavor" | ||
self.assertRaises(RuntimeError, osplatform.get_platform) | ||
|
||
@mock.patch.object(osplatform, "_get_platform_from_fs") | ||
@mock.patch.object(osplatform, "platform") | ||
def test_get_current_platform_module(self, _platform, _platform_from_fs): | ||
_platform.linux_distribution.return_value = ("Ubuntu", "test") | ||
self.assertEqual("Ubuntu", osplatform._get_current_platform()) | ||
_platform_from_fs.assert_not_called() | ||
|
||
@mock.patch.object(osplatform, "_get_platform_from_fs") | ||
@mock.patch.object(osplatform, "platform") | ||
def test_get_current_platform_fs(self, _platform, _platform_from_fs): | ||
# make sure hasattr says False | ||
del _platform.linux_distribution | ||
_platform_from_fs.return_value = "foobar" | ||
self.assertEqual("foobar", osplatform._get_current_platform()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: there is a
BaseTestCase
class in tests/utils.py that allows you to do these patches in-line as opposed to using the decorators.The decorator approach quickly becomes hard to manage with all the positional arguments etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't disagree with the nit, but I guess for expediency, let's merge this. I think there's a larger body of work in re-working (or adding separate methods)
.patch(...)
and.patch_object
to also/instead return the mock so that static code analysers in vscode and Neovim+LSP don't complain about the magic members that are added to the object as part of the patching functionality.