From 377fcb6948252eec3d0b9908834ced66aed53901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 26 Apr 2016 14:55:46 +0200 Subject: [PATCH] [pkgset] Add tests for writing filelists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lubomír Sedlář --- tests/test_pkgset_pkgsets.py | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/test_pkgset_pkgsets.py b/tests/test_pkgset_pkgsets.py index 488bc3e0..3a1d6288 100755 --- a/tests/test_pkgset_pkgsets.py +++ b/tests/test_pkgset_pkgsets.py @@ -7,6 +7,7 @@ import sys import unittest import json import functools +import tempfile sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) @@ -374,5 +375,44 @@ class TestMergePackageSets(PkgsetCompareMixin, unittest.TestCase): 'nosrc': []}) +@mock.patch('kobo.pkgset.FileCache', new=MockFileCache) +class TestSaveFileList(unittest.TestCase): + def setUp(self): + fd, self.tmpfile = tempfile.mkstemp() + os.close(fd) + + def tearDown(self): + os.unlink(self.tmpfile) + + def test_save_arches_alphabetically(self): + pkgset = pkgsets.PackageSetBase([None]) + for name in ['rpms/pungi@4.1.3@3.fc25@x86_64', + 'rpms/pungi@4.1.3@3.fc25@src', + 'rpms/pungi@4.1.3@3.fc25@ppc64']: + pkg = pkgset.file_cache.add(name) + pkgset.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) + + pkgset.save_file_list(self.tmpfile) + + with open(self.tmpfile) as f: + rpms = f.read().strip().split('\n') + self.assertEqual(rpms, ['rpms/pungi@4.1.3@3.fc25@ppc64', + 'rpms/pungi@4.1.3@3.fc25@src', + 'rpms/pungi@4.1.3@3.fc25@x86_64']) + + def test_save_strip_prefix(self): + pkgset = pkgsets.PackageSetBase([None]) + for name in ['rpms/pungi@4.1.3@3.fc25@noarch', 'rpms/pungi@4.1.3@3.fc25@src']: + pkg = pkgset.file_cache.add(name) + pkgset.rpms_by_arch.setdefault(pkg.arch, []).append(pkg) + + pkgset.save_file_list(self.tmpfile, remove_path_prefix='rpms/') + + with open(self.tmpfile) as f: + rpms = f.read().strip().split('\n') + self.assertItemsEqual(rpms, ['pungi@4.1.3@3.fc25@noarch', + 'pungi@4.1.3@3.fc25@src']) + + if __name__ == "__main__": unittest.main()