def test_sections_bzip2(self): """Test fetching sections from a basic TagFile archive using bzip2.""" self.useTempDir() main_dir = os.path.join("mirror", "dists", "unstable", "main") binary_dir = os.path.join(main_dir, "binary-i386") source_dir = os.path.join(main_dir, "source") os.makedirs(binary_dir) os.makedirs(source_dir) with bz2.BZ2File( os.path.join(binary_dir, "Packages.bz2"), "wb") as packages: packages.write(textwrap.dedent(b"""\ Package: test Version: 1.0 Architecture: i386 Maintainer: \xc3\xba\xe1\xb8\x83\xc3\xba\xc3\xb1\xc5\xa7\xc5\xaf\x20\xc4\x91\xc9\x99\x76\xe1\xba\xbd\xc5\x82\xc3\xb5\xe1\xb9\x97\xc3\xa8\xc5\x97\xe1\xb9\xa1 """.decode("UTF-8")).encode("UTF-8")) with bz2.BZ2File( os.path.join(source_dir, "Sources.bz2"), "wb") as sources: sources.write(textwrap.dedent("""\ Source: test Version: 1.0 """).encode("UTF-8")) tagfile = TagFile( "unstable", "main", "i386", "file://%s/mirror" % self.temp_dir) sections = list(tagfile.sections()) self.assertEqual(IndexType.PACKAGES, sections[0][0]) self.assertEqual("test", sections[0][1]["Package"]) self.assertEqual("1.0", sections[0][1]["Version"]) self.assertEqual("i386", sections[0][1]["Architecture"]) self.assertEqual(IndexType.SOURCES, sections[1][0]) self.assertEqual("test", sections[1][1]["Source"]) self.assertEqual("1.0", sections[1][1]["Version"])
def test_sections(self): """Test fetching sections from a basic TagFile archive.""" self.useTempDir() main_dir = os.path.join("mirror", "dists", "unstable", "main") binary_dir = os.path.join(main_dir, "binary-i386") source_dir = os.path.join(main_dir, "source") os.makedirs(binary_dir) os.makedirs(source_dir) packages = gzip.GzipFile(os.path.join(binary_dir, "Packages.gz"), "w") try: packages.write(textwrap.dedent("""\ Package: test Version: 1.0 Architecture: i386 """).encode("UTF-8")) finally: packages.close() sources = gzip.GzipFile(os.path.join(source_dir, "Sources.gz"), "w") try: sources.write(textwrap.dedent("""\ Source: test Version: 1.0 """).encode("UTF-8")) finally: sources.close() tagfile = TagFile( "unstable", "main", "i386", "file://%s/mirror" % self.temp_dir) sections = list(tagfile.sections()) self.assertEqual(IndexType.PACKAGES, sections[0][0]) self.assertEqual("test", sections[0][1]["Package"]) self.assertEqual("1.0", sections[0][1]["Version"]) self.assertEqual("i386", sections[0][1]["Architecture"]) self.assertEqual(IndexType.SOURCES, sections[1][0]) self.assertEqual("test", sections[1][1]["Source"]) self.assertEqual("1.0", sections[1][1]["Version"])
def test_sections_bzip2(self): """Test fetching sections from a basic TagFile archive using bzip2.""" self.useTempDir() main_dir = os.path.join("mirror", "dists", "unstable", "main") binary_dir = os.path.join(main_dir, "binary-i386") source_dir = os.path.join(main_dir, "source") os.makedirs(binary_dir) os.makedirs(source_dir) with bz2.BZ2File(os.path.join(binary_dir, "Packages.bz2"), "wb") as packages: packages.write( textwrap.dedent(b"""\ Package: test Version: 1.0 Architecture: i386 Maintainer: \xc3\xba\xe1\xb8\x83\xc3\xba\xc3\xb1\xc5\xa7\xc5\xaf\x20\xc4\x91\xc9\x99\x76\xe1\xba\xbd\xc5\x82\xc3\xb5\xe1\xb9\x97\xc3\xa8\xc5\x97\xe1\xb9\xa1 """.decode("UTF-8")).encode("UTF-8")) with bz2.BZ2File(os.path.join(source_dir, "Sources.bz2"), "wb") as sources: sources.write( textwrap.dedent("""\ Source: test Version: 1.0 """).encode("UTF-8")) tagfile = TagFile("unstable", "main", "i386", "file://%s/mirror" % self.temp_dir) sections = list(tagfile.sections()) self.assertEqual(IndexType.PACKAGES, sections[0][0]) self.assertEqual("test", sections[0][1]["Package"]) self.assertEqual("1.0", sections[0][1]["Version"]) self.assertEqual("i386", sections[0][1]["Architecture"]) self.assertEqual(IndexType.SOURCES, sections[1][0]) self.assertEqual("test", sections[1][1]["Source"]) self.assertEqual("1.0", sections[1][1]["Version"])
def test_sections_gzip(self): """Test fetching sections from a basic TagFile archive using gzip.""" self.useTempDir() main_dir = os.path.join("mirror", "dists", "unstable", "main") binary_dir = os.path.join(main_dir, "binary-i386") source_dir = os.path.join(main_dir, "source") os.makedirs(binary_dir) os.makedirs(source_dir) with gzip.GzipFile(os.path.join(binary_dir, "Packages.gz"), "wb") as packages: packages.write( textwrap.dedent(u"""\ Package: test Version: 1.0 Architecture: i386 Maintainer: úḃúñŧů đəvẽłõṗèŗṡ """).encode("UTF-8")) with gzip.GzipFile(os.path.join(source_dir, "Sources.gz"), "wb") as sources: sources.write( textwrap.dedent("""\ Source: test Version: 1.0 """).encode("UTF-8")) tagfile = TagFile("unstable", "main", "i386", "file://%s/mirror" % self.temp_dir) sections = list(tagfile.sections()) self.assertEqual(IndexType.PACKAGES, sections[0][0]) self.assertEqual("test", sections[0][1]["Package"]) self.assertEqual("1.0", sections[0][1]["Version"]) self.assertEqual("i386", sections[0][1]["Architecture"]) self.assertEqual(IndexType.SOURCES, sections[1][0]) self.assertEqual("test", sections[1][1]["Source"]) self.assertEqual("1.0", sections[1][1]["Version"])