~deeptik/lava-test/openposix

« back to all changes in this revision

Viewing changes to tests/test_swprofile.py

  • Committer: Paul Larson
  • Date: 2010-08-06 16:54:27 UTC
  • mfrom: (19.1.1 swprofile)
  • Revision ID: paul.larson@canonical.com-20100806165427-jh701vac3f4gotuu
Add support for gathering software profile information from the system

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import unittest
 
2
 
 
3
import abrek.swprofile
 
4
 
 
5
class Version:
 
6
    def __init__(self, version):
 
7
        self.version = version
 
8
 
 
9
class Package:
 
10
    def __init__(self, name, version, is_installed=True):
 
11
        self.is_installed = is_installed
 
12
        self.name = name
 
13
        self.installed = Version(version)
 
14
 
 
15
class AptCache:
 
16
    def __init__(self, packages=[]):
 
17
        self.packages = packages
 
18
 
 
19
    def __iter__(self):
 
20
        return iter(self.packages)
 
21
 
 
22
class SwprofileTests(unittest.TestCase):
 
23
    def setUp(self):
 
24
        self.lsb_desc = 'test description'
 
25
        self.lsb_information = {'DESCRIPTION':self.lsb_desc}
 
26
        self.testpackage = Package('testpkg', '7.77')
 
27
        self.cache = AptCache([self.testpackage])
 
28
 
 
29
    def make_profile(self, test_id='unit', cache=None, info=None):
 
30
        if cache == None:
 
31
            cache = self.cache
 
32
        if info == None:
 
33
            info = self.lsb_information
 
34
        return abrek.swprofile.get_sw_context(test_id, apt_cache=cache,
 
35
                lsb_information=info)
 
36
 
 
37
    def test_pkg_name(self):
 
38
        a = self.make_profile()
 
39
        for pkg in a['packages']:
 
40
            self.assertEqual(self.testpackage.name, pkg['name'])
 
41
 
 
42
    def test_pkg_version(self):
 
43
        a = self.make_profile()
 
44
        for pkg in a['packages']:
 
45
            self.assertEqual(self.testpackage.installed.version, pkg['version'])
 
46
 
 
47
    def test_image_desc(self):
 
48
        a = self.make_profile()
 
49
        self.assertEqual(self.lsb_desc, a['sw_image']['desc'])
 
50