Skip to content

Commit 3797c69

Browse files
committed
[cdd/tests/test_utils_for_tests.py] Specialise for is_jetbrains
1 parent a30976c commit 3797c69

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

cdd/shared/pkg_utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,15 @@ def relative_filename(filename, remove_hints=tuple()):
109109
"""
110110
_filename: str = filename.casefold()
111111
lib = get_python_lib(), get_python_lib(prefix="")
112-
return next(map(lambda elem: filename[len(elem) + 1 :],
113-
filter(lambda elem: _filename.startswith(elem.casefold()), remove_hints + lib)), filename)
112+
return next(
113+
map(
114+
lambda elem: filename[len(elem) + 1 :],
115+
filter(
116+
lambda elem: _filename.startswith(elem.casefold()), remove_hints + lib
117+
),
118+
),
119+
filename,
120+
)
114121

115122

116123
__all__ = ["relative_filename"] # type: list[str]

cdd/tests/test_sqlalchemy/test_emit_sqlalchemy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
Tests for `cdd.emit.sqlalchemy`
33
"""
44

5-
import os
65
from copy import deepcopy
76
from platform import system
8-
from unittest import TestCase, skipIf
7+
from unittest import TestCase
98

109
import cdd.argparse_function.emit
1110
import cdd.argparse_function.parse

cdd/tests/test_utils_for_tests.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
Tests for docstring parsing
33
"""
44

5+
import os.path
6+
import sys
57
from ast import Module
68
from collections import namedtuple
79
from io import StringIO
8-
from os import environ
9-
from sys import version_info
1010
from typing import Any
11-
from unittest import TestCase, skipIf
11+
from unittest import TestCase
1212
from unittest.mock import MagicMock, patch
1313

1414
from cdd.shared.pure_utils import PY_GTE_3_8, PY_GTE_3_12
@@ -27,18 +27,21 @@ def test_unittest_main(self) -> None:
2727
"""
2828
self.assertEqual(type(unittest_main).__name__, "function")
2929
self.assertIsNone(unittest_main())
30-
argparse_mock = MagicMock()
30+
argparse_mock: MagicMock = MagicMock()
3131
# cdd.tests.utils_for_tests.py
3232
with patch("cdd.tests.utils_for_tests.__name__", "__main__"), patch(
3333
"sys.stderr", new_callable=StringIO
3434
), self.assertRaises(SystemExit) as e:
3535
import cdd.tests.utils_for_tests
3636

3737
cdd.tests.utils_for_tests.unittest_main()
38+
is_jetbrains: bool = os.path.basename(
39+
sys.modules["__main__"].__file__
40+
) == "_jb_unittest_runner{}py".format(os.path.extsep)
3841
(
3942
# Python >=3.12 has:
4043
# if self.result.testsRun == 0: where `_NO_TESTS_EXITCODE` is `5`
41-
self.assertEqual(e.exception.code, 5)
44+
self.assertEqual(e.exception.code, 5 if is_jetbrains else 1)
4245
if PY_GTE_3_12
4346
else self.assertIsInstance(e.exception.code, bool)
4447
)

0 commit comments

Comments
 (0)