Skip to content
Snippets Groups Projects
Verified Commit d87fd531 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

test: Deal with divergent test output depending on magic version

This fixes the indexer debian package build.
parent 8c95b872
No related branches found
Tags v0.6.1
1 merge request!287test: Deal with divergent test output depending on magic version
......@@ -29,14 +29,26 @@ from swh.model.hashutil import hash_to_bytes
"raw_text,mimetype,encoding",
[
("du français".encode(), "text/plain", "utf-8"),
(b"def __init__(self):", "text/x-python", "us-ascii"),
(b"def __init__(self):", ("text/x-python", "text/x-script.python"), "us-ascii"),
(b"\xff\xfe\x00\x00\x00\x00\xff\xfe\xff\xff", "application/octet-stream", ""),
],
)
def test_compute_mimetype_encoding(raw_text, mimetype, encoding):
"""Compute mimetype encoding should return results"""
actual_result = compute_mimetype_encoding(raw_text)
assert actual_result == {"mimetype": mimetype, "encoding": encoding}
if isinstance(mimetype, tuple):
# New magic version can return different results, this deals with such a case
expected_result = {"mimetype": mimetype[0], "encoding": encoding}
# as a fallback
fallback_expected_result = {"mimetype": mimetype[1], "encoding": encoding}
else:
expected_result = {"mimetype": mimetype, "encoding": encoding}
fallback_expected_result = expected_result
try:
assert actual_result == expected_result
except AssertionError:
assert actual_result == fallback_expected_result
CONFIG = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment