]>
git.saurik.com Git - apt.git/blob - test/pre-upload-check.py
7 from subprocess
import call
, PIPE
11 stdout
= os
.open("/dev/null",0) #sys.stdout
12 stderr
= os
.open("/dev/null",0) # sys.stderr
14 apt_args
= [] # ["-o","Debug::pkgAcquire::Auth=true"]
17 class testAuthentication(unittest
.TestCase
):
19 # some class wide data
21 pkg
= "libglib2.0-data"
22 pkgver
= "2.13.6-1ubuntu1"
23 pkgpath
= "/var/cache/apt/archives/libglib2.0-data_2.13.6-1ubuntu1_all.deb"
26 for f
in glob
.glob("testkeys/*,key"):
27 call(["apt-key", "add", f
], stdout
=stdout
, stderr
=stderr
)
30 " make sure we get new lists and no i-m-s "
31 call(["rm","-f", "/var/lib/apt/lists/*"])
32 if os
.path
.exists(self
.pkgpath
):
33 os
.unlink(self
.pkgpath
)
35 def _expectedRes(self
, resultstr
):
38 elif resultstr
== 'broken':
42 def testPackages(self
):
43 for f
in glob
.glob("testsources.list/sources.list*package*"):
45 (prefix
, testtype
, result
) = f
.split("-")
46 expected_res
= self
._expectedRes
(result
)
48 call([self
.apt
,"update",
49 "-o","Dir::Etc::sourcelist=./%s" % f
]+apt_args
,
50 stdout
=stdout
, stderr
=stderr
)
52 cmd
= ["install", "-y", "-d", "--reinstall",
53 "%s=%s" % (self
.pkg
, self
.pkgver
),
54 "-o","Dir::state::Status=./fake-status"]
55 res
= call([self
.apt
, "-o","Dir::Etc::sourcelist=./%s" % f
]+cmd
+apt_args
,
56 stdout
=stdout
, stderr
=stderr
)
57 self
.assert_(res
== expected_res
,
58 "test '%s' failed (got %s expected %s" % (f
,res
,expected_res
))
62 for f
in glob
.glob("testsources.list/sources.list*gpg*"):
64 (prefix
, testtype
, result
) = f
.split("-")
65 expected_res
= self
._expectedRes
(result
)
67 call([self
.apt
,"update",
68 "-o","Dir::Etc::sourcelist=./%s" % f
]+apt_args
,
69 stdout
=stdout
, stderr
=stderr
)
71 cmd
= ["install", "-y", "-d", "--reinstall",
72 "%s=%s" % (self
.pkg
, self
.pkgver
),
73 "-o","Dir::state::Status=./fake-status"]
74 res
= call([self
.apt
, "-o","Dir::Etc::sourcelist=./%s" % f
]+
76 stdout
=stdout
, stderr
=stderr
)
77 self
.assert_(res
== expected_res
,
78 "test '%s' failed (got %s expected %s" % (f
,res
,expected_res
))
80 def testRelease(self
):
81 for f
in glob
.glob("testsources.list/sources.list*release*"):
83 (prefix
, testtype
, result
) = f
.split("-")
84 expected_res
= self
._expectedRes
(result
)
86 res
= call([self
.apt
,"-o","Dir::Etc::sourcelist=./%s" % f
]+cmd
+apt_args
,
87 stdout
=stdout
, stderr
=stderr
)
88 self
.assert_(res
== expected_res
,
89 "test '%s' failed (got %s expected %s" % (f
,res
,expected_res
))
93 class testLocalRepositories(unittest
.TestCase
):
94 " test local repository regressions "
96 repo_dir
= "local-repo"
101 self
.repo
= os
.path
.abspath(os
.path
.join(os
.getcwd(), self
.repo_dir
))
102 self
.sources
= os
.path
.join(self
.repo
, "sources.list")
103 s
= open(self
.sources
,"w")
104 s
.write("deb file://%s/ /\n" % self
.repo
)
107 def testLocalRepoAuth(self
):
108 # two times to get at least one i-m-s hit
110 self
.assert_(os
.path
.exists(self
.sources
))
111 cmd
= [self
.apt
,"update","-o", "Dir::Etc::sourcelist=%s" % self
.sources
]+apt_args
112 res
= call(cmd
, stdout
=stdout
, stderr
=stderr
)
113 self
.assertEqual(res
, 0, "local repo test failed")
114 self
.assert_(os
.path
.exists(os
.path
.join(self
.repo
,"Packages.gz")),
115 "Packages.gz vanished from local repo")
117 def testInstallFromLocalRepo(self
):
118 apt
= [self
.apt
,"-o", "Dir::Etc::sourcelist=%s"% self
.sources
]+apt_args
120 res
= call(cmd
, stdout
=stdout
, stderr
=stderr
)
121 self
.assertEqual(res
, 0)
122 res
= call(apt
+["-y","install","--reinstall",self
.pkg
],
123 stdout
=stdout
, stderr
=stderr
)
124 self
.assert_(res
== 0,
125 "installing %s failed (got %s)" % (self
.pkg
, res
))
126 res
= call(apt
+["-y","remove",self
.pkg
],
127 stdout
=stdout
, stderr
=stderr
)
128 self
.assert_(res
== 0,
129 "removing %s failed (got %s)" % (self
.pkg
, res
))
131 def testPythonAptInLocalRepo(self
):
133 apt_pkg
.Config
.Set("Dir::Etc::sourcelist",self
.sources
)
137 self
.assert_(pkg
.name
== 'apt')
141 if __name__
== "__main__":
142 print "Runing simple testsuit on current apt-get and libapt"
143 if len(sys
.argv
) > 1 and sys
.argv
[1] == "-v":