Skip to content

Commit 18b66e0

Browse files
authored
Merge pull request #6 from nexB/4-data-driven-testing
Use data driven testing #4
2 parents 9898806 + 549fa33 commit 18b66e0

346 files changed

Lines changed: 1941 additions & 1083 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,16 @@ pyvenv.cfg
6767
/.pytest_cache/
6868
lib64
6969
tcl
70+
71+
72+
__pycache__
73+
74+
75+
76+
# test files that should not be ignored
77+
!/tests/typecode/data/contenttype/compiled/java/*
78+
!/tests/typecode/data/contenttype/compiled/python/*
79+
!/tests/typecode/data/contenttype/compiled/flash/*
80+
!/tests/typecode/data/contenttype/compiled/linux/*
81+
!/tests/typecode/data/contenttype/compiled/win/*
82+
!/tests/typecode/data/contenttype/package/*

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ norecursedirs = [
3030
"Scripts",
3131
"thirdparty",
3232
"tmp",
33-
"tests/data",
33+
"tests/typecode/data",
3434
".eggs"
3535
]
3636

src/typecode/contenttype.py

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from __future__ import absolute_import
2626
from __future__ import print_function
2727

28+
from collections import OrderedDict
2829
import contextlib
2930
import io
3031
import os
@@ -57,7 +58,6 @@
5758
from typecode.pygments_lexers import get_lexer_for_filename
5859
from typecode.pygments_lexers import guess_lexer
5960

60-
6161
"""
6262
Utilities to detect and report the type of a file or path based on its name,
6363
extension and mostly its content.
@@ -82,15 +82,13 @@ def logger_debug(*args):
8282
def logger_debug(*args):
8383
return logger.debug(' '.join(isinstance(a, string_types) and a or repr(a) for a in args))
8484

85-
8685
data_dir = os.path.join(os.path.dirname(__file__), 'data')
8786

8887
# Python mimetypes path setup using Apache mimetypes DB
8988
os.environ['XDG_DATA_DIRS'] = os.path.join(data_dir, 'apache')
9089
os.environ['XDG_DATA_HOME'] = os.environ['XDG_DATA_DIRS']
9190
APACHE_MIME_TYPES = os.path.join(data_dir, 'apache', 'mime.types')
9291

93-
9492
# Ensure that all dates are UTC, especially for fine free file.
9593
os.environ['TZ'] = 'UTC'
9694

@@ -108,7 +106,6 @@ def as_bytes(items):
108106
ELF_UNKNOWN = 'unknown'
109107
elf_types = (ELF_EXE, ELF_SHARED, ELF_RELOC,)
110108

111-
112109
# TODO:
113110
# http://svn.zope.org/z3c.mimetype/trunk/?pathrev=103648
114111
# http://svn.zope.org/z3c.sharedmimeinfo/trunk/TODO.txt?revision=103668&view=markup
@@ -172,6 +169,55 @@ class Type(object):
172169
'_contains_text',
173170
)
174171

172+
# FIXME: we should use an introspectable attrs class instead
173+
# ATTENTION: keep this in sync with sloats and properties
174+
text_attributes = [
175+
'filetype_file',
176+
'mimetype_file',
177+
'mimetype_python',
178+
'filetype_pygment',
179+
'elf_type',
180+
'programming_language',
181+
]
182+
183+
exportable_attributes = text_attributes + [
184+
'is_file',
185+
'is_dir',
186+
'is_regular',
187+
'is_special',
188+
'date',
189+
'is_link',
190+
'is_broken_link',
191+
'link_target',
192+
'size',
193+
'is_pdf_with_text',
194+
'is_text',
195+
'is_text_with_long_lines',
196+
'is_compact_js',
197+
'is_js_map',
198+
'is_binary',
199+
'is_data',
200+
'is_archive',
201+
'contains_text',
202+
'is_compressed',
203+
'is_c_source',
204+
'is_c_source',
205+
'is_elf',
206+
'is_elf',
207+
'is_filesystem',
208+
'is_java_class',
209+
'is_java_source',
210+
'is_media',
211+
'is_media_with_meta',
212+
'is_office_doc',
213+
'is_package',
214+
'is_pdf',
215+
'is_script',
216+
'is_source',
217+
'is_stripped_elf',
218+
'is_winexe',
219+
]
220+
175221
def __init__(self, location):
176222
if (not location
177223
or (not os.path.exists(location)
@@ -215,6 +261,15 @@ def __repr__(self):
215261
% (self.filetype_file, self.mimetype_file,
216262
self.filetype_pygment, self.mimetype_python))
217263

264+
def to_dict(self, include_date=True):
265+
"""
266+
Return a mapping of attributes.
267+
"""
268+
nv = ((n, getattr(self, n)) for n in self.exportable_attributes)
269+
if not include_date:
270+
nv = ((n,v) for n,v in nv if n != 'date')
271+
return OrderedDict(nv)
272+
218273
@property
219274
def size(self):
220275
"""
File renamed without changes.
9.15 KB
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/typecode/data/contenttype/archive/file_4.26-1.diff.gz renamed to tests/typecode/data/extractible/file_4.26-1.diff.gz

File renamed without changes.

0 commit comments

Comments
 (0)