02_test_upstream_source_tar_unpack.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # vim: set fileencoding=utf-8 :
  2. """Test L{UpstreamSource}'s tarball unpack"""
  3. from . import context
  4. import os
  5. import tarfile
  6. import unittest
  7. import six
  8. import gbp.pkg
  9. class TestUnpack(unittest.TestCase):
  10. """Make sure we unpack gzip and bzip2 archives correctly"""
  11. archive_prefix = "archive"
  12. def _unpack_dir(self, compression):
  13. return "%s-%s" % (self.archive_prefix, compression)
  14. def _check_files(self, files, comp):
  15. """Check if files exist in the unpacked dir"""
  16. for f in files:
  17. target = os.path.join(self._unpack_dir(comp), f)
  18. assert os.path.exists(target), "%s does not exist" % target
  19. def _create_archive(self, comp):
  20. filelist = [ 'README', 'setup.py' ]
  21. name = "%s_0.1.tar.%s" % (self.archive_prefix, comp)
  22. t = tarfile.open(name= name, mode='w:%s' % comp)
  23. for f in filelist:
  24. t.add(os.path.join(self.top, f),
  25. os.path.join(self._unpack_dir(comp), f))
  26. t.close()
  27. return name, filelist
  28. def setUp(self):
  29. self.dir = context.new_tmpdir(__name__)
  30. self.top = context.projectdir
  31. context.chdir(self.dir)
  32. self.archives = {}
  33. for ext in [ "gz", "bz2" ]:
  34. self.archives[ext] = self._create_archive(ext)
  35. def tearDown(self):
  36. context.teardown()
  37. def test_upstream_source_type(self):
  38. for (comp, archive) in six.iteritems(self.archives):
  39. source = gbp.pkg.UpstreamSource(archive[0])
  40. assert source.is_orig() == True
  41. assert source.is_dir() == False
  42. assert source.unpacked == None
  43. source.unpack(".")
  44. assert source.is_orig() == True
  45. assert source.is_dir() == False
  46. assert type(source.unpacked) == str
  47. def test_upstream_source_unpack(self):
  48. for (comp, archive) in six.iteritems(self.archives):
  49. source = gbp.pkg.UpstreamSource(archive[0])
  50. source.unpack(".")
  51. self._check_files(archive[1], comp)
  52. def test_upstream_source_unpack_no_filter(self):
  53. for (comp, archive) in six.iteritems(self.archives):
  54. source = gbp.pkg.UpstreamSource(archive[0])
  55. source.unpack(".", [])
  56. self._check_files(archive[1], comp)
  57. def test_upstream_source_unpack_filtered(self):
  58. exclude = "README"
  59. for (comp, archive) in six.iteritems(self.archives):
  60. source = gbp.pkg.UpstreamSource(archive[0])
  61. source.unpack(".", [exclude])
  62. archive[1].remove(exclude)
  63. self._check_files(archive[1], comp)
  64. # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: