File: test_archives.py

package info (click to toggle)
pgxnclient 1.3.2-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 672 kB
  • sloc: python: 3,545; sh: 71; makefile: 53
file content (68 lines) | stat: -rw-r--r-- 1,949 bytes parent folder | download | duplicates (4)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import unittest

from pgxnclient import tar
from pgxnclient import zip
from pgxnclient import archive

from pgxnclient.errors import PgxnClientException
from .testutils import get_test_filename


class TestArchive(unittest.TestCase):
    def test_from_file_zip(self):
        fn = get_test_filename('foobar-0.42.1.zip')
        a = archive.from_file(fn)
        self.assert_(isinstance(a, zip.ZipArchive))
        self.assertEqual(a.filename, fn)

    def test_from_file_tar(self):
        fn = get_test_filename('foobar-0.42.1.tar.gz')
        a = archive.from_file(fn)
        self.assert_(isinstance(a, tar.TarArchive))
        self.assertEqual(a.filename, fn)

    def test_from_file_unknown(self):
        fn = get_test_filename('META-manyext.json')
        self.assertRaises(PgxnClientException, archive.from_file, fn)


class TestZipArchive(unittest.TestCase):
    def test_can_open(self):
        fn = get_test_filename('foobar-0.42.1.zip')
        a = zip.ZipArchive(fn)
        self.assert_(a.can_open())
        a.open()
        a.close()

    def test_can_open_noext(self):
        fn = get_test_filename('zip.ext')
        a = zip.ZipArchive(fn)
        self.assert_(a.can_open())
        a.open()
        a.close()

    def test_cannot_open(self):
        fn = get_test_filename('foobar-0.42.1.tar.gz')
        a = zip.ZipArchive(fn)
        self.assert_(not a.can_open())


class TestTarArchive(unittest.TestCase):
    def test_can_open(self):
        fn = get_test_filename('foobar-0.42.1.tar.gz')
        a = tar.TarArchive(fn)
        self.assert_(a.can_open())
        a.open()
        a.close()

    def test_can_open_noext(self):
        fn = get_test_filename('tar.ext')
        a = tar.TarArchive(fn)
        self.assert_(a.can_open())
        a.open()
        a.close()

    def test_cannot_open(self):
        fn = get_test_filename('foobar-0.42.1.zip')
        a = tar.TarArchive(fn)
        self.assert_(not a.can_open())