pre-upload-check.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/usr/bin/python
  2. import sys
  3. import os
  4. import glob
  5. import os.path
  6. from subprocess import call, PIPE
  7. import unittest
  8. stdout = os.open("/dev/null",0) #sys.stdout
  9. stderr = os.open("/dev/null",0) # sys.stderr
  10. class testAuthentication(unittest.TestCase):
  11. # some class wide data
  12. apt = "apt-get"
  13. args = [] # ["-q", "-q", "-o","Debug::pkgAcquire::Auth=true"]
  14. pkg = "libglib2.0-data"
  15. pkgver = "2.13.6-1ubuntu1"
  16. pkgpath = "/var/cache/apt/archives/libglib2.0-data_2.13.6-1ubuntu1_all.deb"
  17. def setUp(self):
  18. for f in glob.glob("testkeys/*,key"):
  19. call(["apt-key", "add", f], stdout=stdout, stderr=stderr)
  20. def _cleanup(self):
  21. " make sure we get new lists and no i-m-s "
  22. call(["rm","-f", "/var/lib/apt/lists/*"])
  23. if os.path.exists(self.pkgpath):
  24. os.unlink(self.pkgpath)
  25. def _expectedRes(self, resultstr):
  26. if resultstr == 'ok':
  27. return 0
  28. elif resultstr == 'broken':
  29. return 100
  30. def testPackages(self):
  31. for f in glob.glob("testsources.list/sources.list*package*"):
  32. self._cleanup()
  33. (prefix, testtype, result) = f.split("-")
  34. expected_res = self._expectedRes(result)
  35. # update first
  36. call([self.apt,"update",
  37. "-o","Dir::Etc::sourcelist=./%s" % f]+self.args,
  38. stdout=stdout, stderr=stderr)
  39. # then get the pkg
  40. cmd = ["install", "-y", "-d", "--reinstall",
  41. "%s=%s" % (self.pkg, self.pkgver),
  42. "-o","Dir::state::Status=./fake-status"]
  43. res = call([self.apt, "-o","Dir::Etc::sourcelist=./%s" % f]+cmd+self.args,
  44. stdout=stdout, stderr=stderr)
  45. self.assert_(res == expected_res,
  46. "test '%s' failed (got %s expected %s" % (f,res,expected_res))
  47. def testGPG(self):
  48. for f in glob.glob("testsources.list/sources.list*gpg*"):
  49. self._cleanup()
  50. (prefix, testtype, result) = f.split("-")
  51. expected_res = self._expectedRes(result)
  52. # update first
  53. call([self.apt,"update",
  54. "-o","Dir::Etc::sourcelist=./%s" % f]+self.args,
  55. stdout=stdout, stderr=stderr)
  56. # then get the pkg
  57. cmd = ["install", "-y", "-d", "--reinstall",
  58. "%s=%s" % (self.pkg, self.pkgver),
  59. "-o","Dir::state::Status=./fake-status"]
  60. res = call([self.apt, "-o","Dir::Etc::sourcelist=./%s" % f]+
  61. cmd+self.args,
  62. stdout=stdout, stderr=stderr)
  63. self.assert_(res == expected_res,
  64. "test '%s' failed (got %s expected %s" % (f,res,expected_res))
  65. def testRelease(self):
  66. for f in glob.glob("testsources.list/sources.list*release*"):
  67. self._cleanup()
  68. (prefix, testtype, result) = f.split("-")
  69. expected_res = self._expectedRes(result)
  70. cmd = ["update"]
  71. res = call([self.apt,"-o","Dir::Etc::sourcelist=./%s" % f]+cmd+self.args,
  72. stdout=stdout, stderr=stderr)
  73. self.assert_(res == expected_res,
  74. "test '%s' failed (got %s expected %s" % (f,res,expected_res))
  75. class testPythonApt(unittest.TestCase):
  76. " test if python-apt is still working and if we not accidently broke the ABI "
  77. def testPythonApt(self):
  78. import apt
  79. cache = apt.Cache()
  80. cache.update()
  81. pkg = cache["apt"]
  82. self.assert_(pkg.name == 'apt')
  83. class testAptInstall(unittest.TestCase):
  84. " test if installing still works "
  85. apt = "apt-get"
  86. pkg = "coreutils"
  87. def testInstall(self):
  88. res = call([self.apt,"-y","install","--reinstall",self.pkg],
  89. stdout=stdout, stderr=stderr)
  90. self.assert_(res == 0,
  91. "installing %s failed (got %s)" % (self.pkg, res))
  92. if __name__ == "__main__":
  93. print "Runing simple testsuit on current apt-get and libapt"
  94. if len(sys.argv) > 1 and sys.argv[1] == "-v":
  95. stdout = sys.stdout
  96. stderr = sys.stderr
  97. unittest.main()