summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2012-06-29 16:10:40 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2012-06-29 16:10:40 +0200
commit794e9321c92aab78c3b7123d765967ba67b79851 (patch)
tree9886905374b0ae9bc0043f12be0797c6f8f0af35 /tests
parent43aee9eda68e374067d6d6a9c4dd3c3e9b986041 (diff)
parent6ec2e17ae6712655c1bacffa8c6ecde5f8810960 (diff)
downloadpython-apt-794e9321c92aab78c3b7123d765967ba67b79851.tar.gz
merged from debian-sid
Diffstat (limited to 'tests')
-rwxr-xr-xtests/fakeroot-apt-key2
-rw-r--r--tests/test_auth.py14
-rw-r--r--tests/test_lp659438.py4
-rw-r--r--tests/test_tagfile.py93
4 files changed, 108 insertions, 5 deletions
diff --git a/tests/fakeroot-apt-key b/tests/fakeroot-apt-key
index 7be99711..997161a1 100755
--- a/tests/fakeroot-apt-key
+++ b/tests/fakeroot-apt-key
@@ -1,2 +1,2 @@
#!/bin/sh
-fakeroot /usr/bin/apt-key $*
+exec fakeroot /usr/bin/apt-key $*
diff --git a/tests/test_auth.py b/tests/test_auth.py
index f975c670..99c40db5 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -7,7 +7,7 @@ import tempfile
import time
import unittest
-if sys.version_info.major > 2:
+if sys.version_info[0] > 2:
from http.server import HTTPServer
from http.server import SimpleHTTPRequestHandler as HTTPRequestHandler
else:
@@ -107,6 +107,18 @@ class TestAuthKeys(unittest.TestCase):
"""Test handling of keys for signed repositories."""
+ if sys.version_info[0] == 2 and sys.version_info[1] < 7:
+ def addCleanup(self, function, *args, **kwds):
+ try:
+ self.cleanup.append(lambda: function(*args, **kwds))
+ except AttributeError:
+ self.cleanup = [lambda: function(*args, **kwds)]
+
+ def tearDown(self):
+ for f in self.cleanup:
+ f()
+ self.cleanup = []
+
def setUp(self):
# reset any config manipulations done in the individual tests
apt_pkg.init_config()
diff --git a/tests/test_lp659438.py b/tests/test_lp659438.py
index 01edf3bd..4564f0f6 100644
--- a/tests/test_lp659438.py
+++ b/tests/test_lp659438.py
@@ -39,8 +39,7 @@ class RegressionTestCase(unittest.TestCase):
def setUp(self):
apt_pkg.init_config()
- chroot_path = tempfile.mkdtemp()
- self.addCleanup(lambda: shutil.rmtree(chroot_path))
+ self.chroot_path = chroot_path = tempfile.mkdtemp()
# Create a damaged status file
self.cache = apt.cache.Cache(rootdir=chroot_path)
with open(apt_pkg.config.find_file("Dir::State::status"),
@@ -62,6 +61,7 @@ Version: 3.6.9+build1+nobinonly-0ubuntu1""")
# this resets the rootdir apt_pkg.config to ensure it does not
# "pollute" the later tests
cache = apt.cache.Cache(rootdir="/")
+ shutil.rmtree(self.chroot_path)
def test_survive_reqreinst(self):
"""Test that we survive a package in require reinstallation state"""
diff --git a/tests/test_tagfile.py b/tests/test_tagfile.py
index 371cc6ee..33197e6a 100644
--- a/tests/test_tagfile.py
+++ b/tests/test_tagfile.py
@@ -1,18 +1,26 @@
#!/usr/bin/python
+# -*- coding: utf-8 -*-
#
# Copyright (C) 2010 Michael Vogt <mvo@ubuntu.com>
+# Copyright (C) 2012 Canonical Ltd.
+# Author: Colin Watson <cjwatson@ubuntu.com>
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.
"""Unit tests for verifying the correctness of apt_pkg.TagFile"""
+from __future__ import print_function, unicode_literals
+
+import io
import glob
import os
+import shutil
+import sys
+import tempfile
import unittest
from test_all import get_library_dir
-import sys
sys.path.insert(0, get_library_dir())
import apt_pkg
@@ -20,6 +28,13 @@ import apt_pkg
class TestTagFile(unittest.TestCase):
""" test the apt_pkg.TagFile """
+ def setUp(self):
+ apt_pkg.init()
+ self.temp_dir = tempfile.mkdtemp()
+
+ def tearDown(self):
+ shutil.rmtree(self.temp_dir)
+
def test_tag_file(self):
basepath = os.path.dirname(__file__)
tagfilepath = os.path.join(basepath, "./data/tagfile/*")
@@ -38,5 +53,81 @@ class TestTagFile(unittest.TestCase):
# Raises Type error
self.assertRaises(TypeError, apt_pkg.TagFile, object())
+ def test_utf8(self):
+ value = "Tést Persön <test@example.org>"
+ packages = os.path.join(self.temp_dir, "Packages")
+ with io.open(packages, "w", encoding="UTF-8") as packages_file:
+ print("Maintainer: %s" % value, file=packages_file)
+ print("", file=packages_file)
+ if sys.version < '3':
+ # In Python 2, test the traditional file interface.
+ with open(packages) as packages_file:
+ tagfile = apt_pkg.TagFile(packages_file)
+ tagfile.step()
+ self.assertEqual(
+ value.encode("UTF-8"), tagfile.section["Maintainer"])
+ with io.open(packages, encoding="UTF-8") as packages_file:
+ tagfile = apt_pkg.TagFile(packages_file)
+ tagfile.step()
+ if sys.version < '3':
+ self.assertEqual(
+ value.encode("UTF-8"), tagfile.section["Maintainer"])
+ else:
+ self.assertEqual(value, tagfile.section["Maintainer"])
+
+ def test_latin1(self):
+ value = "Tést Persön <test@example.org>"
+ packages = os.path.join(self.temp_dir, "Packages")
+ with io.open(packages, "w", encoding="ISO-8859-1") as packages_file:
+ print("Maintainer: %s" % value, file=packages_file)
+ print("", file=packages_file)
+ if sys.version < '3':
+ # In Python 2, test the traditional file interface.
+ with open(packages) as packages_file:
+ tagfile = apt_pkg.TagFile(packages_file)
+ tagfile.step()
+ self.assertEqual(
+ value.encode("ISO-8859-1"), tagfile.section["Maintainer"])
+ with io.open(packages) as packages_file:
+ tagfile = apt_pkg.TagFile(packages_file, bytes=True)
+ tagfile.step()
+ self.assertEqual(
+ value.encode("ISO-8859-1"), tagfile.section["Maintainer"])
+ if sys.version >= '3':
+ # In Python 3, TagFile can pick up the encoding of the file
+ # object.
+ with io.open(packages, encoding="ISO-8859-1") as packages_file:
+ tagfile = apt_pkg.TagFile(packages_file)
+ tagfile.step()
+ self.assertEqual(value, tagfile.section["Maintainer"])
+
+ def test_mixed(self):
+ value = "Tést Persön <test@example.org>"
+ packages = os.path.join(self.temp_dir, "Packages")
+ with io.open(packages, "w", encoding="UTF-8") as packages_file:
+ print("Maintainer: %s" % value, file=packages_file)
+ print("", file=packages_file)
+ with io.open(packages, "a", encoding="ISO-8859-1") as packages_file:
+ print("Maintainer: %s" % value, file=packages_file)
+ print("", file=packages_file)
+ if sys.version < '3':
+ # In Python 2, test the traditional file interface.
+ with open(packages) as packages_file:
+ tagfile = apt_pkg.TagFile(packages_file)
+ tagfile.step()
+ self.assertEqual(
+ value.encode("UTF-8"), tagfile.section["Maintainer"])
+ tagfile.step()
+ self.assertEqual(
+ value.encode("ISO-8859-1"), tagfile.section["Maintainer"])
+ with io.open(packages) as packages_file:
+ tagfile = apt_pkg.TagFile(packages_file, bytes=True)
+ tagfile.step()
+ self.assertEqual(
+ value.encode("UTF-8"), tagfile.section["Maintainer"])
+ tagfile.step()
+ self.assertEqual(
+ value.encode("ISO-8859-1"), tagfile.section["Maintainer"])
+
if __name__ == "__main__":
unittest.main()