diff --git a/smart_open/tests/test_smart_open.py b/smart_open/tests/test_smart_open.py index ff634972..baab63a3 100644 --- a/smart_open/tests/test_smart_open.py +++ b/smart_open/tests/test_smart_open.py @@ -6,12 +6,10 @@ # This code is distributed under the terms and conditions # from the MIT License (MIT). -import importlib import unittest import logging import tempfile import os -import pkgutil import sys import hashlib @@ -193,35 +191,16 @@ def test_open_with_keywords_explicit_r(self): actual = fin.read() self.assertEqual(expected, actual) - @unittest.skipIf( - (pkgutil.find_loader('pathlib') is None and - pkgutil.find_loader('pathlib2') is None), + @unittest.skipUnless( + smart_open_lib.PATHLIB_SUPPORT, "do not test pathlib support if pathlib or backport are not available") def test_open_and_read_pathlib_path(self): """If ``pathlib.Path`` is available we should be able to open and read.""" - fpath = os.path.join(CURR_DIR, 'test_data/cp852.tsv.txt') - - # Import ``pathlib`` if the builtin ``pathlib`` or the backport - # ``pathlib2`` are available. The builtin ``pathlib`` will be imported - # with higher precedence. - for pathlib_module in ('pathlib', 'pathlib2'): - try: - pathlib = importlib.import_module(pathlib_module) - break - # Unit test will skip if either module is unavailable so it's safe - # to assume we can import _at least_ one working ``pathlib``. - except ImportError: - pass - - # builtin open() supports pathlib.Path in python>=3.6 only - path_open = pathlib.Path(fpath) if sys.version_info >= (3, 6) else fpath - path_smart_open = pathlib.Path(fpath) + from smart_open.smart_open_lib import pathlib - with open(path_open, 'rb') as fin: - expected = fin.read().decode('cp852') - with smart_open.smart_open(path_smart_open, encoding='cp852') as fin: + fpath = pathlib.Path(os.path.join(CURR_DIR, 'test_data/cp852.tsv.txt')) + with smart_open.smart_open(fpath, mode='r', encoding='cp852') as fin: actual = fin.read() - self.assertEqual(expected, actual) @mock_s3 def test_read_never_returns_none(self):