Skip to content

Commit

Permalink
Added open pathlib.Path skipIf test for Py<3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
clintval committed Mar 15, 2018
1 parent 60236b7 commit b295f04
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions smart_open/tests/test_smart_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,18 @@ def test_open_with_keywords_explicit_r(self):
actual = fin.read()
self.assertEqual(expected, actual)

def test_open_pathlib_path(self):
"""If ``pathlib.Path`` is available we should open it."""
try:
from pathlib import Path
fpath = Path(os.path.join(CURR_DIR, 'test_data/cp852.tsv.txt'))
with smart_open.smart_open(fpath, encoding='cp852') as fin:
fin.read()
except ImportError:
pass
@unittest.skipIf(
sys.version_info < (3, 4),
"only supported for Python>=3.4")
def test_open_and_read_pathlib_path(self):
"""If pathlib.Path is available we should open and read."""
import pathlib
fpath = os.path.join(CURR_DIR, 'test_data/cp852.tsv.txt')
with open(pathlib.Path(fpath), 'rb') as fin:
expected = fin.read().decode('cp852')
with smart_open.smart_open(fpath, encoding='cp852') as fin:
actual = fin.read()
self.assertEqual(expected, actual)

@mock_s3
def test_read_never_returns_none(self):
Expand Down

0 comments on commit b295f04

Please sign in to comment.