diff --git a/CHANGELOG.md b/CHANGELOG.md index 98445fe6..dc502355 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,9 @@ these changes are prefixed with "**BREAKING**" ## [Unreleased][unreleased] -(no unreleased changes) +### Fixed + +* `delphin.tsdb.open()` does not use universal newlines ([#285]) ## [v1.2.3] @@ -1358,3 +1360,4 @@ information about changes, except for [#281]: https://github.com/delph-in/pydelphin/issues/281 [#282]: https://github.com/delph-in/pydelphin/issues/282 [#283]: https://github.com/delph-in/pydelphin/issues/283 +[#285]: https://github.com/delph-in/pydelphin/issues/285 diff --git a/delphin/tsdb.py b/delphin/tsdb.py index 33201859..a5adf95b 100644 --- a/delphin/tsdb.py +++ b/delphin/tsdb.py @@ -766,9 +766,9 @@ def open(dir: util.PathLike, """ path = get_path(dir, name) if path.suffix.lower() == '.gz': - return gzopen(path, mode='rt', encoding=encoding) + return gzopen(path, mode='rt', encoding=encoding, newline='\n') else: - return path.open(encoding=encoding) + return path.open(encoding=encoding, newline='\n') def write(dir: util.PathLike, diff --git a/tests/tsdb_test.py b/tests/tsdb_test.py index 9f20c36d..ec31d2f1 100644 --- a/tests/tsdb_test.py +++ b/tests/tsdb_test.py @@ -265,6 +265,16 @@ def test_write(single_item_skeleton): assert path.with_suffix('').exists() +def test_issue_285(empty_testsuite): + fields = tsdb.read_schema(empty_testsuite)['item'] + tsdb.write(empty_testsuite, 'item', [(0, 'The cat meows.\r')], fields) + fh = tsdb.open(empty_testsuite, 'item') + assert not fh.closed + with fh: + assert list(fh) == ['0@The cat meows.\r\n'] + assert fh.closed + + def test_write_database(tmp_path, mini_testsuite, empty_alt_testsuite): tmp_ts = tmp_path.joinpath('test_write_database') db = tsdb.Database(mini_testsuite)