From 0d622864bf45b2826335b3be31330829f43db7cd Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 2 Sep 2010 16:55:43 +0200 Subject: merged patch from Samuel Lidén Borell to fix crash if there utf8 in the control file (LP: #624290) and add test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/data/test_debs/utf8-package_1.0-1_all.deb | Bin 0 -> 1150 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/data/test_debs/utf8-package_1.0-1_all.deb (limited to 'tests/data') diff --git a/tests/data/test_debs/utf8-package_1.0-1_all.deb b/tests/data/test_debs/utf8-package_1.0-1_all.deb new file mode 100644 index 00000000..e0339c2e Binary files /dev/null and b/tests/data/test_debs/utf8-package_1.0-1_all.deb differ -- cgit v1.2.3 From 6809becd9c7dccc797dde7be2046cad55712c5de Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 3 Sep 2010 18:18:18 +0200 Subject: not not depend on network when running the tests, some style fixes (thanks to Jak for the code-review) --- tests/data/test-repo/Packages.gz | Bin 0 -> 675 bytes tests/test_apt_cache.py | 13 +++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 tests/data/test-repo/Packages.gz (limited to 'tests/data') diff --git a/tests/data/test-repo/Packages.gz b/tests/data/test-repo/Packages.gz new file mode 100644 index 00000000..81daf2bb Binary files /dev/null and b/tests/data/test-repo/Packages.gz differ diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 054ef8b2..22af97f2 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -94,20 +94,21 @@ class TestAptCache(unittest.TestCase): # test single sources.list fetching sources_list = "./data/tmp/test.list" - f=open(sources_list,"w") - f.write("deb http://archive.ubuntu.com/ubuntu lucid restricted\n") + f=open(sources_list, "w") + repo = os.path.abspath("./data/test-repo") + f.write("deb copy:%s /\n" % repo) f.close() self.assertTrue(os.path.exists(sources_list)) # write marker to ensure listcleaner is not run - open("./data/tmp/var/lib/apt/lists/marker","w") + open("./data/tmp/var/lib/apt/lists/marker", "w") # update a single sources.list cache = apt.Cache() cache.update(sources_list=sources_list) # verify we just got a single source - files = filter(lambda f: not (f == "lock" or f == "partial"), + files = filter(lambda f: f not in ("lock", "partial"), os.listdir("./data/tmp/var/lib/apt/lists")) - self.assertTrue("archive.ubuntu.com_ubuntu_dists_lucid_Release" in files) + self.assertEqual(len([f for f in files if f.endswith("tests_data_test-repo_Packages")]), 1) # ensure the listcleaner was not run self.assertTrue("marker" in files) # ensure we don't get additional stuff from /etc/apt/sources.list @@ -115,7 +116,7 @@ class TestAptCache(unittest.TestCase): # now run update again and verify that we got the normal sources.list cache.update() - full_update = filter(lambda f: not (f == "lock" or f == "partial"), + full_update = filter(lambda f: f not in ("lock", "partial"), os.listdir("./data/tmp/var/lib/apt/lists")) self.assertTrue(len(files) < len(full_update)) -- cgit v1.2.3 From b390a866fc3af9e7050148f11fb558fd52a8a703 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 7 Sep 2010 13:13:29 +0200 Subject: tests/test_apt_cache.py: improve the tests so that they do not require a working network --- tests/data/test-repo2/Packages.gz | Bin 0 -> 675 bytes tests/test_apt_cache.py | 63 ++++++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 tests/data/test-repo2/Packages.gz (limited to 'tests/data') diff --git a/tests/data/test-repo2/Packages.gz b/tests/data/test-repo2/Packages.gz new file mode 100644 index 00000000..81daf2bb Binary files /dev/null and b/tests/data/test-repo2/Packages.gz differ diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 22af97f2..428060f3 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -86,17 +86,31 @@ class TestAptCache(unittest.TestCase): apt_pkg.config.set("Dir::State::status", old_status) def test_apt_update(self): + rootdir = "./data/tmp" + shutil.rmtree(rootdir) try: - os.makedirs("./data/tmp/var/lib/apt/lists/partial") + os.makedirs(os.path.join(rootdir, "var/lib/apt/lists/partial")) except OSError, e: pass - apt_pkg.config.set("dir::state", "./data/tmp/var/lib/apt") + state_dir = os.path.join(rootdir, "var/lib/apt") + lists_dir = os.path.join(rootdir, "var/lib/apt/lists") + apt_pkg.config.set("dir::state", state_dir) + # set a local sources.list that does not need the network + base_sources = os.path.abspath(os.path.join(rootdir, "sources.list")) + apt_pkg.config.set("dir::etc::sourcelist", base_sources) + apt_pkg.config.set("dir::etc::sourceparts", "xxx") + # main sources.list + sources_list = base_sources + f=open(sources_list, "w") + repo = os.path.abspath("./data/test-repo2") + f.write("deb copy:%s /\n" % repo) + f.close() # test single sources.list fetching - sources_list = "./data/tmp/test.list" + sources_list = os.path.join(rootdir, "test.list") f=open(sources_list, "w") - repo = os.path.abspath("./data/test-repo") - f.write("deb copy:%s /\n" % repo) + repo_dir = os.path.abspath("./data/test-repo") + f.write("deb copy:%s /\n" % repo_dir) f.close() self.assertTrue(os.path.exists(sources_list)) # write marker to ensure listcleaner is not run @@ -105,23 +119,34 @@ class TestAptCache(unittest.TestCase): # update a single sources.list cache = apt.Cache() cache.update(sources_list=sources_list) - # verify we just got a single source - files = filter(lambda f: f not in ("lock", "partial"), - os.listdir("./data/tmp/var/lib/apt/lists")) - self.assertEqual(len([f for f in files if f.endswith("tests_data_test-repo_Packages")]), 1) - # ensure the listcleaner was not run - self.assertTrue("marker" in files) - # ensure we don't get additional stuff from /etc/apt/sources.list - self.assertTrue(len(files) < 5) + # verify we just got the excpected package file + needle_packages = [f for f in os.listdir(lists_dir) + if f.endswith("tests_data_test-repo_Packages")] + self.assertEqual(len(needle_packages), 1) + # verify that we *only* got the Packages file from a single source + all_packages = [f for f in os.listdir(lists_dir) + if f.endswith("_Packages")] + self.assertEqual(needle_packages, all_packages) + # verify that the listcleaner was not run and the marker file is + # still there + self.assertTrue("marker" in os.listdir(lists_dir)) - # now run update again and verify that we got the normal sources.list + # now run update again (without the "normal" sources.list that + # contains test-repo2 and verify that we got the normal sources.list cache.update() - full_update = filter(lambda f: f not in ("lock", "partial"), - os.listdir("./data/tmp/var/lib/apt/lists")) - self.assertTrue(len(files) < len(full_update)) + needle_packages = [f for f in os.listdir(lists_dir) + if f.endswith("tests_data_test-repo2_Packages")] + self.assertEqual(len(needle_packages), 1) + all_packages = [f for f in os.listdir(lists_dir) + if f.endswith("_Packages")] + self.assertEqual(needle_packages, all_packages) - # cleanup - shutil.rmtree("./data/tmp/") + # and another update with a single source only + cache = apt.Cache() + cache.update(sources_list=sources_list) + all_packages = [f for f in os.listdir(lists_dir) + if f.endswith("_Packages")] + self.assertEqual(len(all_packages), 2) if __name__ == "__main__": unittest.main() -- cgit v1.2.3