Skip to content

Commit

Permalink
refactor: upgrade from disutils.dir_util to shutil
Browse files Browse the repository at this point in the history
  • Loading branch information
apotterri committed Jul 8, 2024
1 parent fa53acf commit 4c35686
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
4 changes: 2 additions & 2 deletions _appmap/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import socket
import sys
from distutils.dir_util import copy_tree
from shutil import copytree
from functools import partial, partialmethod
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -98,7 +98,7 @@ def git_directory_fixture(tmp_path_factory):

@pytest.fixture(name="git")
def tmp_git(git_directory, tmp_path):
copy_tree(git_directory, str(tmp_path))
copytree(git_directory, str(tmp_path), dirs_exist_ok=True)
return utils.git(cwd=tmp_path)


Expand Down
4 changes: 2 additions & 2 deletions _appmap/test/test_command.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import re
from distutils.dir_util import copy_tree
from shutil import copytree
from importlib.metadata import version

import pytest
Expand All @@ -14,7 +14,7 @@
@pytest.fixture(name="_cmd_setup")
def _cmd_setup(request, git, data_dir, monkeypatch):
repo_root = git.cwd
copy_tree(data_dir / request.param, str(repo_root))
copytree(data_dir / request.param, str(repo_root), dirs_exist_ok=True)
monkeypatch.chdir(repo_root)

# pylint: disable=protected-access
Expand Down
22 changes: 11 additions & 11 deletions _appmap/test/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# pylint: disable=missing-function-docstring

from contextlib import contextmanager
from distutils.dir_util import copy_tree
from shutil import copytree
from pathlib import Path
from textwrap import dedent

Expand Down Expand Up @@ -154,7 +154,7 @@ def check_default_config(self, expected_name):
class TestDefaultConfig(DefaultHelpers):
def test_created(self, git, data_dir, monkeypatch):
repo_root = git.cwd
copy_tree(data_dir / "config", str(repo_root))
copytree(data_dir / "config", str(repo_root), dirs_exist_ok=True)
monkeypatch.chdir(repo_root)

# pylint: disable=protected-access
Expand All @@ -163,7 +163,7 @@ def test_created(self, git, data_dir, monkeypatch):
self.check_default_config(repo_root.name)

def test_created_outside_repo(self, data_dir, tmpdir, monkeypatch):
copy_tree(data_dir / "config", str(tmpdir))
copytree(data_dir / "config", str(tmpdir), dirs_exist_ok=True)
monkeypatch.chdir(tmpdir)

# pylint: disable=protected-access
Expand All @@ -180,7 +180,7 @@ def test_skipped_when_overridden(self):
assert not appmap.enabled()

def test_exclusions(self, data_dir, tmpdir, mocker, monkeypatch):
copy_tree(data_dir / "config-exclude", str(tmpdir))
copytree(data_dir / "config-exclude", str(tmpdir), dirs_exist_ok=True)
monkeypatch.chdir(tmpdir)
mocker.patch(
"_appmap.configuration._get_sys_prefix",
Expand All @@ -193,7 +193,7 @@ def test_exclusions(self, data_dir, tmpdir, mocker, monkeypatch):

def test_created_if_missing_and_enabled(self, git, data_dir, monkeypatch, tmpdir):
repo_root = git.cwd
copy_tree(data_dir / "config", str(repo_root))
copytree(data_dir / "config", str(repo_root), dirs_exist_ok=True)
monkeypatch.chdir(repo_root)

path = Path(repo_root / "appmap.yml")
Expand All @@ -213,7 +213,7 @@ def test_created_if_missing_and_enabled(self, git, data_dir, monkeypatch, tmpdir

def test_not_created_if_missing_and_not_enabled(self, git, data_dir, monkeypatch):
repo_root = git.cwd
copy_tree(data_dir / "config", str(repo_root))
copytree(data_dir / "config", str(repo_root), dirs_exist_ok=True)
monkeypatch.chdir(repo_root)

path = Path(repo_root / "appmap.yml")
Expand All @@ -229,7 +229,7 @@ def test_not_created_if_missing_and_not_enabled(self, git, data_dir, monkeypatch
class TestEmpty(DefaultHelpers):
@pytest.fixture(autouse=True)
def setup_config(self, data_dir, monkeypatch, tmpdir):
copy_tree(data_dir / "config", str(tmpdir))
copytree(data_dir / "config", str(tmpdir), dirs_exist_ok=True)
monkeypatch.chdir(tmpdir)

@contextmanager
Expand Down Expand Up @@ -269,7 +269,7 @@ class TestSearchConfig:
# pylint: disable=too-many-arguments

def test_config_in_parent_folder(self, data_dir, tmpdir, monkeypatch):
copy_tree(data_dir / "config-up", str(tmpdir))
copytree(data_dir / "config-up", str(tmpdir), dirs_exist_ok=True)
wd = tmpdir / "project" / "p1"
monkeypatch.chdir(wd)

Expand All @@ -279,8 +279,8 @@ def test_config_in_parent_folder(self, data_dir, tmpdir, monkeypatch):
assert str(Env.current.output_dir).endswith(str(tmpdir / "tmp" / "appmap"))

def _init_repo(self, data_dir, tmpdir, git_directory, repo_root, appmapdir):
copy_tree(data_dir / "config-up", str(tmpdir))
copy_tree(git_directory, str(repo_root))
copytree(data_dir / "config-up", str(tmpdir), dirs_exist_ok=True)
copytree(git_directory, str(repo_root), dirs_exist_ok=True)
with open(appmapdir / "appmap.yml", "w+", encoding="utf-8") as f:
f.writelines(
dedent("""
Expand Down Expand Up @@ -325,7 +325,7 @@ def test_config_above_repo_root(self, data_dir, tmpdir, git_directory, monkeypat
assert Env.current.enabled

def test_config_not_found_in_path_hierarchy(self, data_dir, tmpdir, monkeypatch):
copy_tree(data_dir / "config-up", str(tmpdir))
copytree(data_dir / "config-up", str(tmpdir), dirs_exist_ok=True)
wd = tmpdir / "project" / "p1"
monkeypatch.chdir(wd)

Expand Down
11 changes: 5 additions & 6 deletions _appmap/test/test_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

import json
import os
from distutils.dir_util import copy_tree
from distutils.file_util import copy_file
from shutil import copy, copytree
from threading import Thread

import appmap
import pytest

import appmap
from _appmap.event import Event
from _appmap.recorder import Recorder, ThreadRecorder
from _appmap.wrapt import FunctionWrapper
Expand Down Expand Up @@ -193,9 +192,9 @@ def add_event(name):
def test_process_recording(data_dir, shell, tmp_path):
fixture = data_dir / "package1"
tmp = tmp_path / "process"
copy_tree(fixture, str(tmp / "package1"))
copy_file(data_dir / "appmap.yml", str(tmp))
copy_tree(data_dir / "flask" / "init", str(tmp / "init"))
copytree(fixture, str(tmp / "package1"), dirs_exist_ok=True)
copy(data_dir / "appmap.yml", str(tmp))
copytree(data_dir / "flask" / "init", str(tmp / "init"), dirs_exist_ok=True)

ret = shell.run(
"python",
Expand Down
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[MAIN]
# Specify a score threshold under which the program will exit with error.
fail-under=9.87
fail-under=9.94


# Analyse import fallback blocks. This can be used to support both Python 2 and
Expand Down

0 comments on commit 4c35686

Please sign in to comment.