Skip to content

Commit

Permalink
change import: cmn to icom
Browse files Browse the repository at this point in the history
  • Loading branch information
dhimmel committed Jul 31, 2018
1 parent e3a0f56 commit af8c137
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions pandas/tests/io/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

import pandas as pd
import pandas.io.common as cmn
import pandas.io.common as icom
import pandas.util._test_decorators as td
import pandas.util.testing as tm
from pandas.compat import (
Expand Down Expand Up @@ -55,36 +55,36 @@ class TestCommonIOCapabilities(object):

def test_expand_user(self):
filename = '~/sometest'
expanded_name = cmn._expand_user(filename)
expanded_name = icom._expand_user(filename)

assert expanded_name != filename
assert os.path.isabs(expanded_name)
assert os.path.expanduser(filename) == expanded_name

def test_expand_user_normal_path(self):
filename = '/somefolder/sometest'
expanded_name = cmn._expand_user(filename)
expanded_name = icom._expand_user(filename)

assert expanded_name == filename
assert os.path.expanduser(filename) == expanded_name

@td.skip_if_no('pathlib')
def test_stringify_path_pathlib(self):
rel_path = cmn._stringify_path(Path('.'))
rel_path = icom._stringify_path(Path('.'))
assert rel_path == '.'
redundant_path = cmn._stringify_path(Path('foo//bar'))
redundant_path = icom._stringify_path(Path('foo//bar'))
assert redundant_path == os.path.join('foo', 'bar')

@td.skip_if_no('py.path')
def test_stringify_path_localpath(self):
path = os.path.join('foo', 'bar')
abs_path = os.path.abspath(path)
lpath = LocalPath(path)
assert cmn._stringify_path(lpath) == abs_path
assert icom._stringify_path(lpath) == abs_path

def test_stringify_path_fspath(self):
p = CustomFSPath('foo/bar.csv')
result = cmn._stringify_path(p)
result = icom._stringify_path(p)
assert result == 'foo/bar.csv'

@pytest.mark.parametrize('extension,expected', [
Expand All @@ -97,12 +97,12 @@ def test_stringify_path_fspath(self):
@pytest.mark.parametrize('path_type', path_types)
def test_infer_compression_from_path(self, extension, expected, path_type):
path = path_type('foo/bar.csv' + extension)
compression = cmn._infer_compression(path, compression='infer')
compression = icom._infer_compression(path, compression='infer')
assert compression == expected

def test_get_filepath_or_buffer_with_path(self):
filename = '~/sometest'
filepath_or_buffer, _, _, should_close = cmn.get_filepath_or_buffer(
filepath_or_buffer, _, _, should_close = icom.get_filepath_or_buffer(
filename)
assert filepath_or_buffer != filename
assert os.path.isabs(filepath_or_buffer)
Expand All @@ -111,7 +111,7 @@ def test_get_filepath_or_buffer_with_path(self):

def test_get_filepath_or_buffer_with_buffer(self):
input_buffer = StringIO()
filepath_or_buffer, _, _, should_close = cmn.get_filepath_or_buffer(
filepath_or_buffer, _, _, should_close = icom.get_filepath_or_buffer(
input_buffer)
assert filepath_or_buffer == input_buffer
assert not should_close
Expand Down Expand Up @@ -246,18 +246,18 @@ def test_constructor_bad_file(self, mmap_file):
msg = "[Errno 22]"
err = mmap.error

tm.assert_raises_regex(err, msg, cmn.MMapWrapper, non_file)
tm.assert_raises_regex(err, msg, icom.MMapWrapper, non_file)

target = open(mmap_file, 'r')
target.close()

msg = "I/O operation on closed file"
tm.assert_raises_regex(
ValueError, msg, cmn.MMapWrapper, target)
ValueError, msg, icom.MMapWrapper, target)

def test_get_attr(self, mmap_file):
with open(mmap_file, 'r') as target:
wrapper = cmn.MMapWrapper(target)
wrapper = icom.MMapWrapper(target)

attrs = dir(wrapper.mmap)
attrs = [attr for attr in attrs
Expand All @@ -271,7 +271,7 @@ def test_get_attr(self, mmap_file):

def test_next(self, mmap_file):
with open(mmap_file, 'r') as target:
wrapper = cmn.MMapWrapper(target)
wrapper = icom.MMapWrapper(target)
lines = target.readlines()

for line in lines:
Expand Down Expand Up @@ -313,14 +313,14 @@ def test_compression_size(obj, method, compression_only):
def test_compression_size_fh(obj, method, compression_only):

with tm.ensure_clean() as path:
f, handles = cmn._get_handle(path, 'w', compression=compression_only)
f, handles = icom._get_handle(path, 'w', compression=compression_only)
with f:
getattr(obj, method)(f)
assert not f.closed
assert f.closed
compressed = os.path.getsize(path)
with tm.ensure_clean() as path:
f, handles = cmn._get_handle(path, 'w', compression=None)
f, handles = icom._get_handle(path, 'w', compression=None)
with f:
getattr(obj, method)(f)
assert not f.closed
Expand All @@ -339,7 +339,7 @@ def test_dataframe_compression_defaults_to_infer(
# Test that DataFrame.to_* methods default to inferring compression from
# paths. GH 22004
input = pd.DataFrame([[1.0, 0, -4], [3.4, 5, 2]], columns=['X', 'Y', 'Z'])
extension = cmn._compression_to_extension[compression_only]
extension = icom._compression_to_extension[compression_only]
with tm.ensure_clean('compressed' + extension) as path:
getattr(input, write_method)(path, **write_kwargs)
output = read_method(path, compression=compression_only)
Expand All @@ -358,7 +358,7 @@ def test_series_compression_defaults_to_infer(
# Test that Series.to_* methods default to inferring compression from
# paths. GH 22004
input = pd.Series([0, 5, -2, 10], name='X')
extension = cmn._compression_to_extension[compression_only]
extension = icom._compression_to_extension[compression_only]
with tm.ensure_clean('compressed' + extension) as path:
getattr(input, write_method)(path, **write_kwargs)
output = read_method(path, compression=compression_only, **read_kwargs)
Expand All @@ -377,7 +377,7 @@ def test_compression_warning(compression_only):
[12.32112, 123123.2, 321321.2]],
columns=['X', 'Y', 'Z'])
with tm.ensure_clean() as path:
f, handles = cmn._get_handle(path, 'w', compression=compression_only)
f, handles = icom._get_handle(path, 'w', compression=compression_only)
with tm.assert_produces_warning(RuntimeWarning,
check_stacklevel=False):
with f:
Expand Down

0 comments on commit af8c137

Please sign in to comment.