blob: 371cc6ee740ac215c68307fe27541996aa903a0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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()
|