mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
Merge from bdrung to introduce new DistroInfo.valid(codename) method
This commit is contained in:
commit
ffa4991cb4
@ -106,6 +106,10 @@ class DistroInfo(object):
|
||||
"""Get list of all supported distributions based on the given date."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def valid(self, codename):
|
||||
"""Check if the given codename is known."""
|
||||
return codename in self.all
|
||||
|
||||
def unsupported(self, date=None):
|
||||
"""Get list of all unsupported distributions based on the given date."""
|
||||
if date is None:
|
||||
@ -167,6 +171,11 @@ class DebianDistroInfo(DistroInfo):
|
||||
raise DistroDataOutdated()
|
||||
return distros[-2]["series"]
|
||||
|
||||
def valid(self, codename):
|
||||
"""Check if the given codename is known."""
|
||||
return DistroInfo.valid(self, codename) or \
|
||||
codename in ["unstable", "testing", "stable", "old"]
|
||||
|
||||
|
||||
class UbuntuDistroInfo(DistroInfo):
|
||||
"""provides information about Ubuntu's distributions"""
|
||||
|
@ -177,5 +177,5 @@ def codename_to_distribution(codename):
|
||||
if not info:
|
||||
continue
|
||||
|
||||
if codename in info().all:
|
||||
if info().valid(codename):
|
||||
return distro
|
||||
|
@ -58,6 +58,12 @@ class DebianDistroInfoTestCase(unittest.TestCase):
|
||||
"""Test: Get latest testing Debian distribution."""
|
||||
self.assertEqual(self._distro_info.testing(self._date), "squeeze")
|
||||
|
||||
def test_valid(self):
|
||||
"""Test: Check for valid Debian distribution."""
|
||||
self.assertTrue(self._distro_info.valid("sid"))
|
||||
self.assertTrue(self._distro_info.valid("stable"))
|
||||
self.assertFalse(self._distro_info.valid("foobar"))
|
||||
|
||||
def test_unsupported(self):
|
||||
"""Test: List all unsupported Debian distribution."""
|
||||
unsupported = ["buzz", "rex", "bo", "hamm", "slink", "potato", "woody",
|
||||
@ -111,3 +117,8 @@ class UbuntuDistroInfoTestCase(unittest.TestCase):
|
||||
"gutsy", "intrepid", "jaunty"])
|
||||
self.assertEqual(unsupported -
|
||||
set(self._distro_info.unsupported()), set())
|
||||
|
||||
def test_valid(self):
|
||||
"""Test: Check for valid Ubuntu distribution."""
|
||||
self.assertTrue(self._distro_info.valid("lucid"))
|
||||
self.assertFalse(self._distro_info.valid("42"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user