def testSetupWorkdir(self): with make_rpm.Tempdir() as outer: dummy = os.sep.join([outer, 'rpmbuild']) WriteFile(dummy, 'dummy rpmbuild') os.chmod(dummy, 0o777) with PrependPath([outer]): # Create the builder and exercise it. builder = make_rpm.RpmBuilder('test', '1.0', '0', 'x86', None) # Create spec_file, test files. WriteFile('test.spec', 'Name: test', 'Version: 0.1', 'Summary: test data') WriteFile('file1.txt', 'Hello') WriteFile('file2.txt', 'Goodbye') builder.AddFiles(['file1.txt', 'file2.txt']) with make_rpm.Tempdir(): # Call RpmBuilder. builder.SetupWorkdir('test.spec', outer) # Make sure files exist. self.assertTrue(DirExists('SOURCES')) self.assertTrue(DirExists('BUILD')) self.assertTrue(DirExists('TMP')) self.assertTrue(FileExists('test.spec')) self.assertCountEqual( ['Name: test', 'Version: 1.0', 'Summary: test data'], FileContents('test.spec')) self.assertTrue(FileExists('BUILD/file1.txt')) self.assertCountEqual(['Hello'], FileContents('BUILD/file1.txt')) self.assertTrue(FileExists('BUILD/file2.txt')) self.assertCountEqual(['Goodbye'], FileContents('BUILD/file2.txt'))
def testBuild(self): with make_rpm.Tempdir() as outer: dummy = os.sep.join([outer, 'rpmbuild']) WriteFile( dummy, '#!/bin/sh', 'mkdir -p RPMS', 'touch RPMS/test.rpm', 'echo "Wrote: $PWD/RPMS/test.rpm"', ) os.chmod(dummy, 0o777) with PrependPath([outer]): # Create the builder and exercise it. builder = make_rpm.RpmBuilder('test', '1.0', '0', 'x86', None) # Create spec_file, test files. WriteFile('test.spec', 'Name: test', 'Version: 0.1', 'Summary: test data') # Call RpmBuilder. builder.Build('test.spec', 'test.rpm') # Make sure files exist. self.assertTrue(FileExists('test.rpm'))
def testFindRpmbuild_missing(self): with make_rpm.Tempdir() as outer: with ReplacePath([outer]): with self.assertRaises( make_rpm.NoRpmbuildFoundError) as context: make_rpm.FindRpmbuild('') self.assertIsNotNone(context)
def testFindRpmbuild_present(self): with make_rpm.Tempdir() as outer: dummy = os.sep.join([outer, 'rpmbuild']) WriteFile(dummy, 'dummy rpmbuild') os.chmod(dummy, 0o777) with PrependPath([outer]): path = make_rpm.FindRpmbuild('') self.assertEqual(dummy, path)
def testCopyAndRewrite(self): with make_rpm.Tempdir(): WriteFile('test.txt', 'Some: data1', 'Other: data2', 'More: data3') make_rpm.CopyAndRewrite('test.txt', 'out.txt', { 'Some:': 'data1a', 'More:': 'data3a', }) self.assertTrue(FileExists('out.txt')) self.assertCountEqual( ['Some: data1a', 'Other: data2', 'More: data3a'], FileContents('out.txt'))