Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _parse(self, command):
sys.argv = command.split()
distro.main()
def test_lsb_release_nomodules(self):
self._setup_for_distro(os.path.join(TESTDISTROS, 'lsb',
'ubuntu14_nomodules'))
distroi = distro.LinuxDistribution(True, 'non', 'non')
self.assertEqual(distroi.id(), 'ubuntu')
self.assertEqual(distroi.name(), 'Ubuntu')
self.assertEqual(distroi.name(pretty=True), 'Ubuntu 14.04.3 LTS')
self.assertEqual(distroi.version(), '14.04')
self.assertEqual(distroi.version(pretty=True), '14.04 (trusty)')
self.assertEqual(distroi.version(best=True), '14.04.3')
self.assertEqual(distroi.like(), '')
self.assertEqual(distroi.codename(), 'trusty')
def test_arch_release(self):
self._setup_for_distro(os.path.join(DISTROS, 'arch'))
distroi = distro.LinuxDistribution()
self.assertEqual(distroi.id(), 'arch')
self.assertEqual(distroi.name(), 'Arch Linux')
self.assertEqual(distroi.name(pretty=True), 'Arch Linux')
# Arch Linux has a continuous release concept:
self.assertEqual(distroi.version(), '')
self.assertEqual(distroi.version(pretty=True), '')
self.assertEqual(distroi.version(best=True), '')
self.assertEqual(distroi.like(), '')
self.assertEqual(distroi.codename(), '')
# Test the info from the searched distro release file
# Does not have one; The empty /etc/arch-release file is not
# considered a valid distro release file:
self.assertEqual(distroi.distro_release_file, '')
self.assertEqual(len(distroi.distro_release_info()), 0)
def test_linux_distribution(self):
_distro = distro.LinuxDistribution(False, self.ubuntu14_os_release)
i = _distro.linux_distribution()
assert i == ('Ubuntu', '14.04', 'Trusty Tahr')
def test_kvmibm1_dist_release(self):
distro_release = os.path.join(DISTROS, 'kvmibm1', 'etc',
'base-release')
distroi = distro.LinuxDistribution(False, 'non', distro_release)
self.assertEqual(distroi.id(), 'base')
self.assertEqual(distroi.name(), 'KVM for IBM z Systems')
self.assertEqual(distroi.name(pretty=True), 'KVM for IBM z Systems 1.1.1 (Z)')
self.assertEqual(distroi.version(), '1.1.1')
self.assertEqual(distroi.version(pretty=True), '1.1.1 (Z)')
self.assertEqual(distroi.version(best=True), '1.1.1')
self.assertEqual(distroi.like(), '')
self.assertEqual(distroi.codename(), 'Z')
def test_lsb_release_rc130(self):
self._setup_for_distro(os.path.join(TESTDISTROS, 'lsb', 'lsb_rc130'))
try:
distroi = distro.LinuxDistribution(True, 'non', 'non')
exc = None
except Exception as _exc:
exc = _exc
self.assertEqual(isinstance(exc, subprocess.CalledProcessError), True)
self.assertEqual(exc.returncode, 130)
def _test_attr(self, info_method, attr_method):
for dist in DISTROS:
self._setup_for_distro(os.path.join(DISTROS_DIR, dist))
_distro = distro.LinuxDistribution()
info = getattr(_distro, info_method)()
for key in info.keys():
try:
assert info[key] == getattr(_distro, attr_method)(key)
except AssertionError:
print("distro: {0}, key: {1}".format(dist, key))
def test_debian8_release(self):
self._setup_for_distro(os.path.join(DISTROS, 'debian8'))
distroi = distro.LinuxDistribution()
self.assertEqual(distroi.id(), 'debian')
self.assertEqual(distroi.name(), 'Debian GNU/Linux')
self.assertEqual(distroi.name(pretty=True), 'Debian GNU/Linux 8 (jessie)')
self.assertEqual(distroi.version(), '8')
self.assertEqual(distroi.version(pretty=True), '8 (jessie)')
self.assertEqual(distroi.version(best=True), '8.2')
self.assertEqual(distroi.like(), '')
self.assertEqual(distroi.codename(), 'jessie')
# Test the info from the searched distro release file
# Does not have one:
self.assertEqual(distroi.distro_release_file, '')
self.assertEqual(len(distroi.distro_release_info()), 0)
def test_rhel7_os_release(self):
os_release = os.path.join(DISTROS, 'rhel7', 'etc', 'os-release')
distroi = distro.LinuxDistribution(False, os_release, 'non')
self.assertEqual(distroi.id(), 'rhel')
self.assertEqual(distroi.name(), 'Red Hat Enterprise Linux Server')
self.assertEqual(
distroi.name(pretty=True),
'Red Hat Enterprise Linux Server 7.0 (Maipo)')
self.assertEqual(distroi.version(), '7.0')
self.assertEqual(distroi.version(pretty=True), '7.0 (Maipo)')
self.assertEqual(distroi.version(best=True), '7.0')
self.assertEqual(distroi.like(), 'fedora')
self.assertEqual(distroi.codename(), 'Maipo')
def test_cli(self):
command = [sys.executable, '-m', 'distro']
desired_output = 'Name: ' + distro.name(pretty=True)
distro_version = distro.version(pretty=True)
distro_codename = distro.codename()
desired_output += '\n' + 'Version: ' + distro_version
desired_output += '\n' + 'Codename: ' + distro_codename
desired_output += '\n'
assert self._run(command) == desired_output