Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FileNotFoundErrors to support windows #1

Open
wants to merge 14 commits into
base: windows
Choose a base branch
from
13 changes: 7 additions & 6 deletions biom/tests/test_cli/test_subset_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ def test_invalid_input(self):
def test_subset_samples_hdf5(self):
"""Correctly subsets samples in a hdf5 table"""
cwd = os.getcwd()
if '/' in __file__:
os.chdir(__file__.rsplit('/', 1)[0])
obs = _subset_table(hdf5_biom='test_data/test.biom', axis='sample',
if os.path.sep in __file__:
os.chdir(__file__.rsplit(os.path.sep, 1)[0])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__file__.rsplit(os.path.sep, 1)[0] can be os.path.dirname(__file__), I guess.

obs = _subset_table(hdf5_biom=os.path.join('test_data', 'test.biom'),
axis='sample',
ids=['Sample1', 'Sample2', 'Sample3'],
json_table_str=None)
os.chdir(cwd)
Expand All @@ -71,9 +72,9 @@ def test_subset_samples_hdf5(self):
def test_subset_observations_hdf5(self):
"""Correctly subsets samples in a hdf5 table"""
cwd = os.getcwd()
if '/' in __file__:
os.chdir(__file__.rsplit('/', 1)[0])
obs = _subset_table(hdf5_biom='test_data/test.biom',
if os.path.sep in __file__:
os.chdir(__file__.rsplit(os.path.sep, 1)[0])
obs = _subset_table(hdf5_biom=os.path.join('test_data', 'test.biom'),
axis='observation',
ids=['GG_OTU_1', 'GG_OTU_3', 'GG_OTU_5'],
json_table_str=None)
Expand Down
6 changes: 3 additions & 3 deletions biom/tests/test_cli/test_table_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def setUp(self):
self.cmd = _normalize_table

cwd = os.getcwd()
if '/' in __file__:
os.chdir(__file__.rsplit('/', 1)[0])
self.table = biom.load_table('test_data/test.json')
if os.path.sep in __file__:
os.chdir(__file__.rsplit(os.path.sep, 1)[0])
self.table = biom.load_table(os.path.join('test_data', 'test.json'))
os.chdir(cwd)

def test_bad_inputs(self):
Expand Down
3 changes: 2 additions & 1 deletion biom/tests/test_cli/test_validate_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def setUp(self):
self.to_remove = []

cur_path = os.path.split(os.path.abspath(__file__))[0]
examples_path = os.path.join(cur_path.rsplit('/', 3)[0], 'examples')
examples_path = os.path.join(cur_path.rsplit(os.path.sep, 3)[0],
'examples')
self.hdf5_file_valid = os.path.join(examples_path,
'min_sparse_otu_table_hdf5.biom')
self.hdf5_file_valid_md = os.path.join(examples_path,
Expand Down
31 changes: 16 additions & 15 deletions biom/tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@ def test_parse_adjacency_table_no_header(self):
def test_parse_biom_table_hdf5(self):
"""Make sure we can parse a HDF5 table through the same loader"""
cwd = os.getcwd()
if '/' in __file__[1:]:
os.chdir(__file__.rsplit('/', 1)[0])
Table.from_hdf5(h5py.File('test_data/test.biom', 'r'))
if os.path.sep in __file__[1:]:
os.chdir(__file__.rsplit(os.path.sep, 1)[0])
Table.from_hdf5(h5py.File(os.path.join('test_data', 'test.biom'),
'r'))
os.chdir(cwd)

def test_save_table_filepath(self):
Expand All @@ -296,23 +297,23 @@ def test_save_table_filepath(self):

def test_load_table_filepath(self):
cwd = os.getcwd()
if '/' in __file__[1:]:
os.chdir(__file__.rsplit('/', 1)[0])
load_table('test_data/test.biom')
if os.path.sep in __file__[1:]:
os.chdir(__file__.rsplit(os.path.sep, 1)[0])
load_table(os.path.join('test_data', 'test.biom'))
os.chdir(cwd)

def test_load_table_inmemory(self):
cwd = os.getcwd()
if '/' in __file__[1:]:
os.chdir(__file__.rsplit('/', 1)[0])
load_table(h5py.File('test_data/test.biom', 'r'))
if os.path.sep in __file__[1:]:
os.chdir(__file__.rsplit(os.path.sep, 1)[0])
load_table(h5py.File(os.path.join('test_data', 'test.biom'), 'r'))
os.chdir(cwd)

def test_load_table_inmemory_json(self):
cwd = os.getcwd()
if '/' in __file__[1:]:
os.chdir(__file__.rsplit('/', 1)[0])
load_table(open('test_data/test.json'))
if os.path.sep in __file__[1:]:
os.chdir(__file__.rsplit(os.path.sep, 1)[0])
load_table(open(os.path.join('test_data', 'test.json')))
os.chdir(cwd)

def test_load_table_inmemory_stringio(self):
Expand Down Expand Up @@ -350,10 +351,10 @@ def test_parse_biom_table_with_hdf5(self):
"""tests for parse_biom_table when we have h5py"""
# We will round-trip the HDF5 file to several different formats, and
# make sure we can recover the same table using parse_biom_table
if '/' in __file__[1:]:
os.chdir(__file__.rsplit('/', 1)[0])
if os.path.sep in __file__[1:]:
os.chdir(__file__.rsplit(os.path.sep, 1)[0])

t = parse_biom_table(h5py.File('test_data/test.biom', 'r'))
t = parse_biom_table(h5py.File(os.path.join('test_data', 'test.biom'), 'r'))

# These things are not round-trippable using the general-purpose
# parse_biom_table function
Expand Down