Skip to content

Commit

Permalink
[cdd/tests/test_utils_for_tests.py] Specialise for is_jetbrains
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelMarks committed Mar 15, 2024
1 parent 2f06c04 commit 557ea80
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
11 changes: 9 additions & 2 deletions cdd/shared/pkg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,15 @@ def relative_filename(filename, remove_hints=tuple()):
"""
_filename: str = filename.casefold()
lib = get_python_lib(), get_python_lib(prefix="")
return next(map(lambda elem: filename[len(elem) + 1 :],
filter(lambda elem: _filename.startswith(elem.casefold()), remove_hints + lib)), filename)
return next(
map(
lambda elem: filename[len(elem) + 1 :],
filter(
lambda elem: _filename.startswith(elem.casefold()), remove_hints + lib
),
),
filename,
)


__all__ = ["relative_filename"] # type: list[str]
3 changes: 1 addition & 2 deletions cdd/tests/test_sqlalchemy/test_emit_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
Tests for `cdd.emit.sqlalchemy`
"""

import os
from copy import deepcopy
from platform import system
from unittest import TestCase, skipIf
from unittest import TestCase

import cdd.argparse_function.emit
import cdd.argparse_function.parse
Expand Down
13 changes: 8 additions & 5 deletions cdd/tests/test_utils_for_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Tests for docstring parsing
"""

import os.path
import sys
from ast import Module
from collections import namedtuple
from io import StringIO
from os import environ
from sys import version_info
from typing import Any
from unittest import TestCase, skipIf
from unittest import TestCase
from unittest.mock import MagicMock, patch

from cdd.shared.pure_utils import PY_GTE_3_8, PY_GTE_3_12
Expand All @@ -27,18 +27,21 @@ def test_unittest_main(self) -> None:
"""
self.assertEqual(type(unittest_main).__name__, "function")
self.assertIsNone(unittest_main())
argparse_mock = MagicMock()
argparse_mock: MagicMock = MagicMock()
# cdd.tests.utils_for_tests.py
with patch("cdd.tests.utils_for_tests.__name__", "__main__"), patch(
"sys.stderr", new_callable=StringIO
), self.assertRaises(SystemExit) as e:
import cdd.tests.utils_for_tests

cdd.tests.utils_for_tests.unittest_main()
is_jetbrains: bool = os.path.basename(
sys.modules["__main__"].__file__
) == "_jb_unittest_runner{}py".format(os.path.extsep)
(
# Python >=3.12 has:
# if self.result.testsRun == 0: where `_NO_TESTS_EXITCODE` is `5`
self.assertEqual(e.exception.code, 5)
self.assertEqual(e.exception.code, 5 if is_jetbrains else 1)
if PY_GTE_3_12
else self.assertIsInstance(e.exception.code, bool)
)
Expand Down

0 comments on commit 557ea80

Please sign in to comment.