|
4 | 4 |
|
5 | 5 | from six.moves.urllib.request import urlretrieve |
6 | 6 |
|
| 7 | +try: |
| 8 | + import pathlib |
| 9 | +except ImportError: |
| 10 | + # Python 2.7 |
| 11 | + import pathlib2 as pathlib |
| 12 | + |
7 | 13 | import os |
8 | 14 | import os.path |
9 | 15 |
|
@@ -48,23 +54,32 @@ def test_dir(self, bunch): |
48 | 54 |
|
49 | 55 | def test_read_description(): |
50 | 56 | descr = base._read_description("adk_equilibrium.rst") |
51 | | - assert len(descr) == 1252 |
52 | | - 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 |
53 | 66 |
|
54 | 67 | def test_sha256(tmpdir, some_text): |
55 | 68 | filename = "address.txt" |
56 | 69 | with tmpdir.as_cwd(): |
57 | | - with open(filename, "w") as txt: |
58 | | - txt.write(some_text) |
| 70 | + with open(filename, "wb") as txt: |
| 71 | + txt.write(some_text.encode("utf-8")) |
59 | 72 | checksum = base._sha256(filename) |
60 | 73 | assert checksum == "4446bfb2ec5dedfbd981d059d6005f5144b067b392a00e3bcf98f8302ec8f765" |
61 | 74 |
|
62 | 75 | @pytest.mark.parametrize('data_home,location', [ |
63 | | - (None, os.path.expanduser("~/MDAnalysis_data")), |
64 | | - ("/tmp/MDAnalysisData", "/tmp/MDAnalysisData"), |
| 76 | + (None, |
| 77 | + pathlib.Path("~/MDAnalysis_data").expanduser()), |
| 78 | + (str(pathlib.Path("/tmp/MDAnalysisData")), |
| 79 | + pathlib.Path("/tmp/MDAnalysisData")), |
65 | 80 | ]) |
66 | 81 | def test_get_data_home(data_home, location): |
67 | | - assert base.get_data_home(data_home=data_home) == location |
| 82 | + assert base.get_data_home(data_home=data_home) == str(location) |
68 | 83 |
|
69 | 84 | def test_clear_data_home(tmpdir, some_text): |
70 | 85 | data_home_path = tmpdir.join("MDAnalysis_data_test") |
|
0 commit comments