01-fix-tests.patch 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --- contrib/python/chardet/py2/test.py (index)
  2. +++ contrib/python/chardet/py2/test.py (working tree)
  3. @@ -11,7 +11,7 @@ import textwrap
  4. from difflib import ndiff
  5. from io import open
  6. from os import listdir
  7. -from os.path import dirname, isdir, join, realpath, relpath, splitext
  8. +from os.path import dirname, isdir, join, splitext, basename
  9. try:
  10. import hypothesis.strategies as st
  11. @@ -22,20 +22,21 @@ except ImportError:
  12. import pytest
  13. import chardet
  14. +import yatest.common
  15. # TODO: Restore Hungarian encodings (iso-8859-2 and windows-1250) after we
  16. # retrain model.
  17. MISSING_ENCODINGS = {'iso-8859-2', 'iso-8859-6', 'windows-1250',
  18. 'windows-1254', 'windows-1256'}
  19. -EXPECTED_FAILURES = {'tests/iso-8859-7-greek/disabled.gr.xml',
  20. - 'tests/iso-8859-9-turkish/divxplanet.com.xml',
  21. - 'tests/iso-8859-9-turkish/subtitle.srt',
  22. - 'tests/iso-8859-9-turkish/wikitop_tr_ISO-8859-9.txt'}
  23. +EXPECTED_FAILURES = {'iso-8859-7-greek/disabled.gr.xml',
  24. + 'iso-8859-9-turkish/divxplanet.com.xml',
  25. + 'iso-8859-9-turkish/subtitle.srt',
  26. + 'iso-8859-9-turkish/wikitop_tr_ISO-8859-9.txt'}
  27. def gen_test_params():
  28. """Yields tuples of paths and encodings to use for test_encoding_detection"""
  29. - base_path = relpath(join(dirname(realpath(__file__)), 'tests'))
  30. + base_path = yatest.common.work_path('test_data')
  31. for encoding in listdir(base_path):
  32. path = join(base_path, encoding)
  33. # Skip files in tests directory
  34. @@ -58,12 +59,16 @@ def gen_test_params():
  35. continue
  36. full_path = join(path, file_name)
  37. test_case = full_path, encoding
  38. - if full_path in EXPECTED_FAILURES:
  39. + if join(basename(path), file_name) in EXPECTED_FAILURES:
  40. test_case = pytest.param(*test_case, marks=pytest.mark.xfail)
  41. yield test_case
  42. -@pytest.mark.parametrize ('file_name, encoding', gen_test_params())
  43. +def get_test_name(args):
  44. + return join(basename(dirname(args)), basename(args))
  45. +
  46. +
  47. +@pytest.mark.parametrize ('file_name, encoding', gen_test_params(), ids=get_test_name)
  48. def test_encoding_detection(file_name, encoding):
  49. with open(file_name, 'rb') as f:
  50. input_bytes = f.read()