-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathtest_distro.py
More file actions
63 lines (54 loc) · 2.47 KB
/
test_distro.py
File metadata and controls
63 lines (54 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from patchwork import info
import unittest
from unittest import TestCase
import mock
from patchwork.info import lsb_release_info
ubuntu1104_lsb_info = lsb_release_info('No LSB modules are available.',
'Ubuntu',
'Ubuntu 11.04',
'11.04',
'natty')
amazon2012_03_lsb_info = lsb_release_info(':core-4.0-amd64:core-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch',
'AmazonAMI',
'Amazon Linux AMI release 2012.03',
'2012.03',
'n/a')
class DistroNameDetection(TestCase):
@mock.patch('patchwork.info.lsb_release')
@mock.patch('patchwork.info.run')
def test_ubuntu_detection_via_lsb_release(self, run, lsb_release):
lsb_release.return_value = ubuntu1104_lsb_info
self.assertEqual(info.distro_name(), 'ubuntu')
lsb_release.assert_called()
self.assertFalse(run.called)
@mock.patch('patchwork.info.lsb_release')
@mock.patch('patchwork.info.run')
def test_amazon_detection_via_lsb_release(self, run, lsb_release):
lsb_release.return_value = amazon2012_03_lsb_info
self.assertEqual(info.distro_name(), 'amazon')
lsb_release.assert_called()
self.assertFalse(run.called)
class DistroFamilyDetection(TestCase):
@mock.patch('patchwork.info.distro_name')
@mock.patch('patchwork.info.run')
def test_debian_family(self, run, distro_name_fxn):
for d in ('ubuntu', 'debian'):
distro_name_fxn.return_value = d
self.assertEqual('debian', info.distro_family())
self.assertFalse(run.called)
@mock.patch('patchwork.info.distro_name')
@mock.patch('patchwork.info.run')
def test_redhat_family(self, run, distro_name_fxn):
for d in ('redhat', 'centos', 'fedora', 'amazon'):
distro_name_fxn.return_value = d
self.assertEqual('redhat', info.distro_family())
self.assertFalse(run.called)
@mock.patch('patchwork.info.exists')
@mock.patch('patchwork.info.distro_name')
@mock.patch('patchwork.info.run')
def test_family_inference(self, run, distro_name_fxn, file_exists):
"""If debian_version exists, then it should be picked up as debian-family,
even if exact type couldn't be worked out."""
distro_name_fxn.return_value = 'other'
file_exists.side_effect = lambda s: s == '/etc/debian_version'
self.assertEqual('debian', info.distro_family())