Skip to content

Commit

Permalink
Merge pull request #17 from histrio/newline-in-description
Browse files Browse the repository at this point in the history
Fix for #16: handle new lines in description
  • Loading branch information
histrio committed Oct 13, 2021
2 parents ac0afed + c9383ad commit 88548ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ python:
- 2.7
- 3.7
- 3.8
- pypy
- pypy3

notifications:
Expand Down
3 changes: 2 additions & 1 deletion src/descript/ion.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def add_key(dfile, key, value):
with native_open(dfile, 'a') as fh:
if " " in key:
key = '"' + key + '"'
value = value.replace('\n', '\\n')
line = key + ' ' + value + '\n'
fh.write(line)

Expand All @@ -73,7 +74,7 @@ def get_key(dfile, key):
for line in dfile:
head, tail = parse_line(line)
if head == key:
return tail
return tail.replace('\\n', '\n')


class Description(object):
Expand Down
11 changes: 7 additions & 4 deletions test/test_descript_ion_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

test_descriptions = [
"test description",
"\ntest description",
"test \ndescription",
"test description\n",
]


Expand Down Expand Up @@ -87,8 +90,8 @@ def test_read_write_with_file_with_spaces_in_name(description, tmp_filename):
del f.description


@pytest.mark.parametrize('description', test_descriptions)
def test_do_not_store_full_path(description, tmp_filename):
def test_do_not_store_full_path(tmp_filename):
description = 'description'
with descript.ion.open(tmp_filename) as f:
f.description = description

Expand All @@ -100,8 +103,8 @@ def test_do_not_store_full_path(description, tmp_filename):
assert data == '{0} {1}\n'.format(basename, description)


@pytest.mark.parametrize('description', test_descriptions)
def test_no_need_full_path(description, tmpdir, tmp_filename):
def test_no_need_full_path(tmpdir, tmp_filename):
description = 'description'
base_tmp_filename = os.path.basename(tmp_filename)

tmpdir.join(base_tmp_filename).write('something')
Expand Down

0 comments on commit 88548ce

Please sign in to comment.