Skip to content

Commit

Permalink
skip tests that require optional dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Jan 18, 2025
1 parent faca926 commit 445dfcc
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/monty/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Iterable, cast
from typing import TYPE_CHECKING, cast

if TYPE_CHECKING:
from typing import Any, Union
from typing import Any, Iterable, Union


def remove_non_ascii(s: str) -> str:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

from monty.dev import deprecated, install_excepthook, requires

try:
from IPython.core import ultratb
except ImportError as exc:
ultratb = None

# Set all warnings to always be triggered.
warnings.simplefilter("always")

Expand Down Expand Up @@ -199,5 +204,6 @@ def use_import_error():
use_import_error()


@pytest.mark.skipif(ultratb is None, reason="ipython is not installed")
def test_install_except_hook():
install_excepthook()
2 changes: 1 addition & 1 deletion tests/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def return_none(self):


class TestTimeout:
@pytest.mark.skipif(platform.system() == "Windows", "Skip on windows")
@pytest.mark.skipif(platform.system() == "Windows", reason="Skip on windows")
def test_with(self):
try:
with timeout(1, "timeout!"):
Expand Down
5 changes: 4 additions & 1 deletion tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import pathlib
from enum import Enum
from typing import Union
from typing import TYPE_CHECKING

import numpy as np
import pytest
Expand All @@ -23,6 +23,9 @@

from . import __version__ as TESTS_VERSION

if TYPE_CHECKING:
from typing import Union

try:
import pandas as pd
except ImportError:
Expand Down
10 changes: 9 additions & 1 deletion tests/test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

from math import sqrt

from monty.multiprocessing import imap_tqdm
import pytest

try:
from tqdm.autonotebook import tqdm

from monty.multiprocessing import imap_tqdm
except ImportError:
tqdm = None


@pytest.mark.skipif(tqdm is None, reason="tqdm not installed")
def test_imap_tqdm():
results = imap_tqdm(4, sqrt, range(10_000))
assert len(results) == 10_000
Expand Down
2 changes: 1 addition & 1 deletion tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_dumpfn_loadfn(self):
with pytest.raises(TypeError):
loadfn("monte_test.txt", fmt="garbage")

@pytest.mark.skipif(msgpack is None, "msgpack-python not installed.")
@pytest.mark.skipif(msgpack is None, reason="msgpack-python not installed.")
def test_mpk(self):
d = {"hello": "world"}

Expand Down
8 changes: 4 additions & 4 deletions tests/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,21 @@ def teardown_method(self):


class TestRemove:
@pytest.mark.skipif(platform.system() == "Windows", "Skip on windows")
@pytest.mark.skipif(platform.system() == "Windows", reason="Skip on windows")
def test_remove_file(self):
tempdir = tempfile.mkdtemp(dir=TEST_DIR)
tempf = tempfile.mkstemp(dir=tempdir)[1]
remove(tempf)
assert not os.path.isfile(tempf)
shutil.rmtree(tempdir)

@pytest.mark.skipif(platform.system() == "Windows", "Skip on windows")
@pytest.mark.skipif(platform.system() == "Windows", reason="Skip on windows")
def test_remove_folder(self):
tempdir = tempfile.mkdtemp(dir=TEST_DIR)
remove(tempdir)
assert not os.path.isdir(tempdir)

@pytest.mark.skipif(platform.system() == "Windows", "Skip on windows")
@pytest.mark.skipif(platform.system() == "Windows", reason="Skip on windows")
def test_remove_symlink(self):
tempdir = tempfile.mkdtemp(dir=TEST_DIR)
tempf = tempfile.mkstemp(dir=tempdir)[1]
Expand All @@ -215,7 +215,7 @@ def test_remove_symlink(self):
assert not os.path.islink(templink)
remove(tempdir)

@pytest.mark.skipif(platform.system() == "Windows", "Skip on windows")
@pytest.mark.skipif(platform.system() == "Windows", reason="Skip on windows")
def test_remove_symlink_follow(self):
tempdir = tempfile.mkdtemp(dir=TEST_DIR)
tempf = tempfile.mkstemp(dir=tempdir)[1]
Expand Down

0 comments on commit 445dfcc

Please sign in to comment.