From a429b6b220c647daadefe7278dc89501f51e747c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikul=C3=A1=C5=A1=20Poul?= Date: Sat, 14 Jul 2018 18:43:28 +0200 Subject: [PATCH 1/9] Initial appveyor config --- .appveyor.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..aafd6e3 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,19 @@ +environment: + + matrix: + - PYTHON: "C:\\Python36" + - PYTHON: "C:\\Python37" + +build: off + +install: + - "%PYTHON%\\python.exe -m pip install -r requirements.txt" + - "%PYTHON%\\python.exe setup.py install" + +test_script: + - "%PYTHON%\\python.exe setup.py test" + +branches: + only: + - master + - /release-v[0-9]+/ From b7402cf6bed227e91d28221b87c539b12e91f2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikul=C3=A1=C5=A1=20Poul?= Date: Sat, 14 Jul 2018 19:11:20 +0200 Subject: [PATCH 2/9] Appveyor and Windows compat --- arca/_arca.py | 18 +++++++++++++++++- tests/common.py | 4 +++- tests/conftest.py | 8 +++++++- tests/test_vagrant.py | 6 +++--- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/arca/_arca.py b/arca/_arca.py index 8c2ced1..ed4ebea 100644 --- a/arca/_arca.py +++ b/arca/_arca.py @@ -1,5 +1,6 @@ import hashlib import json +import platform import re from collections import defaultdict from datetime import datetime @@ -139,7 +140,22 @@ def validate_repo_url(self, repo: str): :raise ValueError: If the URL is not valid """ # that should match valid git repos - if not isinstance(repo, str) or not re.match(r"^(https?|file)://[\w._\-/~]*[.git]?/?$", repo): + valid = True + + url_regex = re.compile(r"^https?://[\w._\-/~]*[.git]?/?$") + + if not isinstance(repo, str): + valid = False + + if platform.system() == "Windows": + if not url_regex.match(repo) and not re.match(r"file://(localhost)?/[a-zA-Z]:\\[\\\S|*\S]?.*", repo): + valid = False + + else: + if not url_regex.match(repo) and not re.match(r"file://[\w._\-/~]*[.git]?/?$", repo): + valid = False + + if not valid: raise ValueError(f"{repo} is not a valid http[s] or file:// git repository.") def repo_id(self, repo: str) -> str: diff --git a/tests/common.py b/tests/common.py index 9926962..657d57e 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1,8 +1,10 @@ import os - +from pathlib import Path if os.environ.get("TRAVIS", False): BASE_DIR = "/home/travis/build/{}/test_loc".format(os.environ.get("TRAVIS_REPO_SLUG", "mikicz/arca")) +elif os.environ.get("APPVEYOR", False): + BASE_DIR = Path(os.environ["APPVEYOR_BUILD_FOLDER"]) / "test_loc" else: BASE_DIR = "/tmp/arca/test" diff --git a/tests/conftest.py b/tests/conftest.py index d8757db..894bf99 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,4 @@ +import platform import shutil import tempfile from pathlib import Path @@ -16,7 +17,12 @@ def create_temp_repo(file) -> TempRepo: git_dir = Path(tempfile.mkdtemp()) repo = Repo.init(str(git_dir)) - return TempRepo(repo, git_dir, f"file://{git_dir}", "master", git_dir / file) + file_url = f"file://{git_dir}" + + if platform.system() == "Windows": + file_url = f"file:///{git_dir}" + + return TempRepo(repo, git_dir, file_url, "master", git_dir / file) @pytest.fixture() diff --git a/tests/test_vagrant.py b/tests/test_vagrant.py index 1d613ac..8ebde65 100644 --- a/tests/test_vagrant.py +++ b/tests/test_vagrant.py @@ -11,8 +11,8 @@ def test_validation(): - if os.environ.get("TRAVIS", False): - pytest.skip("Vagrant doesn't work on Travis") + if os.environ.get("CI", False): + pytest.skip("Vagrant doesn't work on CIs") backend = VagrantBackend() @@ -54,7 +54,7 @@ def test_validation(): # If you want to test that even init of the VM works, set ``destroy`` to True, it will destroy the previous one as well. # Set to ``False`` by default to bootup time and bandwidth. def test_vagrant(temp_repo_func, destroy=False): - if os.environ.get("TRAVIS", False): + if os.environ.get("CI", False): pytest.skip("Vagrant doesn't work on Travis") backend = VagrantBackend(verbosity=2, use_registry_name="docker.io/mikicz/arca-test", From c7ddef3e001adc3035bf8f2d936e5a7c55dd2f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikul=C3=A1=C5=A1=20Poul?= Date: Sat, 14 Jul 2018 19:17:30 +0200 Subject: [PATCH 3/9] Not deleting fixtures --- tests/conftest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 894bf99..6c818ac 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,4 @@ +import os import platform import shutil import tempfile @@ -36,7 +37,11 @@ def temp_repo_func(): yield temp_repo - shutil.rmtree(str(temp_repo.repo_path)) + # The fixture is not being cleaned because the deletion raises + # [WinError 32] The process cannot access the file because it is being used by another process + + if not os.environ.get("APPVEYOR", False): + shutil.rmtree(str(temp_repo.repo_path)) @pytest.fixture() @@ -50,4 +55,5 @@ def temp_repo_static(): yield temp_repo - shutil.rmtree(str(temp_repo.repo_path)) + if not os.environ.get("APPVEYOR", False): + shutil.rmtree(str(temp_repo.repo_path)) From 0c3a1f717069bd57cb5be1d81d4cc9ce19074c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikul=C3=A1=C5=A1=20Poul?= Date: Sat, 14 Jul 2018 19:32:04 +0200 Subject: [PATCH 4/9] More conditions on shutil.rmtree, fixed params for validation repo urls --- arca/_arca.py | 14 ++++++------- tests/test_arca_class.py | 45 +++++++++++++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/arca/_arca.py b/arca/_arca.py index ed4ebea..847539c 100644 --- a/arca/_arca.py +++ b/arca/_arca.py @@ -146,14 +146,14 @@ def validate_repo_url(self, repo: str): if not isinstance(repo, str): valid = False - - if platform.system() == "Windows": - if not url_regex.match(repo) and not re.match(r"file://(localhost)?/[a-zA-Z]:\\[\\\S|*\S]?.*", repo): - valid = False - else: - if not url_regex.match(repo) and not re.match(r"file://[\w._\-/~]*[.git]?/?$", repo): - valid = False + if platform.system() == "Windows": + if not url_regex.match(repo) and not re.match(r"file://(localhost)?/[a-zA-Z]:\\[\\\S|*\S]?.*", repo): + valid = False + + else: + if not url_regex.match(repo) and not re.match(r"file://[\w._\-/~]*[.git]?/?$", repo): + valid = False if not valid: raise ValueError(f"{repo} is not a valid http[s] or file:// git repository.") diff --git a/tests/test_arca_class.py b/tests/test_arca_class.py index c7abde1..d7fbe2d 100644 --- a/tests/test_arca_class.py +++ b/tests/test_arca_class.py @@ -1,4 +1,6 @@ # encoding=utf-8 +import os +import platform import re import shutil from pathlib import Path @@ -32,18 +34,33 @@ class NotASubclassClass: @pytest.mark.parametrize(["url", "valid"], [ + # http/s ("http://host.xz/path/to/repo.git/", True), ("https://host.xz/path/to/repo.git/", True), ("http://host.xz/path/to/repo.git", True), ("https://host.xz/path/to/repo.git", True), - ("file:///path/to/repo.git/", True), - ("file://~/path/to/repo.git/", True), ("http://host.xz/path/to/repo/", True), ("https://host.xz/path/to/repo/", True), ("http://host.xz/path/to/repo", True), ("https://host.xz/path/to/repo", True), - ("file:///path/to/repo.git", True), - ("file://~/path/to/repo.git", True), + + # linux paths + pytest.param("file:///path/to/repo.git/", True, + marks=pytest.mark.skipif(platform.system() == "Windows", reason="Linux Path")), + pytest.param("file://~/path/to/repo.git/", True, + marks=pytest.mark.skipif(platform.system() == "Windows", reason="Linux Path")), + pytest.param("file:///path/to/repo.git", True, + marks=pytest.mark.skipif(platform.system() == "Windows", reason="Linux Path")), + pytest.param("file://~/path/to/repo.git", True, + marks=pytest.mark.skipif(platform.system() == "Windows", reason="Linux Path")), + + # windows paths + pytest.param("file:///C:\\user\\path \\to\\repo", True, + marks=pytest.mark.skipif(platform.system() != "Windows", reason="Windows Path")), + pytest.param("http:///c:\\user\\path \\to\\repo", True, + marks=pytest.mark.skipif(platform.system() != "Windows", reason="Windows Path")), + + # ssh ("git://host.xz/path/to/repo.git/", False), ("git://host.xz/~user/path/to/repo.git/", False), ("ssh://host.xz/path/to/repo.git/", False), @@ -177,7 +194,8 @@ def test_depth(temp_repo_static): cloned_repo, cloned_repo_path = arca.get_files(temp_repo_static.url, temp_repo_static.branch) assert cloned_repo.commit().count() == 2 - shutil.rmtree(str(cloned_repo_path)) + if not os.environ.get("APPVEYOR", False): + shutil.rmtree(str(cloned_repo_path)) # test that when setting a certain depth, at least the depth is pulled (in case of merges etc) @@ -194,7 +212,8 @@ def test_depth(temp_repo_static): cloned_repo, cloned_repo_path = arca.get_files(temp_repo_static.url, temp_repo_static.branch) assert cloned_repo.commit().count() == before_second_pull + 1 - shutil.rmtree(str(cloned_repo_path)) + if not os.environ.get("APPVEYOR", False): + shutil.rmtree(str(cloned_repo_path)) # test when setting depth bigger than repo size, no fictional commits are included @@ -202,7 +221,8 @@ def test_depth(temp_repo_static): assert cloned_repo.commit().count() == 22 # 20 plus the 2 extra commits - shutil.rmtree(str(cloned_repo_path)) + if not os.environ.get("APPVEYOR", False): + shutil.rmtree(str(cloned_repo_path)) # test no limit @@ -254,7 +274,9 @@ def test_reference(): cloned_repo, cloned_repo_path = arca.get_files(git_url_1, branch, reference=Path("/tmp/arca/") / str(uuid4())) assert (cloned_repo_path / "test_file.txt").read_text() == last_uuid - shutil.rmtree(str(cloned_repo_path)) + + if not os.environ.get("APPVEYOR", False): + shutil.rmtree(str(cloned_repo_path)) # test existing reference with no common commits @@ -269,7 +291,9 @@ def test_reference(): cloned_repo, cloned_repo_path = arca.get_files(git_url_1, branch, reference=git_dir_2) assert (cloned_repo_path / "test_file.txt").read_text() == last_uuid - shutil.rmtree(str(cloned_repo_path)) + + if not os.environ.get("APPVEYOR", False): + shutil.rmtree(str(cloned_repo_path)) # test existing reference with common commits @@ -351,7 +375,8 @@ def test_pull_error(): with pytest.raises(PullError): arca.get_files(git_url, "some_branch") - shutil.rmtree(str(git_dir)) + if not os.environ.get("APPVEYOR", False): + shutil.rmtree(str(git_dir)) with pytest.raises(PullError): arca.get_files(git_url, "master") From cbc3b6f066c823e8a904d9070265a2366a771921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikul=C3=A1=C5=A1=20Poul?= Date: Sat, 14 Jul 2018 20:02:36 +0200 Subject: [PATCH 5/9] Paths and unicode --- tests/common.py | 2 +- tests/test_arca_class.py | 12 ++++++------ tests/test_backends.py | 2 +- tests/test_single_pull.py | 4 ++-- tests/test_vagrant.py | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/common.py b/tests/common.py index 657d57e..c980e7c 100644 --- a/tests/common.py +++ b/tests/common.py @@ -4,7 +4,7 @@ if os.environ.get("TRAVIS", False): BASE_DIR = "/home/travis/build/{}/test_loc".format(os.environ.get("TRAVIS_REPO_SLUG", "mikicz/arca")) elif os.environ.get("APPVEYOR", False): - BASE_DIR = Path(os.environ["APPVEYOR_BUILD_FOLDER"]) / "test_loc" + BASE_DIR = str(Path(os.environ["APPVEYOR_BUILD_FOLDER"]) / "test_loc") else: BASE_DIR = "/tmp/arca/test" diff --git a/tests/test_arca_class.py b/tests/test_arca_class.py index d7fbe2d..bebc1f2 100644 --- a/tests/test_arca_class.py +++ b/tests/test_arca_class.py @@ -57,7 +57,7 @@ class NotASubclassClass: # windows paths pytest.param("file:///C:\\user\\path \\to\\repo", True, marks=pytest.mark.skipif(platform.system() != "Windows", reason="Windows Path")), - pytest.param("http:///c:\\user\\path \\to\\repo", True, + pytest.param("file:///c:\\user\\path \\to\\repo", True, marks=pytest.mark.skipif(platform.system() != "Windows", reason="Windows Path")), # ssh @@ -257,7 +257,7 @@ def test_reference(): arca = Arca(base_dir=BASE_DIR) branch = "master" - git_dir_1 = Path("/tmp/arca/") / str(uuid4()) + git_dir_1 = Path(BASE_DIR) / str(uuid4()) git_url_1 = f"file://{git_dir_1}" filepath_1 = git_dir_1 / "test_file.txt" repo_1 = Repo.init(git_dir_1) @@ -272,7 +272,7 @@ def test_reference(): # test nonexistent reference - cloned_repo, cloned_repo_path = arca.get_files(git_url_1, branch, reference=Path("/tmp/arca/") / str(uuid4())) + cloned_repo, cloned_repo_path = arca.get_files(git_url_1, branch, reference=Path(BASE_DIR) / str(uuid4())) assert (cloned_repo_path / "test_file.txt").read_text() == last_uuid if not os.environ.get("APPVEYOR", False): @@ -280,7 +280,7 @@ def test_reference(): # test existing reference with no common commits - git_dir_2 = Path("/tmp/arca/") / str(uuid4()) + git_dir_2 = Path(BASE_DIR) / str(uuid4()) filepath_2 = git_dir_2 / "test_file.txt" repo_2 = Repo.init(git_dir_2) @@ -297,7 +297,7 @@ def test_reference(): # test existing reference with common commits - git_dir_3 = Path("/tmp/arca/") / str(uuid4()) + git_dir_3 = Path(BASE_DIR) / str(uuid4()) git_url_3 = f"file://{git_dir_3}" filepath_3 = git_dir_3 / "test_file.txt" repo_3 = repo_1.clone(str(git_dir_3)) # must pass string, fails otherwise @@ -358,7 +358,7 @@ def test_get_reference_repository(temp_repo_static): def test_pull_error(): arca = Arca(base_dir=BASE_DIR) - git_dir = Path("/tmp/arca/") / str(uuid4()) + git_dir = Path(BASE_DIR) / str(uuid4()) git_url = f"file://{git_dir}" with pytest.raises(PullError): diff --git a/tests/test_backends.py b/tests/test_backends.py index fd507c9..fb318d6 100644 --- a/tests/test_backends.py +++ b/tests/test_backends.py @@ -56,7 +56,7 @@ def test_backends(temp_repo_func, backend, requirements_location, file_location) assert arca.run(temp_repo_func.url, temp_repo_func.branch, task).output == "Some string" - filepath.write_text(SECOND_RETURN_STR_FUNCTION) + filepath.write_text(SECOND_RETURN_STR_FUNCTION, encoding="utf-8") temp_repo_func.repo.create_head("new_branch") temp_repo_func.repo.create_tag("test_tag") temp_repo_func.repo.index.add([str(filepath)]) diff --git a/tests/test_single_pull.py b/tests/test_single_pull.py index 99f6341..1a6011a 100644 --- a/tests/test_single_pull.py +++ b/tests/test_single_pull.py @@ -13,7 +13,7 @@ def test_single_pull(temp_repo_func, mocker): assert arca.run(temp_repo_func.url, temp_repo_func.branch, task).output == "Some string" assert arca._pull.call_count == 1 - temp_repo_func.file_path.write_text(SECOND_RETURN_STR_FUNCTION) + temp_repo_func.file_path.write_text(SECOND_RETURN_STR_FUNCTION, encoding="utf-8") temp_repo_func.repo.index.add([str(temp_repo_func.file_path)]) temp_repo_func.repo.index.commit("Updated function") @@ -40,7 +40,7 @@ def test_pull_efficiency(temp_repo_func, mocker): assert arca.run(temp_repo_func.url, temp_repo_func.branch, task).output == "Some string" assert arca._pull.call_count == 2 - temp_repo_func.file_path.write_text(SECOND_RETURN_STR_FUNCTION) + temp_repo_func.file_path.write_text(SECOND_RETURN_STR_FUNCTION, encoding="utf-8") temp_repo_func.repo.index.add([str(temp_repo_func.file_path)]) temp_repo_func.repo.index.commit("Updated function") diff --git a/tests/test_vagrant.py b/tests/test_vagrant.py index 8ebde65..052d9de 100644 --- a/tests/test_vagrant.py +++ b/tests/test_vagrant.py @@ -78,7 +78,7 @@ def test_vagrant(temp_repo_func, destroy=False): # branch branch - return unicode temp_repo_func.repo.create_head("branch") temp_repo_func.repo.branches.branch.checkout() - temp_repo_func.file_path.write_text(SECOND_RETURN_STR_FUNCTION) + temp_repo_func.file_path.write_text(SECOND_RETURN_STR_FUNCTION, encoding="utf-8") temp_repo_func.repo.index.add([str(temp_repo_func.file_path)]) temp_repo_func.repo.index.commit("Test unicode on a separate branch") From 71d1c51e2be7a9512e71faee2fe14291a12d0259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikul=C3=A1=C5=A1=20Poul?= Date: Sat, 14 Jul 2018 20:12:36 +0200 Subject: [PATCH 6/9] more conditional deletes --- tests/test_arca_class.py | 3 +-- tests/test_runner.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_arca_class.py b/tests/test_arca_class.py index bebc1f2..edbde5f 100644 --- a/tests/test_arca_class.py +++ b/tests/test_arca_class.py @@ -375,8 +375,7 @@ def test_pull_error(): with pytest.raises(PullError): arca.get_files(git_url, "some_branch") - if not os.environ.get("APPVEYOR", False): - shutil.rmtree(str(git_dir)) + shutil.rmtree(str(git_dir)) with pytest.raises(PullError): arca.get_files(git_url, "master") diff --git a/tests/test_runner.py b/tests/test_runner.py index 4cea1e7..23dea4b 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -1,4 +1,5 @@ import json +import os import tempfile from pathlib import Path @@ -49,7 +50,8 @@ def test_definition_corruption(definition): assert output["error"] assert output["reason"] == "corrupted_definition" - file.unlink() + if not os.environ.get("APPVEYOR", False): + file.unlink() @pytest.mark.parametrize("module_name,object_name", [ @@ -74,7 +76,8 @@ def test_import_error(module_name, object_name): assert output["error"] assert output["reason"] == "import" - file.unlink() + if not os.environ.get("APPVEYOR", False): + file.unlink() @pytest.mark.parametrize("func,result", [ @@ -104,7 +107,8 @@ def test_run(mocker, func, result): assert output["success"] is False assert result.__name__ in output["error"] - file.unlink() + if not os.environ.get("APPVEYOR", False): + file.unlink() @pytest.mark.parametrize("args,kwargs,result", [ @@ -130,7 +134,8 @@ def func(カ): assert Result(output).output == result - file.unlink() + if not os.environ.get("APPVEYOR", False): + file.unlink() def test_output(temp_repo_func): From 4c166673433402f552f5add606f4b4de999a3dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikul=C3=A1=C5=A1=20Poul?= Date: Sat, 14 Jul 2018 20:21:07 +0200 Subject: [PATCH 7/9] Closing repo? --- .appveyor.yml | 2 +- tests/test_arca_class.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index aafd6e3..1386ad4 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,7 +1,7 @@ environment: matrix: - - PYTHON: "C:\\Python36" +# - PYTHON: "C:\\Python36" - PYTHON: "C:\\Python37" build: off diff --git a/tests/test_arca_class.py b/tests/test_arca_class.py index edbde5f..1c10988 100644 --- a/tests/test_arca_class.py +++ b/tests/test_arca_class.py @@ -375,6 +375,8 @@ def test_pull_error(): with pytest.raises(PullError): arca.get_files(git_url, "some_branch") + repo.close() + shutil.rmtree(str(git_dir)) with pytest.raises(PullError): From d5c7e47b82f95117a4141b1ffd22936a359fd666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikul=C3=A1=C5=A1=20Poul?= Date: Sat, 14 Jul 2018 20:23:19 +0200 Subject: [PATCH 8/9] 3.6 --- .appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 1386ad4..afa8088 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,8 +1,8 @@ environment: matrix: -# - PYTHON: "C:\\Python36" - - PYTHON: "C:\\Python37" + - PYTHON: "C:\\Python36" +# - PYTHON: "C:\\Python37" build: off From e13cb7b75878b43aee35160d7bfa9e274d358ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikul=C3=A1=C5=A1=20Poul?= Date: Sat, 14 Jul 2018 20:35:36 +0200 Subject: [PATCH 9/9] Fixed closing, upgrading docker package if it helps... --- requirements.txt | 2 +- setup.py | 4 ++-- tests/conftest.py | 12 ++++-------- tests/test_arca_class.py | 21 ++++++++++----------- tests/test_runner.py | 25 +++++++++++++------------ 5 files changed, 30 insertions(+), 34 deletions(-) diff --git a/requirements.txt b/requirements.txt index 5b7a6b9..e3ee38c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ gitpython pytest dogpile.cache==0.6.5 -docker~=3.1.0 +docker~=3.4.1 pytest-flake8 pytest-cov pytest-mock diff --git a/setup.py b/setup.py index 2da721a..f0563b9 100644 --- a/setup.py +++ b/setup.py @@ -39,10 +39,10 @@ def long_description(): ], extras_require={ "docker": [ - "docker~=3.2.1", + "docker~=3.4.1", ], "vagrant": [ - "docker~=3.2.1", + "docker~=3.4.1", "python-vagrant", "fabric3", ], diff --git a/tests/conftest.py b/tests/conftest.py index 6c818ac..a7067d1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,3 @@ -import os import platform import shutil import tempfile @@ -37,11 +36,8 @@ def temp_repo_func(): yield temp_repo - # The fixture is not being cleaned because the deletion raises - # [WinError 32] The process cannot access the file because it is being used by another process - - if not os.environ.get("APPVEYOR", False): - shutil.rmtree(str(temp_repo.repo_path)) + temp_repo.repo.close() + shutil.rmtree(str(temp_repo.repo_path)) @pytest.fixture() @@ -55,5 +51,5 @@ def temp_repo_static(): yield temp_repo - if not os.environ.get("APPVEYOR", False): - shutil.rmtree(str(temp_repo.repo_path)) + temp_repo.repo.close() + shutil.rmtree(str(temp_repo.repo_path)) diff --git a/tests/test_arca_class.py b/tests/test_arca_class.py index 1c10988..29e766a 100644 --- a/tests/test_arca_class.py +++ b/tests/test_arca_class.py @@ -1,5 +1,4 @@ # encoding=utf-8 -import os import platform import re import shutil @@ -194,8 +193,8 @@ def test_depth(temp_repo_static): cloned_repo, cloned_repo_path = arca.get_files(temp_repo_static.url, temp_repo_static.branch) assert cloned_repo.commit().count() == 2 - if not os.environ.get("APPVEYOR", False): - shutil.rmtree(str(cloned_repo_path)) + cloned_repo.close() + shutil.rmtree(str(cloned_repo_path)) # test that when setting a certain depth, at least the depth is pulled (in case of merges etc) @@ -212,8 +211,8 @@ def test_depth(temp_repo_static): cloned_repo, cloned_repo_path = arca.get_files(temp_repo_static.url, temp_repo_static.branch) assert cloned_repo.commit().count() == before_second_pull + 1 - if not os.environ.get("APPVEYOR", False): - shutil.rmtree(str(cloned_repo_path)) + cloned_repo.close() + shutil.rmtree(str(cloned_repo_path)) # test when setting depth bigger than repo size, no fictional commits are included @@ -221,8 +220,8 @@ def test_depth(temp_repo_static): assert cloned_repo.commit().count() == 22 # 20 plus the 2 extra commits - if not os.environ.get("APPVEYOR", False): - shutil.rmtree(str(cloned_repo_path)) + cloned_repo.close() + shutil.rmtree(str(cloned_repo_path)) # test no limit @@ -275,8 +274,8 @@ def test_reference(): cloned_repo, cloned_repo_path = arca.get_files(git_url_1, branch, reference=Path(BASE_DIR) / str(uuid4())) assert (cloned_repo_path / "test_file.txt").read_text() == last_uuid - if not os.environ.get("APPVEYOR", False): - shutil.rmtree(str(cloned_repo_path)) + cloned_repo.close() + shutil.rmtree(str(cloned_repo_path)) # test existing reference with no common commits @@ -292,8 +291,8 @@ def test_reference(): cloned_repo, cloned_repo_path = arca.get_files(git_url_1, branch, reference=git_dir_2) assert (cloned_repo_path / "test_file.txt").read_text() == last_uuid - if not os.environ.get("APPVEYOR", False): - shutil.rmtree(str(cloned_repo_path)) + cloned_repo.close() + shutil.rmtree(str(cloned_repo_path)) # test existing reference with common commits diff --git a/tests/test_runner.py b/tests/test_runner.py index 23dea4b..c538ee8 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -36,7 +36,8 @@ "kwargs": [1, 2, 3]}, ]) def test_definition_corruption(definition): - _, file = tempfile.mkstemp() + fd, file = tempfile.mkstemp() + file = Path(file) if isinstance(definition, dict): @@ -50,8 +51,8 @@ def test_definition_corruption(definition): assert output["error"] assert output["reason"] == "corrupted_definition" - if not os.environ.get("APPVEYOR", False): - file.unlink() + os.close(fd) + file.unlink() @pytest.mark.parametrize("module_name,object_name", [ @@ -61,7 +62,7 @@ def test_definition_corruption(definition): ("arca", "Arca.some_random_method"), ]) def test_import_error(module_name, object_name): - _, file = tempfile.mkstemp() + fd, file = tempfile.mkstemp() file = Path(file) file.write_text(json.dumps({ @@ -76,8 +77,8 @@ def test_import_error(module_name, object_name): assert output["error"] assert output["reason"] == "import" - if not os.environ.get("APPVEYOR", False): - file.unlink() + os.close(fd) + file.unlink() @pytest.mark.parametrize("func,result", [ @@ -89,7 +90,7 @@ def test_run(mocker, func, result): load = mocker.patch("arca._runner.EntryPoint.load") load.return_value = func - _, file = tempfile.mkstemp() + fd, file = tempfile.mkstemp() file = Path(file) file.write_text(json.dumps({ @@ -107,8 +108,8 @@ def test_run(mocker, func, result): assert output["success"] is False assert result.__name__ in output["error"] - if not os.environ.get("APPVEYOR", False): - file.unlink() + os.close(fd) + file.unlink() @pytest.mark.parametrize("args,kwargs,result", [ @@ -125,7 +126,7 @@ def func(カ): load.return_value = func - _, file = tempfile.mkstemp() + fd, file = tempfile.mkstemp() file = Path(file) file.write_text(Task("library.mod:func", args=args, kwargs=kwargs).json) @@ -134,8 +135,8 @@ def func(カ): assert Result(output).output == result - if not os.environ.get("APPVEYOR", False): - file.unlink() + os.close(fd) + file.unlink() def test_output(temp_repo_func):