From b1bece668958fe8e77aa336b6cee529ad9660df1 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 10:16:12 +0800 Subject: [PATCH 01/26] update setup action to v5 --- .github/workflows/lint.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5e4be4008..3d70cc8e8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,7 +9,7 @@ jobs: - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.x" @@ -26,5 +26,4 @@ jobs: - name: mypy run: | mypy --version - rm -rf .mypy_cache mypy src From 18475815f421cc6080fea7eb460be209a23d6698 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 10:29:52 +0800 Subject: [PATCH 02/26] fix exclude entry in pre-commit config --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca69d8fa1..66164dca8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -exclude: ^(docs|tests/files|cmd_line|tasks.py) +exclude: ^(docs|tests/test_files|tasks.py) ci: autoupdate_schedule: monthly From e914a984be286c11a8d247e6a4996c7f57957ff5 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 10:32:51 +0800 Subject: [PATCH 03/26] try to commit local pre-commit changes --- .pre-commit-config.yaml | 2 +- tests/test_collections.py | 1 + tests/test_design_patterns.py | 1 + tests/test_dev.py | 1 + tests/test_fractions.py | 1 + tests/test_functools.py | 1 + tests/test_io.py | 1 + tests/test_json.py | 1 + tests/test_os.py | 1 + tests/test_shutil.py | 1 + 10 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 66164dca8..71a31eb8a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.0 + rev: v0.5.4 hooks: - id: ruff args: [--fix] diff --git a/tests/test_collections.py b/tests/test_collections.py index 8057f7bc2..58d2af9e7 100644 --- a/tests/test_collections.py +++ b/tests/test_collections.py @@ -3,6 +3,7 @@ import os import pytest + from monty.collections import AttrDict, FrozenAttrDict, Namespace, frozendict, tree TEST_DIR = os.path.join(os.path.dirname(__file__), "test_files") diff --git a/tests/test_design_patterns.py b/tests/test_design_patterns.py index c37bc87da..67a7ffc2b 100644 --- a/tests/test_design_patterns.py +++ b/tests/test_design_patterns.py @@ -6,6 +6,7 @@ from typing import Any import pytest + from monty.design_patterns import cached_class, singleton diff --git a/tests/test_dev.py b/tests/test_dev.py index 8c44d8aec..13bb211be 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -7,6 +7,7 @@ from unittest.mock import patch import pytest + from monty.dev import deprecated, install_excepthook, requires # Set all warnings to always be triggered. diff --git a/tests/test_fractions.py b/tests/test_fractions.py index 7d5f27709..230dcf5a7 100644 --- a/tests/test_fractions.py +++ b/tests/test_fractions.py @@ -1,6 +1,7 @@ from __future__ import annotations import pytest + from monty.fractions import gcd, gcd_float, lcm diff --git a/tests/test_functools.py b/tests/test_functools.py index 8bf3fabff..120e6bd75 100644 --- a/tests/test_functools.py +++ b/tests/test_functools.py @@ -5,6 +5,7 @@ import unittest import pytest + from monty.functools import ( TimeoutError, lazy_property, diff --git a/tests/test_io.py b/tests/test_io.py index 9daa17bef..052bc471b 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -5,6 +5,7 @@ from unittest.mock import patch import pytest + from monty.io import ( FileLock, FileLockException, diff --git a/tests/test_json.py b/tests/test_json.py index 9c9e572c7..9e878311b 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -39,6 +39,7 @@ ObjectId = None import pytest + from monty.json import ( MontyDecoder, MontyEncoder, diff --git a/tests/test_os.py b/tests/test_os.py index c6ca8d7ca..af5b156f4 100644 --- a/tests/test_os.py +++ b/tests/test_os.py @@ -4,6 +4,7 @@ from pathlib import Path import pytest + from monty.os import cd, makedirs_p from monty.os.path import find_exts, zpath diff --git a/tests/test_shutil.py b/tests/test_shutil.py index 98ddc1acc..4c4ed9cbc 100644 --- a/tests/test_shutil.py +++ b/tests/test_shutil.py @@ -9,6 +9,7 @@ from pathlib import Path import pytest + from monty.shutil import ( compress_dir, compress_file, From 9ea1f23a822074d479004abd847278ab7b4e6418 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 02:33:04 +0000 Subject: [PATCH 04/26] pre-commit auto-fixes --- tests/test_collections.py | 1 - tests/test_design_patterns.py | 1 - tests/test_dev.py | 1 - tests/test_fractions.py | 1 - tests/test_functools.py | 1 - tests/test_io.py | 1 - tests/test_json.py | 1 - tests/test_os.py | 1 - tests/test_shutil.py | 1 - 9 files changed, 9 deletions(-) diff --git a/tests/test_collections.py b/tests/test_collections.py index 58d2af9e7..8057f7bc2 100644 --- a/tests/test_collections.py +++ b/tests/test_collections.py @@ -3,7 +3,6 @@ import os import pytest - from monty.collections import AttrDict, FrozenAttrDict, Namespace, frozendict, tree TEST_DIR = os.path.join(os.path.dirname(__file__), "test_files") diff --git a/tests/test_design_patterns.py b/tests/test_design_patterns.py index 67a7ffc2b..c37bc87da 100644 --- a/tests/test_design_patterns.py +++ b/tests/test_design_patterns.py @@ -6,7 +6,6 @@ from typing import Any import pytest - from monty.design_patterns import cached_class, singleton diff --git a/tests/test_dev.py b/tests/test_dev.py index 13bb211be..8c44d8aec 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -7,7 +7,6 @@ from unittest.mock import patch import pytest - from monty.dev import deprecated, install_excepthook, requires # Set all warnings to always be triggered. diff --git a/tests/test_fractions.py b/tests/test_fractions.py index 230dcf5a7..7d5f27709 100644 --- a/tests/test_fractions.py +++ b/tests/test_fractions.py @@ -1,7 +1,6 @@ from __future__ import annotations import pytest - from monty.fractions import gcd, gcd_float, lcm diff --git a/tests/test_functools.py b/tests/test_functools.py index 120e6bd75..8bf3fabff 100644 --- a/tests/test_functools.py +++ b/tests/test_functools.py @@ -5,7 +5,6 @@ import unittest import pytest - from monty.functools import ( TimeoutError, lazy_property, diff --git a/tests/test_io.py b/tests/test_io.py index 052bc471b..9daa17bef 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -5,7 +5,6 @@ from unittest.mock import patch import pytest - from monty.io import ( FileLock, FileLockException, diff --git a/tests/test_json.py b/tests/test_json.py index 9e878311b..9c9e572c7 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -39,7 +39,6 @@ ObjectId = None import pytest - from monty.json import ( MontyDecoder, MontyEncoder, diff --git a/tests/test_os.py b/tests/test_os.py index af5b156f4..c6ca8d7ca 100644 --- a/tests/test_os.py +++ b/tests/test_os.py @@ -4,7 +4,6 @@ from pathlib import Path import pytest - from monty.os import cd, makedirs_p from monty.os.path import find_exts, zpath diff --git a/tests/test_shutil.py b/tests/test_shutil.py index 4c4ed9cbc..98ddc1acc 100644 --- a/tests/test_shutil.py +++ b/tests/test_shutil.py @@ -9,7 +9,6 @@ from pathlib import Path import pytest - from monty.shutil import ( compress_dir, compress_file, From b7381d2875322c984438cf10bf51498a1f765c8e Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 11:02:16 +0800 Subject: [PATCH 05/26] test --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 71a31eb8a..bd4998266 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.4 + rev: v0.5.5 hooks: - id: ruff args: [--fix] @@ -24,7 +24,7 @@ repos: exclude: ^tests - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.10.1 + rev: v1.11.0 hooks: - id: mypy From 588a3e884ace5d3fcbd32ee35bb5e1b51ac08619 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 11:08:30 +0800 Subject: [PATCH 06/26] relocate guarded import blocks to the end --- src/monty/io.py | 10 +++++----- src/monty/serialization.py | 8 ++++---- tests/test_collections.py | 1 + tests/test_design_patterns.py | 1 + tests/test_dev.py | 1 + tests/test_fractions.py | 1 + tests/test_functools.py | 1 + tests/test_io.py | 1 + tests/test_json.py | 24 ++++++++++++------------ tests/test_os.py | 1 + tests/test_serialization.py | 5 ++--- tests/test_shutil.py | 1 + 12 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/monty/io.py b/src/monty/io.py index f24a63ddd..6c7bdf7cf 100644 --- a/src/monty/io.py +++ b/src/monty/io.py @@ -9,11 +9,6 @@ import errno import gzip import io - -try: - import lzma -except ImportError: - lzma = None # type: ignore[assignment] import mmap import os import subprocess @@ -21,6 +16,11 @@ from pathlib import Path from typing import TYPE_CHECKING +try: + import lzma +except ImportError: + lzma = None # type: ignore[assignment] + if TYPE_CHECKING: from typing import IO, Generator, Union diff --git a/src/monty/serialization.py b/src/monty/serialization.py index a17b99131..4c46daf41 100644 --- a/src/monty/serialization.py +++ b/src/monty/serialization.py @@ -9,15 +9,15 @@ import os from typing import TYPE_CHECKING +from monty.io import zopen +from monty.json import MontyDecoder, MontyEncoder +from monty.msgpack import default, object_hook + try: from ruamel.yaml import YAML except ImportError: YAML = None # type: ignore[arg-type] -from monty.io import zopen -from monty.json import MontyDecoder, MontyEncoder -from monty.msgpack import default, object_hook - try: import msgpack except ImportError: diff --git a/tests/test_collections.py b/tests/test_collections.py index 8057f7bc2..58d2af9e7 100644 --- a/tests/test_collections.py +++ b/tests/test_collections.py @@ -3,6 +3,7 @@ import os import pytest + from monty.collections import AttrDict, FrozenAttrDict, Namespace, frozendict, tree TEST_DIR = os.path.join(os.path.dirname(__file__), "test_files") diff --git a/tests/test_design_patterns.py b/tests/test_design_patterns.py index c37bc87da..67a7ffc2b 100644 --- a/tests/test_design_patterns.py +++ b/tests/test_design_patterns.py @@ -6,6 +6,7 @@ from typing import Any import pytest + from monty.design_patterns import cached_class, singleton diff --git a/tests/test_dev.py b/tests/test_dev.py index 8c44d8aec..13bb211be 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -7,6 +7,7 @@ from unittest.mock import patch import pytest + from monty.dev import deprecated, install_excepthook, requires # Set all warnings to always be triggered. diff --git a/tests/test_fractions.py b/tests/test_fractions.py index 7d5f27709..230dcf5a7 100644 --- a/tests/test_fractions.py +++ b/tests/test_fractions.py @@ -1,6 +1,7 @@ from __future__ import annotations import pytest + from monty.fractions import gcd, gcd_float, lcm diff --git a/tests/test_functools.py b/tests/test_functools.py index 8bf3fabff..120e6bd75 100644 --- a/tests/test_functools.py +++ b/tests/test_functools.py @@ -5,6 +5,7 @@ import unittest import pytest + from monty.functools import ( TimeoutError, lazy_property, diff --git a/tests/test_io.py b/tests/test_io.py index 9daa17bef..052bc471b 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -5,6 +5,7 @@ from unittest.mock import patch import pytest + from monty.io import ( FileLock, FileLockException, diff --git a/tests/test_json.py b/tests/test_json.py index 9c9e572c7..122302d82 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -8,6 +8,18 @@ from enum import Enum from typing import Union +import pytest +from monty.json import ( + MontyDecoder, + MontyEncoder, + MSONable, + _load_redirect, + jsanitize, + load, +) + +from . import __version__ as tests_version + try: import numpy as np except ImportError: @@ -38,18 +50,6 @@ except ImportError: ObjectId = None -import pytest -from monty.json import ( - MontyDecoder, - MontyEncoder, - MSONable, - _load_redirect, - jsanitize, - load, -) - -from . import __version__ as tests_version - TEST_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_files") diff --git a/tests/test_os.py b/tests/test_os.py index c6ca8d7ca..af5b156f4 100644 --- a/tests/test_os.py +++ b/tests/test_os.py @@ -4,6 +4,7 @@ from pathlib import Path import pytest + from monty.os import cd, makedirs_p from monty.os.path import find_exts, zpath diff --git a/tests/test_serialization.py b/tests/test_serialization.py index d2e0cf9cb..6d1e8ab9a 100644 --- a/tests/test_serialization.py +++ b/tests/test_serialization.py @@ -6,15 +6,14 @@ import unittest import pytest +from monty.serialization import dumpfn, loadfn +from monty.tempfile import ScratchDir try: import msgpack except ImportError: msgpack = None -from monty.serialization import dumpfn, loadfn -from monty.tempfile import ScratchDir - class TestSerial: @classmethod diff --git a/tests/test_shutil.py b/tests/test_shutil.py index 98ddc1acc..4c4ed9cbc 100644 --- a/tests/test_shutil.py +++ b/tests/test_shutil.py @@ -9,6 +9,7 @@ from pathlib import Path import pytest + from monty.shutil import ( compress_dir, compress_file, From f75fc0c0295571db1fc75a5430891f2c7b2bad34 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 03:08:47 +0000 Subject: [PATCH 07/26] pre-commit auto-fixes --- tests/test_collections.py | 1 - tests/test_design_patterns.py | 1 - tests/test_dev.py | 1 - tests/test_fractions.py | 1 - tests/test_functools.py | 1 - tests/test_io.py | 1 - tests/test_os.py | 1 - tests/test_shutil.py | 1 - 8 files changed, 8 deletions(-) diff --git a/tests/test_collections.py b/tests/test_collections.py index 58d2af9e7..8057f7bc2 100644 --- a/tests/test_collections.py +++ b/tests/test_collections.py @@ -3,7 +3,6 @@ import os import pytest - from monty.collections import AttrDict, FrozenAttrDict, Namespace, frozendict, tree TEST_DIR = os.path.join(os.path.dirname(__file__), "test_files") diff --git a/tests/test_design_patterns.py b/tests/test_design_patterns.py index 67a7ffc2b..c37bc87da 100644 --- a/tests/test_design_patterns.py +++ b/tests/test_design_patterns.py @@ -6,7 +6,6 @@ from typing import Any import pytest - from monty.design_patterns import cached_class, singleton diff --git a/tests/test_dev.py b/tests/test_dev.py index 13bb211be..8c44d8aec 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -7,7 +7,6 @@ from unittest.mock import patch import pytest - from monty.dev import deprecated, install_excepthook, requires # Set all warnings to always be triggered. diff --git a/tests/test_fractions.py b/tests/test_fractions.py index 230dcf5a7..7d5f27709 100644 --- a/tests/test_fractions.py +++ b/tests/test_fractions.py @@ -1,7 +1,6 @@ from __future__ import annotations import pytest - from monty.fractions import gcd, gcd_float, lcm diff --git a/tests/test_functools.py b/tests/test_functools.py index 120e6bd75..8bf3fabff 100644 --- a/tests/test_functools.py +++ b/tests/test_functools.py @@ -5,7 +5,6 @@ import unittest import pytest - from monty.functools import ( TimeoutError, lazy_property, diff --git a/tests/test_io.py b/tests/test_io.py index 052bc471b..9daa17bef 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -5,7 +5,6 @@ from unittest.mock import patch import pytest - from monty.io import ( FileLock, FileLockException, diff --git a/tests/test_os.py b/tests/test_os.py index af5b156f4..c6ca8d7ca 100644 --- a/tests/test_os.py +++ b/tests/test_os.py @@ -4,7 +4,6 @@ from pathlib import Path import pytest - from monty.os import cd, makedirs_p from monty.os.path import find_exts, zpath diff --git a/tests/test_shutil.py b/tests/test_shutil.py index 4c4ed9cbc..98ddc1acc 100644 --- a/tests/test_shutil.py +++ b/tests/test_shutil.py @@ -9,7 +9,6 @@ from pathlib import Path import pytest - from monty.shutil import ( compress_dir, compress_file, From 8839c80b0446d162a660cd711f3ee0b702ce6ab8 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 11:23:34 +0800 Subject: [PATCH 08/26] debug: trigger workflow --- tests/test_subprocess.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py index 223211c2d..a96e8073b 100644 --- a/tests/test_subprocess.py +++ b/tests/test_subprocess.py @@ -8,8 +8,8 @@ def test_command(): sleep05 = Command("sleep 0.5") sleep05.run(timeout=1) - print(sleep05) - assert sleep05.retcode == 0 + print(sleep05, sleep05.error, sleep05.output) + assert sleep05.retcode == 0, sleep05 assert not sleep05.killed sleep05.run(timeout=0.1) From 6bda30bc57b6c90e0507e92ee068041c9d5909b0 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 11:35:33 +0800 Subject: [PATCH 09/26] avoid print in unit tests --- tests/test_dev.py | 6 +++--- tests/test_json.py | 2 +- tests/test_pprint.py | 2 +- tests/test_subprocess.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_dev.py b/tests/test_dev.py index 8c44d8aec..d09fca395 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -142,7 +142,7 @@ class TestClassNew: """A dummy class for tests.""" def __post_init__(self): - print("Hello.") + pass def method_a(self): pass @@ -155,7 +155,7 @@ class TestClassOld: class_attrib_old = "OLD_ATTRIB" def __post_init__(self): - print("Hello.") + pass def method_b(self): """This is method_b.""" @@ -245,7 +245,7 @@ def test_requires(self): @requires(fictitious_mod is not None, err_msg) def use_fictitious_mod(): - print("success") + pass with pytest.raises(RuntimeError, match=err_msg): use_fictitious_mod() diff --git a/tests/test_json.py b/tests/test_json.py index 122302d82..5a823a4fd 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -682,7 +682,7 @@ def test_pint_quantity(self): cls = ClassContainingQuantity(qty=pint.Quantity("9.81 m/s**2")) d = json.loads(MontyEncoder().encode(cls)) - print(d) + assert isinstance(d, dict) assert d["qty"]["@module"] == "pint" assert d["qty"]["@class"] == "Quantity" diff --git a/tests/test_pprint.py b/tests/test_pprint.py index 581f80795..1f3a120e3 100644 --- a/tests/test_pprint.py +++ b/tests/test_pprint.py @@ -34,4 +34,4 @@ def __str__(self): ], ) - print(draw_tree(root)) + assert draw_tree(root) diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py index a96e8073b..082b7d2aa 100644 --- a/tests/test_subprocess.py +++ b/tests/test_subprocess.py @@ -8,7 +8,7 @@ def test_command(): sleep05 = Command("sleep 0.5") sleep05.run(timeout=1) - print(sleep05, sleep05.error, sleep05.output) + print(sleep05, sleep05.error, sleep05.output) # DEBUG assert sleep05.retcode == 0, sleep05 assert not sleep05.killed From 134a25da406366c6f6eec6c62e0c75802e675343 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 11:37:51 +0800 Subject: [PATCH 10/26] remove unused and commented out print --- src/monty/subprocess.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/monty/subprocess.py b/src/monty/subprocess.py index 104261c2e..ff77117b2 100644 --- a/src/monty/subprocess.py +++ b/src/monty/subprocess.py @@ -74,11 +74,9 @@ def run(self, timeout: Optional[float] = None, **kwargs) -> Self: def target(**kw): try: - # print('Thread started') with Popen(self.command, **kw) as self.process: self.output, self.error = self.process.communicate() self.retcode = self.process.returncode - # print('Thread stopped') except Exception: self.error = traceback.format_exc() self.retcode = -1 @@ -96,7 +94,6 @@ def target(**kw): thread.join(timeout) if thread.is_alive() and self.process is not None: - # print("Terminating process") self.process.terminate() self.killed = True thread.join() From 19d76a5ef088d513573f00d4ab2eb59548a00f14 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 11:40:07 +0800 Subject: [PATCH 11/26] remove guard for Python 2.7 --- src/monty/termcolor.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/monty/termcolor.py b/src/monty/termcolor.py index 336ef8829..2e236d6c9 100644 --- a/src/monty/termcolor.py +++ b/src/monty/termcolor.py @@ -128,12 +128,7 @@ def cprint( It accepts arguments of print function. """ - try: - print((colored(text, color, on_color, attrs)), **kwargs) - except TypeError: - # flush is not supported by py2.7 - kwargs.pop("flush", None) - print((colored(text, color, on_color, attrs)), **kwargs) + print((colored(text, color, on_color, attrs)), **kwargs) def colored_map(text: str, cmap: dict) -> str: @@ -162,12 +157,7 @@ def cprint_map(text: str, cmap: dict, **kwargs) -> None: Examples: cprint_map("Hello world", {"Hello": "red"}) """ - try: - print(colored_map(text, cmap), **kwargs) - except TypeError: - # flush is not supported by py2.7 - kwargs.pop("flush", None) - print(colored_map(text, cmap), **kwargs) + print(colored_map(text, cmap), **kwargs) def get_terminal_size(): From 015081068611fbea4c35315dccc9cced5c203abc Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 11:59:23 +0800 Subject: [PATCH 12/26] remove redundant blank line --- src/monty/json.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/monty/json.py b/src/monty/json.py index f98990974..8d6da9eb0 100644 --- a/src/monty/json.py +++ b/src/monty/json.py @@ -51,7 +51,6 @@ except ImportError: orjson = None - try: import torch except ImportError: From 29ce0dc3698354080fd0e75b0c2c5a77cde88380 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 17:03:23 +0800 Subject: [PATCH 13/26] Use more detailed debug msg --- tests/test_subprocess.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py index 082b7d2aa..45d06b0a8 100644 --- a/tests/test_subprocess.py +++ b/tests/test_subprocess.py @@ -8,8 +8,9 @@ def test_command(): sleep05 = Command("sleep 0.5") sleep05.run(timeout=1) - print(sleep05, sleep05.error, sleep05.output) # DEBUG - assert sleep05.retcode == 0, sleep05 + # DEBUG: this unit test fail in Win CI sometimes + full_msg = f"{sleep05=}\n{sleep05.error=}\n{sleep05.output}" + assert sleep05.retcode == 0, full_msg assert not sleep05.killed sleep05.run(timeout=0.1) From 31cd6ac23bc16723d5db10d97d3b79ca0e29f44d Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 17:13:58 +0800 Subject: [PATCH 14/26] rename test class to avoid PytestCollectionWarning --- tests/test_design_patterns.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_design_patterns.py b/tests/test_design_patterns.py index c37bc87da..f28a663b6 100644 --- a/tests/test_design_patterns.py +++ b/tests/test_design_patterns.py @@ -52,24 +52,24 @@ def test_pickle(self): @cached_class -class TestClass: +class ClassForTest: def __init__(self, value: Any) -> None: self.value = value def test_caching(): # Test that instances are cached - inst1 = TestClass(1) - inst2 = TestClass(1) + inst1 = ClassForTest(1) + inst2 = ClassForTest(1) assert inst1 is inst2 - inst3 = TestClass(2) + inst3 = ClassForTest(2) assert inst1 is not inst3 def test_picklability(): # Test that instances can be pickled and unpickled - original = TestClass(42) + original = ClassForTest(42) pickled = pickle.dumps(original) unpickled = pickle.loads(pickled) @@ -77,7 +77,7 @@ def test_picklability(): assert original.value == unpickled.value # Check that the unpickled instance is the same as a newly created instance - new_instance = TestClass(42) + new_instance = ClassForTest(42) assert unpickled is new_instance @@ -97,8 +97,8 @@ def __init__(self): def test_class_identity(): # Ensure the decorated class is still recognized as the original class - assert isinstance(TestClass(1), TestClass) - assert type(TestClass(1)) is TestClass + assert isinstance(ClassForTest(1), ClassForTest) + assert type(ClassForTest(1)) is ClassForTest def test_multiple_arguments(): From b7e9e47ad37d94d208430a068c4b7311e93eed6d Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 17:17:36 +0800 Subject: [PATCH 15/26] install ipython in ci for test_install_except_hook --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 980489faf..9e6094f95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,8 @@ ci = [ "orjson", "types-orjson", "types-requests", - "torch" + "torch", + "ipython", ] docs = [ "sphinx", From 14851537be3eb9cccbd0fde199fd59e92714909a Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 17:22:14 +0800 Subject: [PATCH 16/26] install bson in CI --- pyproject.toml | 1 + tests/test_json.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9e6094f95..242ccc28e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,7 @@ ci = [ "types-requests", "torch", "ipython", + "bson", ] docs = [ "sphinx", diff --git a/tests/test_json.py b/tests/test_json.py index 5a823a4fd..99db6dfd1 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -873,7 +873,7 @@ def test_jsanitize_pandas(self): assert clean == s.to_dict() @pytest.mark.skipif( - np is None or ObjectId is None, reason="numpy and bson not present" + np is None or ObjectId is None, reason="numpy or bson not present" ) def test_jsanitize_numpy_bson(self): d = { From 98290381c415ffb7434eb07b4435bb99d208c76d Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 17:26:23 +0800 Subject: [PATCH 17/26] install pydantic instead of bson --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 242ccc28e..e654e07f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ ci = [ "types-requests", "torch", "ipython", - "bson", + "pydantic", ] docs = [ "sphinx", From a45b3b49c9edaa228f0c9c5b424b4b7530c15d87 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 26 Jul 2024 17:47:29 +0800 Subject: [PATCH 18/26] use capital for global var name --- tests/test_json.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_json.py b/tests/test_json.py index 99db6dfd1..5a51ba1a7 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -18,7 +18,7 @@ load, ) -from . import __version__ as tests_version +from . import __version__ as TESTS_VERSION try: import numpy as np @@ -320,7 +320,7 @@ def test_unsafe_hash(self): def test_version(self): obj = self.good_cls("Hello", "World", "Python") d = obj.as_dict() - assert d["@version"] == tests_version + assert d["@version"] == TESTS_VERSION def test_nested_to_from_dict(self): GMC = GoodMSONClass From 9161eecca68df2bfe7f8234755fa87375f805304 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Mon, 29 Jul 2024 19:03:42 +0800 Subject: [PATCH 19/26] var name tweaks --- tests/test_tempfile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_tempfile.py b/tests/test_tempfile.py index 4bce40893..9aaf7bce2 100644 --- a/tests/test_tempfile.py +++ b/tests/test_tempfile.py @@ -49,7 +49,7 @@ def test_with_copy_gzip(self): # We write a pre-scratch file. with open("pre_scratch_text", "w") as f: f.write("write") - init_gz = [f for f in os.listdir(os.getcwd()) if f.endswith(".gz")] + init_gz_files = [f for f in os.listdir(os.getcwd()) if f.endswith(".gz")] with ( ScratchDir( self.scratch_root, @@ -62,10 +62,10 @@ def test_with_copy_gzip(self): f.write("write") files = os.listdir(os.getcwd()) - # Make sure the stratch_text.gz exists + # Make sure the scratch_text.gz exists assert "scratch_text.gz" in files for f in files: - if f.endswith(".gz") and f not in init_gz: + if f.endswith(".gz") and f not in init_gz_files: os.remove(f) os.remove("pre_scratch_text") From b78e6dab5ab1d157b0932fe44eb0c14ebc422fa5 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Mon, 29 Jul 2024 19:04:46 +0800 Subject: [PATCH 20/26] rename to 3000_lines_gz.txt.gz to avoid overlap name --- .../{3000_lines.txt.gz => 3000_lines_gz.txt.gz} | Bin tests/test_io.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/test_files/{3000_lines.txt.gz => 3000_lines_gz.txt.gz} (100%) diff --git a/tests/test_files/3000_lines.txt.gz b/tests/test_files/3000_lines_gz.txt.gz similarity index 100% rename from tests/test_files/3000_lines.txt.gz rename to tests/test_files/3000_lines_gz.txt.gz diff --git a/tests/test_io.py b/tests/test_io.py index 9daa17bef..91326d526 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -110,7 +110,7 @@ def test_reverse_readfile_gz(self): Make sure a file containing line numbers is read in reverse order, i.e. the first line that is read corresponds to the last line number. """ - fname = os.path.join(TEST_DIR, "3000_lines.txt.gz") + fname = os.path.join(TEST_DIR, "3000_lines_gz.txt.gz") for idx, line in enumerate(reverse_readfile(fname)): assert int(line) == self.NUMLINES - idx From 24995d86d01ac019ceea0d5f1dd80c424de3b7b5 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Mon, 29 Jul 2024 19:10:17 +0800 Subject: [PATCH 21/26] Revert "rename to 3000_lines_gz.txt.gz to avoid overlap name" This reverts commit b78e6dab5ab1d157b0932fe44eb0c14ebc422fa5. --- .../{3000_lines_gz.txt.gz => 3000_lines.txt.gz} | Bin tests/test_io.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/test_files/{3000_lines_gz.txt.gz => 3000_lines.txt.gz} (100%) diff --git a/tests/test_files/3000_lines_gz.txt.gz b/tests/test_files/3000_lines.txt.gz similarity index 100% rename from tests/test_files/3000_lines_gz.txt.gz rename to tests/test_files/3000_lines.txt.gz diff --git a/tests/test_io.py b/tests/test_io.py index 91326d526..9daa17bef 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -110,7 +110,7 @@ def test_reverse_readfile_gz(self): Make sure a file containing line numbers is read in reverse order, i.e. the first line that is read corresponds to the last line number. """ - fname = os.path.join(TEST_DIR, "3000_lines_gz.txt.gz") + fname = os.path.join(TEST_DIR, "3000_lines.txt.gz") for idx, line in enumerate(reverse_readfile(fname)): assert int(line) == self.NUMLINES - idx From 29605f39d8583398ba577191a4edc4d467297c25 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 22 Aug 2024 12:04:23 +0800 Subject: [PATCH 22/26] bump to ruff 0.6 --- .pre-commit-config.yaml | 4 ++-- tests/test_collections.py | 1 + tests/test_design_patterns.py | 1 + tests/test_dev.py | 1 + tests/test_fractions.py | 1 + tests/test_functools.py | 1 + tests/test_io.py | 1 + tests/test_json.py | 1 + tests/test_os.py | 1 + tests/test_serialization.py | 1 + tests/test_shutil.py | 1 + tests/test_tempfile.py | 1 + 12 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bd4998266..6a7097d56 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.5 + rev: v0.6.1 hooks: - id: ruff args: [--fix] @@ -24,7 +24,7 @@ repos: exclude: ^tests - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.11.0 + rev: v1.11.1 hooks: - id: mypy diff --git a/tests/test_collections.py b/tests/test_collections.py index 8057f7bc2..58d2af9e7 100644 --- a/tests/test_collections.py +++ b/tests/test_collections.py @@ -3,6 +3,7 @@ import os import pytest + from monty.collections import AttrDict, FrozenAttrDict, Namespace, frozendict, tree TEST_DIR = os.path.join(os.path.dirname(__file__), "test_files") diff --git a/tests/test_design_patterns.py b/tests/test_design_patterns.py index f28a663b6..6e3766f4c 100644 --- a/tests/test_design_patterns.py +++ b/tests/test_design_patterns.py @@ -6,6 +6,7 @@ from typing import Any import pytest + from monty.design_patterns import cached_class, singleton diff --git a/tests/test_dev.py b/tests/test_dev.py index d09fca395..f5cbf9390 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -7,6 +7,7 @@ from unittest.mock import patch import pytest + from monty.dev import deprecated, install_excepthook, requires # Set all warnings to always be triggered. diff --git a/tests/test_fractions.py b/tests/test_fractions.py index 7d5f27709..230dcf5a7 100644 --- a/tests/test_fractions.py +++ b/tests/test_fractions.py @@ -1,6 +1,7 @@ from __future__ import annotations import pytest + from monty.fractions import gcd, gcd_float, lcm diff --git a/tests/test_functools.py b/tests/test_functools.py index 8bf3fabff..120e6bd75 100644 --- a/tests/test_functools.py +++ b/tests/test_functools.py @@ -5,6 +5,7 @@ import unittest import pytest + from monty.functools import ( TimeoutError, lazy_property, diff --git a/tests/test_io.py b/tests/test_io.py index 9daa17bef..052bc471b 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -5,6 +5,7 @@ from unittest.mock import patch import pytest + from monty.io import ( FileLock, FileLockException, diff --git a/tests/test_json.py b/tests/test_json.py index 5a51ba1a7..25781091b 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -9,6 +9,7 @@ from typing import Union import pytest + from monty.json import ( MontyDecoder, MontyEncoder, diff --git a/tests/test_os.py b/tests/test_os.py index c6ca8d7ca..af5b156f4 100644 --- a/tests/test_os.py +++ b/tests/test_os.py @@ -4,6 +4,7 @@ from pathlib import Path import pytest + from monty.os import cd, makedirs_p from monty.os.path import find_exts, zpath diff --git a/tests/test_serialization.py b/tests/test_serialization.py index 6d1e8ab9a..e7c853a58 100644 --- a/tests/test_serialization.py +++ b/tests/test_serialization.py @@ -6,6 +6,7 @@ import unittest import pytest + from monty.serialization import dumpfn, loadfn from monty.tempfile import ScratchDir diff --git a/tests/test_shutil.py b/tests/test_shutil.py index 16cd9aa78..e506b4ae4 100644 --- a/tests/test_shutil.py +++ b/tests/test_shutil.py @@ -9,6 +9,7 @@ from pathlib import Path import pytest + from monty.shutil import ( compress_dir, compress_file, diff --git a/tests/test_tempfile.py b/tests/test_tempfile.py index 4dfd3b17f..088aec670 100644 --- a/tests/test_tempfile.py +++ b/tests/test_tempfile.py @@ -4,6 +4,7 @@ import shutil import pytest + from monty.tempfile import ScratchDir TEST_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_files") From 0fcc9cab7145a797f76d817ef4f57b7743663db0 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 22 Aug 2024 12:06:22 +0800 Subject: [PATCH 23/26] ruff fix tasks.py --- tasks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks.py b/tasks.py index 921412adb..7432034a0 100755 --- a/tasks.py +++ b/tasks.py @@ -11,6 +11,7 @@ import requests from invoke import task + from monty import __version__ as ver from monty.os import cd From 242f2de5cc87444f4e40e95fe78ddfc5218005a4 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Mon, 21 Oct 2024 11:56:13 +0800 Subject: [PATCH 24/26] clean up merge issue --- src/monty/io.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/monty/io.py b/src/monty/io.py index dd5d6a268..9ca0f2cb9 100644 --- a/src/monty/io.py +++ b/src/monty/io.py @@ -17,11 +17,6 @@ from pathlib import Path from typing import TYPE_CHECKING -try: - import lzma -except ImportError: - lzma = None # type: ignore[assignment] - if TYPE_CHECKING: from typing import IO, Generator, Union From eee712e1903aaf6ff04e7dc9e7e07622997986d8 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Tue, 22 Oct 2024 10:38:37 +0800 Subject: [PATCH 25/26] make module level var all cap --- tests/test_shutil.py | 90 ++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/tests/test_shutil.py b/tests/test_shutil.py index e506b4ae4..dfc1375fd 100644 --- a/tests/test_shutil.py +++ b/tests/test_shutil.py @@ -20,57 +20,57 @@ remove, ) -test_dir = os.path.join(os.path.dirname(__file__), "test_files") +TEST_DIR = os.path.join(os.path.dirname(__file__), "test_files") class TestCopyR: def setup_method(self): - os.mkdir(os.path.join(test_dir, "cpr_src")) - with open(os.path.join(test_dir, "cpr_src", "test"), "w") as f: + os.mkdir(os.path.join(TEST_DIR, "cpr_src")) + with open(os.path.join(TEST_DIR, "cpr_src", "test"), "w") as f: f.write("what") - os.mkdir(os.path.join(test_dir, "cpr_src", "sub")) - with open(os.path.join(test_dir, "cpr_src", "sub", "testr"), "w") as f: + os.mkdir(os.path.join(TEST_DIR, "cpr_src", "sub")) + with open(os.path.join(TEST_DIR, "cpr_src", "sub", "testr"), "w") as f: f.write("what2") if os.name != "nt": os.symlink( - os.path.join(test_dir, "cpr_src", "test"), - os.path.join(test_dir, "cpr_src", "mysymlink"), + os.path.join(TEST_DIR, "cpr_src", "test"), + os.path.join(TEST_DIR, "cpr_src", "mysymlink"), ) def test_recursive_copy_and_compress(self): - copy_r(os.path.join(test_dir, "cpr_src"), os.path.join(test_dir, "cpr_dst")) - assert os.path.exists(os.path.join(test_dir, "cpr_dst", "test")) - assert os.path.exists(os.path.join(test_dir, "cpr_dst", "sub", "testr")) - - compress_dir(os.path.join(test_dir, "cpr_src")) - assert os.path.exists(os.path.join(test_dir, "cpr_src", "test.gz")) - assert os.path.exists(os.path.join(test_dir, "cpr_src", "sub", "testr.gz")) - - decompress_dir(os.path.join(test_dir, "cpr_src")) - assert os.path.exists(os.path.join(test_dir, "cpr_src", "test")) - assert os.path.exists(os.path.join(test_dir, "cpr_src", "sub", "testr")) - with open(os.path.join(test_dir, "cpr_src", "test")) as f: + copy_r(os.path.join(TEST_DIR, "cpr_src"), os.path.join(TEST_DIR, "cpr_dst")) + assert os.path.exists(os.path.join(TEST_DIR, "cpr_dst", "test")) + assert os.path.exists(os.path.join(TEST_DIR, "cpr_dst", "sub", "testr")) + + compress_dir(os.path.join(TEST_DIR, "cpr_src")) + assert os.path.exists(os.path.join(TEST_DIR, "cpr_src", "test.gz")) + assert os.path.exists(os.path.join(TEST_DIR, "cpr_src", "sub", "testr.gz")) + + decompress_dir(os.path.join(TEST_DIR, "cpr_src")) + assert os.path.exists(os.path.join(TEST_DIR, "cpr_src", "test")) + assert os.path.exists(os.path.join(TEST_DIR, "cpr_src", "sub", "testr")) + with open(os.path.join(TEST_DIR, "cpr_src", "test")) as f: txt = f.read() assert txt == "what" def test_pathlib(self): - test_path = Path(test_dir) + test_path = Path(TEST_DIR) copy_r(test_path / "cpr_src", test_path / "cpr_dst") assert (test_path / "cpr_dst" / "test").exists() assert (test_path / "cpr_dst" / "sub" / "testr").exists() def teardown_method(self): - shutil.rmtree(os.path.join(test_dir, "cpr_src")) - shutil.rmtree(os.path.join(test_dir, "cpr_dst")) + shutil.rmtree(os.path.join(TEST_DIR, "cpr_src")) + shutil.rmtree(os.path.join(TEST_DIR, "cpr_dst")) class TestCompressFileDir: def setup_method(self): - with open(os.path.join(test_dir, "tempfile"), "w") as f: + with open(os.path.join(TEST_DIR, "tempfile"), "w") as f: f.write("hello world") def test_compress_and_decompress_file(self): - fname = os.path.join(test_dir, "tempfile") + fname = os.path.join(TEST_DIR, "tempfile") for fmt in ["gz", "bz2"]: compress_file(fname, fmt) @@ -93,8 +93,8 @@ def test_compress_and_decompress_file(self): assert decompress_file("non-existent.bz2") is None def test_compress_and_decompress_with_target_dir(self): - fname = os.path.join(test_dir, "tempfile") - target_dir = os.path.join(test_dir, "temp_target_dir") + fname = os.path.join(TEST_DIR, "tempfile") + target_dir = os.path.join(TEST_DIR, "temp_target_dir") for fmt in ["gz", "bz2"]: compress_file(fname, fmt, target_dir) @@ -117,20 +117,20 @@ def test_compress_and_decompress_with_target_dir(self): assert f.read() == "hello world" def teardown_method(self): - os.remove(os.path.join(test_dir, "tempfile")) + os.remove(os.path.join(TEST_DIR, "tempfile")) class TestGzipDir: def setup_method(self): - os.mkdir(os.path.join(test_dir, "gzip_dir")) - with open(os.path.join(test_dir, "gzip_dir", "tempfile"), "w") as f: + os.mkdir(os.path.join(TEST_DIR, "gzip_dir")) + with open(os.path.join(TEST_DIR, "gzip_dir", "tempfile"), "w") as f: f.write("what") - self.mtime = os.path.getmtime(os.path.join(test_dir, "gzip_dir", "tempfile")) + self.mtime = os.path.getmtime(os.path.join(TEST_DIR, "gzip_dir", "tempfile")) def test_gzip_dir(self): - full_f = os.path.join(test_dir, "gzip_dir", "tempfile") - gzip_dir(os.path.join(test_dir, "gzip_dir")) + full_f = os.path.join(TEST_DIR, "gzip_dir", "tempfile") + gzip_dir(os.path.join(TEST_DIR, "gzip_dir")) assert os.path.exists(f"{full_f}.gz") assert not os.path.exists(full_f) @@ -142,7 +142,7 @@ def test_gzip_dir(self): def test_gzip_dir_file_coexist(self): """Test case where both file and file.gz exist.""" - full_f = os.path.join(test_dir, "gzip_dir", "temptestfile") + full_f = os.path.join(TEST_DIR, "gzip_dir", "temptestfile") gz_f = f"{full_f}.gz" # Create both the file and its gzipped version @@ -154,7 +154,7 @@ def test_gzip_dir_file_coexist(self): with pytest.warns( UserWarning, match="Both temptestfile and temptestfile.gz exist." ): - gzip_dir(os.path.join(test_dir, "gzip_dir")) + gzip_dir(os.path.join(TEST_DIR, "gzip_dir")) # Verify contents of the files with open(full_f, "r") as f: @@ -164,13 +164,13 @@ def test_gzip_dir_file_coexist(self): assert g.read() == b"gzipped" def test_handle_sub_dirs(self): - sub_dir = os.path.join(test_dir, "gzip_dir", "sub_dir") + sub_dir = os.path.join(TEST_DIR, "gzip_dir", "sub_dir") sub_file = os.path.join(sub_dir, "new_tempfile") os.mkdir(sub_dir) with open(sub_file, "w") as f: f.write("anotherwhat") - gzip_dir(os.path.join(test_dir, "gzip_dir")) + gzip_dir(os.path.join(TEST_DIR, "gzip_dir")) assert os.path.exists(f"{sub_file}.gz") assert not os.path.exists(sub_file) @@ -179,13 +179,13 @@ def test_handle_sub_dirs(self): assert g.readline().decode("utf-8") == "anotherwhat" def teardown_method(self): - shutil.rmtree(os.path.join(test_dir, "gzip_dir")) + shutil.rmtree(os.path.join(TEST_DIR, "gzip_dir")) class TestRemove: @unittest.skipIf(platform.system() == "Windows", "Skip on windows") def test_remove_file(self): - tempdir = tempfile.mkdtemp(dir=test_dir) + tempdir = tempfile.mkdtemp(dir=TEST_DIR) tempf = tempfile.mkstemp(dir=tempdir)[1] remove(tempf) assert not os.path.isfile(tempf) @@ -193,17 +193,17 @@ def test_remove_file(self): @unittest.skipIf(platform.system() == "Windows", "Skip on windows") def test_remove_folder(self): - tempdir = tempfile.mkdtemp(dir=test_dir) + tempdir = tempfile.mkdtemp(dir=TEST_DIR) remove(tempdir) assert not os.path.isdir(tempdir) @unittest.skipIf(platform.system() == "Windows", "Skip on windows") def test_remove_symlink(self): - tempdir = tempfile.mkdtemp(dir=test_dir) + tempdir = tempfile.mkdtemp(dir=TEST_DIR) tempf = tempfile.mkstemp(dir=tempdir)[1] - os.symlink(tempdir, os.path.join(test_dir, "temp_link")) - templink = os.path.join(test_dir, "temp_link") + os.symlink(tempdir, os.path.join(TEST_DIR, "temp_link")) + templink = os.path.join(TEST_DIR, "temp_link") remove(templink) assert os.path.isfile(tempf) assert os.path.isdir(tempdir) @@ -212,11 +212,11 @@ def test_remove_symlink(self): @unittest.skipIf(platform.system() == "Windows", "Skip on windows") def test_remove_symlink_follow(self): - tempdir = tempfile.mkdtemp(dir=test_dir) + tempdir = tempfile.mkdtemp(dir=TEST_DIR) tempf = tempfile.mkstemp(dir=tempdir)[1] - os.symlink(tempdir, os.path.join(test_dir, "temp_link")) - templink = os.path.join(test_dir, "temp_link") + os.symlink(tempdir, os.path.join(TEST_DIR, "temp_link")) + templink = os.path.join(TEST_DIR, "temp_link") remove(templink, follow_symlink=True) assert not os.path.isfile(tempf) assert not os.path.isdir(tempdir) From bfe943195d77cdc73b9d561d0195100877f49379 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Fri, 8 Nov 2024 18:27:54 +0800 Subject: [PATCH 26/26] enhance comment --- tests/test_subprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py index 45d06b0a8..c5c82dd60 100644 --- a/tests/test_subprocess.py +++ b/tests/test_subprocess.py @@ -8,7 +8,7 @@ def test_command(): sleep05 = Command("sleep 0.5") sleep05.run(timeout=1) - # DEBUG: this unit test fail in Win CI sometimes + # DEBUG: this unit test fail in Windows CI intermittently (PR702) full_msg = f"{sleep05=}\n{sleep05.error=}\n{sleep05.output}" assert sleep05.retcode == 0, full_msg assert not sleep05.killed