Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_mimetype.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import pytest | import pytest | ||||
import unittest | import unittest | ||||
from typing import Any, Dict | from typing import Any, Dict | ||||
from swh.indexer.mimetype import ( | from swh.indexer.mimetype import ( | ||||
MimetypeIndexer, MimetypeRangeIndexer, compute_mimetype_encoding | MimetypeIndexer, MimetypeRangeIndexer, compute_mimetype_encoding | ||||
) | ) | ||||
from swh.indexer.tests.utils import ( | from swh.indexer.tests.utils import ( | ||||
CommonContentIndexerTest, CommonContentIndexerRangeTest, | CommonContentIndexerTest, CommonContentIndexerRangeTest, | ||||
BASE_TEST_CONFIG, fill_storage, fill_obj_storage, filter_dict, | BASE_TEST_CONFIG, fill_storage, fill_obj_storage, filter_dict, | ||||
) | ) | ||||
class BasicTest(unittest.TestCase): | def test_compute_mimetype_encoding(): | ||||
def test_compute_mimetype_encoding(self): | |||||
"""Compute mimetype encoding should return results""" | """Compute mimetype encoding should return results""" | ||||
for _input, _mimetype, _encoding in [ | for _input, _mimetype, _encoding in [ | ||||
('du français'.encode(), 'text/plain', 'utf-8'), | ('du français'.encode(), 'text/plain', 'utf-8'), | ||||
(b'def __init__(self):', 'text/x-python', 'us-ascii')]: | (b'def __init__(self):', 'text/x-python', 'us-ascii'), | ||||
(b'\xff\xfe\x00\x00\x00\x00\xff\xfe\xff\xff', | |||||
'application/octet-stream', '') | |||||
]: | |||||
actual_result = compute_mimetype_encoding(_input) | actual_result = compute_mimetype_encoding(_input) | ||||
self.assertEqual(actual_result, { | assert actual_result == { | ||||
'mimetype': _mimetype, | 'mimetype': _mimetype, | ||||
'encoding': _encoding | 'encoding': _encoding | ||||
}) | } | ||||
CONFIG = { | CONFIG = { | ||||
**BASE_TEST_CONFIG, | **BASE_TEST_CONFIG, | ||||
'tools': { | 'tools': { | ||||
'name': 'file', | 'name': 'file', | ||||
'version': '1:5.30-1+deb9u1', | 'version': '1:5.30-1+deb9u1', | ||||
'configuration': { | 'configuration': { | ||||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |