summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2012-02-14 09:37:12 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2012-02-14 09:37:12 +0100
commite09f5a1211b9940d4f6061ad905871e767ac5eb5 (patch)
tree6f2d728f0e86e6ca4b980e508bd928470a491949
parent601d841cc3644f827487a277b5e031323450a6c4 (diff)
parent3514672ed2a333eb6791d425ebe59b883cf8d349 (diff)
downloadpython-apt-e09f5a1211b9940d4f6061ad905871e767ac5eb5.tar.gz
merged from lp:~mvo/apt/mvo
-rw-r--r--debian/changelog13
-rw-r--r--python/tag.cc39
-rw-r--r--tests/data/tagfile/history.1.log.gzbin0 -> 270 bytes
-rw-r--r--tests/data/tagfile/history.log15
-rw-r--r--tests/test_tagfile.py42
5 files changed, 97 insertions, 12 deletions
diff --git a/debian/changelog b/debian/changelog
index 7e45d0ae..8c4d1584 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,4 @@
-python-apt (0.8.4) UNRELEASED; urgency=low
+python-apt (0.8.3ubuntu4) UNRELEASED; urgency=low
* doc/examples/build-deps.py:
- update the build-deps.py example to use the apt API more
@@ -7,11 +7,12 @@ python-apt (0.8.4) UNRELEASED; urgency=low
- use apt_inst for reading the control_filelist
* debian/control:
- remove no longer needed dependency on python-debian
-
- -- Michael Vogt <michael.vogt@ubuntu.com> Wed, 04 Jan 2012 12:07:48 +0100
-
-python-apt (0.8.3.1) UNRELEASED; urgency=low
-
+ * tests/test_tagfile.py:
+ - add test for apt_pkg.TagFile() both for compressed/uncompressed
+ files
+ * python/tag.cc, tests/test_tagfile.py:
+ - add support a filename argument in apt_pkg.TagFile() (in addition
+ to the file object currently supported)
* tests/test_apt_cache.py:
- fix tests on kfreebsd/ia64
* apt/debfile.py:
diff --git a/python/tag.cc b/python/tag.cc
index 3996af8e..49f53c31 100644
--- a/python/tag.cc
+++ b/python/tag.cc
@@ -390,21 +390,48 @@ PyObject *ParseSection(PyObject *self,PyObject *Args)
static PyObject *TagFileNew(PyTypeObject *type,PyObject *Args,PyObject *kwds)
{
+ TagFileData *New;
PyObject *File;
+
char *kwlist[] = {"file", 0};
if (PyArg_ParseTupleAndKeywords(Args,kwds,"O",kwlist,&File) == 0)
return 0;
- int fileno = PyObject_AsFileDescriptor(File);
- if (fileno == -1)
+
+ // check if we got a filename or a file object
+ int fileno = -1;
+ const char *filename = NULL;
+ if (PyString_Check(File))
+ filename = PyObject_AsString(File);
+ else
+ fileno = PyObject_AsFileDescriptor(File);
+
+ // handle invalid arguments
+ if (fileno == -1 && filename == NULL)
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "Argument must be string, fd or have a fileno() method");
return 0;
+ }
- TagFileData *New = (TagFileData*)type->tp_alloc(type, 0);
+ New = (TagFileData*)type->tp_alloc(type, 0);
+ if (fileno > 0)
+ {
#ifdef APT_HAS_GZIP
- new (&New->Fd) FileFd();
- New->Fd.OpenDescriptor(fileno, FileFd::ReadOnlyGzip, false);
+ new (&New->Fd) FileFd();
+ New->Fd.OpenDescriptor(fileno, FileFd::ReadOnlyGzip, false);
+#else
+ new (&New->Fd) FileFd(fileno,false);
+#endif
+ }
+ else
+ {
+ // FileFd::Extension got added in this revision
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 12)
+ new (&New->Fd) FileFd(filename, FileFd::ReadOnly, FileFd::Extension, false);
#else
- new (&New->Fd) FileFd(fileno,false);
+ new (&New->Fd) FileFd(filename, FileFd::ReadOnly, false);
#endif
+ }
New->Owner = File;
Py_INCREF(New->Owner);
new (&New->Object) pkgTagFile(&New->Fd);
diff --git a/tests/data/tagfile/history.1.log.gz b/tests/data/tagfile/history.1.log.gz
new file mode 100644
index 00000000..4174e02b
--- /dev/null
+++ b/tests/data/tagfile/history.1.log.gz
Binary files differ
diff --git a/tests/data/tagfile/history.log b/tests/data/tagfile/history.log
new file mode 100644
index 00000000..f1d72665
--- /dev/null
+++ b/tests/data/tagfile/history.log
@@ -0,0 +1,15 @@
+
+Start-Date: 2012-02-01 13:54:52
+Commandline: apt-get install chromium-browser
+Install: chromium-browser:amd64 (16.0.912.77~r118311-0ubuntu1), chromium-browser-l10n:amd64 (16.0.912.77~r118311-0ubuntu1, automatic), chromium-codecs-ffmpeg:amd64 (16.0.912.77~r118311-0ubuntu1, automatic)
+End-Date: 2012-02-01 13:55:01
+
+Start-Date: 2012-02-02 10:39:04
+Commandline: apt-get install python-geoclue
+Install: python-geoclue:amd64 (0.1.0-4build1)
+End-Date: 2012-02-02 10:39:08
+
+Start-Date: 2012-02-03 10:20:50
+Commandline: apt-get install python-qt4
+Install: python-qt4:amd64 (4.9-3ubuntu1)
+End-Date: 2012-02-03 10:20:55
diff --git a/tests/test_tagfile.py b/tests/test_tagfile.py
new file mode 100644
index 00000000..371cc6ee
--- /dev/null
+++ b/tests/test_tagfile.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2010 Michael Vogt <mvo@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"""
+
+import glob
+import os
+import unittest
+
+from test_all import get_library_dir
+import sys
+sys.path.insert(0, get_library_dir())
+
+import apt_pkg
+
+class TestTagFile(unittest.TestCase):
+ """ test the apt_pkg.TagFile """
+
+ def test_tag_file(self):
+ basepath = os.path.dirname(__file__)
+ tagfilepath = os.path.join(basepath, "./data/tagfile/*")
+ # test once for compressed and uncompressed
+ for testfile in glob.glob(tagfilepath):
+ # test once using the open() method and once using the path
+ for f in [testfile, open(testfile)]:
+ tagfile = apt_pkg.TagFile(f)
+ for i, stanza in enumerate(tagfile):
+ pass
+ self.assertEqual(i, 2)
+
+ def test_errors(self):
+ # Raises SystemError via lbiapt
+ self.assertRaises(SystemError, apt_pkg.TagFile, "not-there-no-no")
+ # Raises Type error
+ self.assertRaises(TypeError, apt_pkg.TagFile, object())
+
+if __name__ == "__main__":
+ unittest.main()