Clearer unsupported platform error message
If we don't know how to support a detected platform the old code gave a cryptic error message. Make this more clear by setting a specific "unknown" platform value that raises if you attempt to get package manager info with an error message that explains this situation. Change-Id: I125dad3a3aa8f67ad5e96430e51022f5aa461b23
This commit is contained in:
parent
313cccff27
commit
c373280025
|
@ -384,6 +384,8 @@ class Depends(object):
|
|||
elif distro_id in ["arch"]:
|
||||
atoms.add("pacman")
|
||||
self.platform = Pacman()
|
||||
else:
|
||||
self.platform = Unknown()
|
||||
return ["platform:%s" % (atom,) for atom in sorted(atoms)]
|
||||
|
||||
|
||||
|
@ -398,6 +400,13 @@ class Platform(object):
|
|||
raise NotImplementedError(self.get_pkg_version)
|
||||
|
||||
|
||||
class Unknown(Platform):
|
||||
"""Unknown platform implementation. Raises error."""
|
||||
|
||||
def get_pkg_version(self, pkg_name):
|
||||
raise Exception("Uknown package manager for current platform.")
|
||||
|
||||
|
||||
class Brew(Platform):
|
||||
"""brew specific platform implementation."""
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
NAME="Unknown"
|
||||
VERSION="12345"
|
||||
ID=unknown
|
||||
ID_LIKE=unknown
|
||||
PRETTY_NAME="Not a real distro 12345"
|
||||
VERSION_ID="12345"
|
||||
HOME_URL="https://example.com"
|
||||
SUPPORT_URL="https://help.example.com"
|
||||
BUG_REPORT_URL="https://bugs.example.com"
|
||||
VERSION_CODENAME=Testing
|
|
@ -25,6 +25,7 @@ import distro
|
|||
import fixtures
|
||||
import mock
|
||||
import ometa.runtime
|
||||
from testtools import ExpectedException
|
||||
from testtools.matchers import Contains
|
||||
from testtools.matchers import Equals
|
||||
from testtools.matchers import MatchesSetwise
|
||||
|
@ -93,6 +94,16 @@ class TestDepends(TestCase):
|
|||
yield mock_checkoutput
|
||||
mock_checkoutput.assert_called_once_with()
|
||||
|
||||
def test_detects_unknown(self):
|
||||
with DistroFixture("Unknown"):
|
||||
depends = Depends("")
|
||||
self.assertThat(
|
||||
depends.platform_profiles(), Contains("platform:unknown"))
|
||||
with ExpectedException(Exception,
|
||||
"Uknown package manager for "
|
||||
"current platform."):
|
||||
depends.platform.get_pkg_version('x')
|
||||
|
||||
def test_detects_amazon_linux(self):
|
||||
with DistroFixture("AmazonAMI"):
|
||||
depends = Depends("")
|
||||
|
|
Loading…
Reference in New Issue