diff options
Diffstat (limited to 'tests/identify_test.py')
-rw-r--r-- | tests/identify_test.py | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/tests/identify_test.py b/tests/identify_test.py index 8e00f60..8cc5856 100644 --- a/tests/identify_test.py +++ b/tests/identify_test.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import unicode_literals - import io import os +import socket import stat +from tempfile import TemporaryDirectory import pytest @@ -14,6 +12,21 @@ from identify import identify def test_all_tags_includes_basic_ones(): assert 'file' in identify.ALL_TAGS assert 'directory' in identify.ALL_TAGS + assert 'executable' in identify.ALL_TAGS + assert 'text' in identify.ALL_TAGS + assert 'socket' in identify.ALL_TAGS + + +@pytest.mark.parametrize( + 'tag_group', + ( + identify.TYPE_TAGS, + identify.MODE_TAGS, + identify.ENCODING_TAGS, + ), +) +def test_all_tags_contains_all_groups(tag_group): + assert tag_group < identify.ALL_TAGS def test_all_tags_contains_each_type(): @@ -41,6 +54,17 @@ def test_tags_from_path_symlink(tmpdir): assert identify.tags_from_path(x.strpath) == {'symlink'} +def test_tags_from_path_socket(): + tmproot = '/tmp' # short path avoids `OSError: AF_UNIX path too long` + with TemporaryDirectory(dir=tmproot) as tmpdir: + socket_path = os.path.join(tmpdir, 'socket') + with socket.socket(socket.AF_UNIX) as sock: + sock.bind(socket_path) + tags = identify.tags_from_path(socket_path) + + assert tags == {'socket'} + + def test_tags_from_path_broken_symlink(tmpdir): x = tmpdir.join('foo') x.mksymlinkto(tmpdir.join('lol')) @@ -177,9 +201,9 @@ def test_tags_from_interpreter(interpreter, expected): ( (b'hello world', True), (b'', True), - ('éóñəå ⊂(◉‿◉)つ(ノ≥∇≤)ノ'.encode('utf8'), True), - (r'¯\_(ツ)_/¯'.encode('utf8'), True), - ('♪┏(・o・)┛♪┗ ( ・o・) ┓♪┏ ( ) ┛♪┗ (・o・ ) ┓♪'.encode('utf8'), True), + ('éóñəå ⊂(◉‿◉)つ(ノ≥∇≤)ノ'.encode(), True), + (r'¯\_(ツ)_/¯'.encode(), True), + ('♪┏(・o・)┛♪┗ ( ・o・) ┓♪┏ ( ) ┛♪┗ (・o・ ) ┓♪'.encode(), True), ('éóñå'.encode('latin1'), True), (b'hello world\x00', False), |