From 6c12a2e555ab75ecd81a37723047e969e0178519 Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Sat, 7 Dec 2019 15:50:03 +0100 Subject: [PATCH] test: fix unicode test_ignore issue under Windows Py2 --- tests/dir_helpers.py | 4 ++-- tests/func/test_ignore.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/dir_helpers.py b/tests/dir_helpers.py index 336fd3474..17379d3a6 100644 --- a/tests/dir_helpers.py +++ b/tests/dir_helpers.py @@ -6,7 +6,7 @@ import pytest from funcy.py3 import lmap, retry from dvc.utils import makedirs -from dvc.utils.compat import basestring, is_py2, pathlib, fspath, fspath_py35 +from dvc.utils.compat import basestring, pathlib, fspath, fspath_py35, bytes __all__ = ["tmp_dir", "scm", "dvc", "repo_template", "run_copy", "erepo_dir"] @@ -61,7 +61,7 @@ class TmpDir(pathlib.Path): self._gen(contents, prefix=path) else: makedirs(path.parent, exist_ok=True) - if is_py2 and isinstance(contents, str): + if isinstance(contents, bytes): path.write_bytes(contents) else: path.write_text(contents, encoding="utf-8") diff --git a/tests/func/test_ignore.py b/tests/func/test_ignore.py index b08d57415..ee4c5f7a1 100644 --- a/tests/func/test_ignore.py +++ b/tests/func/test_ignore.py @@ -25,7 +25,12 @@ def test_ignore(tmp_dir, dvc, monkeypatch): def test_ignore_unicode(tmp_dir, dvc): - tmp_dir.gen({"dir": {"тест": "проверка", "other": "text"}}) + tmp_dir.gen({"dir": {"other": "text"}}) + # Path() doesn't handle unicode paths in Windows/Python 2 + # I don't know to debug it further, waiting till Python 2 EOL + with open("dir/тест", "wb") as fd: + fd.write("проверка".encode("utf-8")) + tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "dir/тест") assert _files_set("dir", dvc.dvcignore) == {"dir/other"}