File: test_archive_tools.py

package info (click to toggle)
mcomix 1.2.1mcomix3+git20200206-1
  • links: PTS
  • area: main
  • in suites: bullseye, sid
  • size: 6,604 kB
  • sloc: python: 17,232; xml: 52; sh: 11; makefile: 7
file content (56 lines) | stat: -rw-r--r-- 1,686 bytes parent folder | download | duplicates (3)
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

import os

from . import MComixTest, get_testfile_path

from mcomix import archive_tools
from mcomix import constants


_EXTENSION_TO_MIME_TYPES = {
    'cbz'    : constants.ZIP,
    'zip'    : constants.ZIP,
    'zip.bz2': constants.ZIP_EXTERNAL,
    'rar'    : constants.RAR,
    'tar'    : constants.TAR,
    'tar.gz' : constants.GZIP,
    'tar.bz2': constants.BZIP2,
    'tar.xz' : constants.XZ,
    'pdf'    : constants.PDF,
    '7z'     : constants.SEVENZIP,
    'lha'    : constants.LHA,
}

_ARCHIVE_TYPE_NAMES = {
    constants.ZIP         : 'zip',
    constants.RAR         : 'rar',
    constants.TAR         : 'tar',
    constants.GZIP        : 'gzip',
    constants.BZIP2       : 'bzip2',
    constants.XZ          : 'xz',
    constants.PDF         : 'pdf',
    constants.SEVENZIP    : '7z',
    constants.LHA         : 'lha',
    constants.ZIP_EXTERNAL: 'zip (external)',
}

class ArchiveToolsTest(MComixTest):

    def test_archive_mime_type(self):

       dir = get_testfile_path('archives')
       for filename in os.listdir(dir):
           ext = '.'.join(filename.split('.')[1:])
           path = os.path.join(dir, filename)
           archive_type = archive_tools.archive_mime_type(path)
           expected_type = _EXTENSION_TO_MIME_TYPES.get(ext, '???')
           msg = (
               'archive_mime_type("%s") failed; '
               'result differs: %s [%s] instead of %s [%s]'
               % (path,
                  archive_type, _ARCHIVE_TYPE_NAMES.get(archive_type, '???'),
                  expected_type, _ARCHIVE_TYPE_NAMES.get(expected_type, '???'),
                 )
           )
           self.assertEqual(archive_type, expected_type, msg=msg)