Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/buildbot/buildbot/test/test_package_rpm.py
blob: 05d284178c838a8479180ac5190c612cb7952cb4 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# test step.package.rpm.*

from twisted.trial import unittest

from buildbot.test.runutils import SlaveCommandTestBase
from buildbot.steps.package.rpm import RpmBuild, RpmLint, RpmSpec


class TestRpmBuild(unittest.TestCase):
    """
    Tests the package.rpm.RpmBuild class.
    """

    def test_creation(self):
        """
        Test that instances are created with proper data.
        """
        rb = RpmBuild()
        self.assertEquals(rb.specfile, None)
        self.assertFalse(rb.autoRelease)
        self.assertFalse(rb.vcsRevision)

        rb2 = RpmBuild('aspec.spec', autoRelease=True, vcsRevision=True)
        self.assertEquals(rb2.specfile, 'aspec.spec')
        self.assertTrue(rb2.autoRelease)
        self.assertTrue(rb2.vcsRevision)

    def test_rpmbuild(self):
        """
        Verifies the rpmbuild string is what we would expect.
        """
        rb = RpmBuild('topdir', 'buildir', 'rpmdir', 'sourcedir',
            'specdir', 'dist')
        expected_result = ('rpmbuild --define "_topdir buildir"'
            ' --define "_builddir rpmdir" --define "_rpmdir sourcedir"'
            ' --define "_sourcedir specdir" --define "_specdir dist"'
            ' --define "_srcrpmdir `pwd`" --define "dist .el5"')
        self.assertEquals(rb.rpmbuild, expected_result)


class TestRpmLint(unittest.TestCase):
    """
    Tests the package.rpm.RpmLint class.
    """

    def test_command(self):
        """
        Test that instance command variable is created with proper data.
        """
        rl = RpmLint()
        expected_result = ["/usr/bin/rpmlint", "-i", '*rpm']
        self.assertEquals(rl.command, expected_result)


class TestRpmSpec(unittest.TestCase):
    """
    Tests the package.rpm.RpmSpec class.
    """

    def test_creation(self):
        """
        Test that instances are created with proper data.
        """
        rs = RpmSpec()
        self.assertEquals(rs.specfile, None)
        self.assertEquals(rs.pkg_name, None)
        self.assertEquals(rs.pkg_version, None)
        self.assertFalse(rs.loaded)

    def test_load(self):
        try:
            from cStringIO import StringIO
        except ImportError, ie:
            from StringIO import StringIO

        specfile = StringIO()
        specfile.write("""\
Name:           example
Version:        1.0.0
Release:        1%{?dist}
Summary:        An example spec

Group:          Development/Libraries
License:        GPLv2+
URL:            http://www.example.dom
Source0:        %{name}-%{version}.tar.gz
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildArch:      noarch
Requires:       python >= 2.4
BuildRequires:  python-setuptools


%description
An example spec for an rpm.


%prep
%setup -q


%build
%{__python} setup.py build


%install
rm -rf $RPM_BUILD_ROOT
%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT/


%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%doc INSTALL LICENSE AUTHORS COPYING
# For noarch packages: sitelib
%{python_sitelib}/*


%changelog
* Wed Jan  7 2009 Steve 'Ashcrow' Milner <smilner+buildbot@redhat.com> - \
1.0.0-1
- example""")
        specfile.flush()
        specfile.seek(0)
        rs = RpmSpec(specfile)
        rs.load()
        self.assertTrue(rs.loaded)
        self.assertEquals(rs.pkg_name, 'example')
        self.assertEquals(rs.pkg_version, '1.0.0')