Skip to content

Commit 386c100

Browse files
committed
fixed tests with line endings for UNIX/Windows
Ensure that CRLF/LF line endings do not matter for tests. Fixed sha256 test, which incorrectly wrote a text file instead of binary.
1 parent 359d60d commit 386c100

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Changes
1414
- update online docs theme (#43)
15+
- tested for Python 2.7, 3.6 - 3.9 on Linux, macOS, Windows (#48)
1516

1617
## [0.8.0] - 2019-08-13
1718

MDAnalysisData/tests/test_base.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,29 @@ def test_dir(self, bunch):
5454

5555
def test_read_description():
5656
descr = base._read_description("adk_equilibrium.rst")
57-
assert len(descr) == 1252
58-
assert descr.startswith(".. -*- coding: utf-8 -*-\n\n.. _`adk-equilibrium-dataset`:")
57+
assert (descr.startswith( # UNIX
58+
".. -*- coding: utf-8 -*-\n\n.. _`adk-equilibrium-dataset`:") or
59+
descr.startswith( # Windows
60+
".. -*- coding: utf-8 -*-\r\n\r\n.. _`adk-equilibrium-dataset`:"))
61+
# descr is read with automatic line ending conversion so by splitting into
62+
# words we don't need to care about that (len(descr) differs between UNIX
63+
# and Windows)
64+
n_words = len(descr.split())
65+
assert n_words == 153
5966

6067
def test_sha256(tmpdir, some_text):
6168
filename = "address.txt"
6269
with tmpdir.as_cwd():
63-
with open(filename, "w") as txt:
64-
txt.write(some_text)
70+
with open(filename, "wb") as txt:
71+
txt.write(some_text.encode("utf-8"))
6572
checksum = base._sha256(filename)
6673
assert checksum == "4446bfb2ec5dedfbd981d059d6005f5144b067b392a00e3bcf98f8302ec8f765"
6774

6875
@pytest.mark.parametrize('data_home,location', [
69-
(None, pathlib.Path("~/MDAnalysis_data").expanduser()),
70-
(str(pathlib.Path("/tmp/MDAnalysisData")), pathlib.Path("/tmp/MDAnalysisData")),
76+
(None,
77+
pathlib.Path("~/MDAnalysis_data").expanduser()),
78+
(str(pathlib.Path("/tmp/MDAnalysisData")),
79+
pathlib.Path("/tmp/MDAnalysisData")),
7180
])
7281
def test_get_data_home(data_home, location):
7382
assert base.get_data_home(data_home=data_home) == str(location)

0 commit comments

Comments
 (0)