mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Drop (seemingly?) unused sep2tabs function
This commit is contained in:
@@ -148,39 +148,6 @@ def convert_newlines(fname, in_place=True, tmp_dir=None, tmp_prefix="gxupload",
|
||||
return (i, temp_name)
|
||||
|
||||
|
||||
def sep2tabs(fname, in_place=True, patt=r"\s+", tmp_dir=None, tmp_prefix="gxupload"):
|
||||
"""
|
||||
Transforms in place a 'sep' separated file to a tab separated one
|
||||
"""
|
||||
regexp = re.compile(patt)
|
||||
fd, temp_name = tempfile.mkstemp(prefix=tmp_prefix, dir=tmp_dir)
|
||||
with io.open(fd, mode="w", encoding='utf-8') as fp:
|
||||
i = None
|
||||
for i, line in enumerate(io.open(fname, encoding='utf-8', newline='')):
|
||||
if line.endswith("\r"):
|
||||
line = line.rstrip('\r')
|
||||
elems = regexp.split(line)
|
||||
fp.write(u"%s\r" % '\t'.join(elems))
|
||||
elif line.endswith("\r\n"):
|
||||
line = line.rstrip('\r\n')
|
||||
elems = regexp.split(line)
|
||||
fp.write(u"%s\r\n" % '\t'.join(elems))
|
||||
else:
|
||||
line = line.rstrip('\n')
|
||||
elems = regexp.split(line)
|
||||
fp.write(u"%s\n" % '\t'.join(elems))
|
||||
if i is None:
|
||||
i = 0
|
||||
else:
|
||||
i += 1
|
||||
if in_place:
|
||||
shutil.move(temp_name, fname)
|
||||
# Return number of lines in file.
|
||||
return (i, None)
|
||||
else:
|
||||
return (i, temp_name)
|
||||
|
||||
|
||||
def convert_newlines_sep2tabs(fname, in_place=True, patt=r"\s+", tmp_dir=None, tmp_prefix="gxupload"):
|
||||
"""
|
||||
Combines above methods: convert_newlines() and sep2tabs()
|
||||
|
||||
@@ -7,18 +7,9 @@ from galaxy.datatypes.sniff import (
|
||||
convert_newlines,
|
||||
convert_newlines_sep2tabs,
|
||||
get_test_fname,
|
||||
sep2tabs,
|
||||
)
|
||||
|
||||
|
||||
def assert_converts_to_1234_sep2tabs(content, line_ending="\n"):
|
||||
with tempfile.NamedTemporaryFile(delete=False, mode='w') as tf:
|
||||
tf.write(content)
|
||||
rval = sep2tabs(tf.name, tmp_prefix="gxtest", tmp_dir=tempfile.gettempdir())
|
||||
assert rval == (2, None), rval
|
||||
assert '1\t2%s3\t4%s' % (line_ending, line_ending) == io.open(tf.name, newline='').read()
|
||||
|
||||
|
||||
def assert_converts_to_1234_convert_sep2tabs(content, expected='1\t2\n3\t4\n', line_ending="\n"):
|
||||
with tempfile.NamedTemporaryFile(delete=False, mode='w') as tf:
|
||||
tf.write(content)
|
||||
@@ -73,20 +64,6 @@ def test_convert_newlines_non_utf():
|
||||
assert open(new_file, "rb").read() == open(get_test_fname("1imzml"), "rb").read()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('source,line_ending', [
|
||||
("1 2\n3 4\n", None),
|
||||
("1 2\n3 4\n", None),
|
||||
("1\t2\n3\t4\n", None),
|
||||
("1\t2\r3\t4\r", '\r'),
|
||||
("1\t2\r\n3\t4\r\n", '\r\n'),
|
||||
])
|
||||
def test_sep2tabs(source, line_ending):
|
||||
if line_ending:
|
||||
assert_converts_to_1234_sep2tabs(source, line_ending)
|
||||
else:
|
||||
assert_converts_to_1234_sep2tabs(source)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('source,expected', [
|
||||
("1 2\n3 4\n", None),
|
||||
("1 2\n3 4\n", None),
|
||||
|
||||
Reference in New Issue
Block a user