diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2012-02-06 14:56:13 +0100 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2012-02-06 14:56:13 +0100 |
| commit | 89df8999cddf71b1f5cbbc621d64260fd19f1bb2 (patch) | |
| tree | c1d8472ff8116cf518a77de3afbe2e930a803757 | |
| parent | 64c1ffa6310efdff6353346fe621aea10e36f2c9 (diff) | |
| parent | 3514672ed2a333eb6791d425ebe59b883cf8d349 (diff) | |
| download | python-apt-89df8999cddf71b1f5cbbc621d64260fd19f1bb2.tar.gz | |
* 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)
| -rw-r--r-- | debian/changelog | 6 | ||||
| -rw-r--r-- | po/python-apt.pot | 41 | ||||
| -rw-r--r-- | python/tag.cc | 39 | ||||
| -rw-r--r-- | tests/data/tagfile/history.1.log.gz | bin | 0 -> 270 bytes | |||
| -rw-r--r-- | tests/data/tagfile/history.log | 15 | ||||
| -rw-r--r-- | tests/test_tagfile.py | 42 |
6 files changed, 117 insertions, 26 deletions
diff --git a/debian/changelog b/debian/changelog index 4deb8b3b..a585bbb4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +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 + * 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) -- Michael Vogt <michael.vogt@ubuntu.com> Wed, 04 Jan 2012 12:07:48 +0100 diff --git a/po/python-apt.pot b/po/python-apt.pot index 02c65f13..bde5f9c1 100644 --- a/po/python-apt.pot +++ b/po/python-apt.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-01-30 15:44+0100\n" +"POT-Creation-Date: 2012-02-06 14:56+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -474,23 +474,28 @@ msgid "" "Please check your Internet connection." msgstr "" -#: ../apt/debfile.py:85 +#: ../apt/debfile.py:82 #, python-format msgid "List of files for '%s' could not be read" msgstr "" -#: ../apt/debfile.py:202 +#: ../apt/debfile.py:93 +#, python-format +msgid "List of control files for '%s' could not be read" +msgstr "" + +#: ../apt/debfile.py:211 #, python-format msgid "Dependency is not satisfiable: %s\n" msgstr "" -#: ../apt/debfile.py:223 +#: ../apt/debfile.py:232 #, python-format msgid "Conflicts with the installed package '%s'" msgstr "" #. TRANSLATORS: the first '%s' is the package that breaks, the second the dependency that makes it break, the third the relation (e.g. >=) and the latest the version for the releation -#: ../apt/debfile.py:364 +#: ../apt/debfile.py:373 #, python-format msgid "" "Breaks existing package '%(pkgname)s' dependency %(depname)s " @@ -498,63 +503,59 @@ msgid "" msgstr "" #. TRANSLATORS: the first '%s' is the package that conflicts, the second the packagename that it conflicts with (so the name of the deb the user tries to install), the third is the relation (e.g. >=) and the last is the version for the relation -#: ../apt/debfile.py:380 +#: ../apt/debfile.py:389 #, python-format msgid "" "Breaks existing package '%(pkgname)s' conflict: %(targetpkg)s (%(comptype)s " "%(targetver)s)" msgstr "" -#: ../apt/debfile.py:390 +#: ../apt/debfile.py:399 #, python-format msgid "" "Breaks existing package '%(pkgname)s' that conflict: '%(targetpkg)s'. But " "the '%(debfile)s' provides it via: '%(provides)s'" msgstr "" -#: ../apt/debfile.py:438 +#: ../apt/debfile.py:447 msgid "No Architecture field in the package" msgstr "" -#: ../apt/debfile.py:448 +#: ../apt/debfile.py:457 #, python-format msgid "Wrong architecture '%s'" msgstr "" #. the deb is older than the installed -#: ../apt/debfile.py:455 +#: ../apt/debfile.py:464 msgid "A later version is already installed" msgstr "" -#: ../apt/debfile.py:480 +#: ../apt/debfile.py:489 msgid "Failed to satisfy all dependencies (broken cache)" msgstr "" -#: ../apt/debfile.py:510 +#: ../apt/debfile.py:519 #, python-format msgid "Cannot install '%s'" msgstr "" -#: ../apt/debfile.py:554 -msgid "Python-debian module not available" -msgstr "" - -#: ../apt/debfile.py:597 +#: ../apt/debfile.py:593 msgid "" "Automatically decompressed:\n" "\n" msgstr "" -#: ../apt/debfile.py:603 +#: ../apt/debfile.py:599 msgid "Automatically converted to printable ascii:\n" msgstr "" -#: ../apt/debfile.py:693 +#: ../apt/debfile.py:689 #, python-format msgid "Install Build-Dependencies for source package '%s' that builds %s\n" msgstr "" -#: ../apt/debfile.py:704 +#: ../apt/debfile.py:700 msgid "An essential package would be removed" msgstr "" 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 Binary files differnew file mode 100644 index 00000000..4174e02b --- /dev/null +++ b/tests/data/tagfile/history.1.log.gz 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() |
