File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 5
5
from __future__ import annotations
6
6
7
7
import contextlib
8
+ import os
8
9
import platform
9
10
import sys
10
11
import traceback
@@ -146,3 +147,8 @@ def _is_relative_to(self: Path, *other: Path) -> bool:
146
147
return True
147
148
except ValueError :
148
149
return False
150
+
151
+
152
+ def _is_env_set_and_non_empty (env_var : str ) -> bool :
153
+ """Checks if env_var is set and non-empty."""
154
+ return os .environ .get (env_var ) not in ["" , None ]
Original file line number Diff line number Diff line change 4
4
5
5
import unittest .mock
6
6
from pathlib import Path , PosixPath
7
+ from typing import Any
7
8
8
9
import pytest
9
10
10
11
from pylint .constants import full_version
11
- from pylint .lint .utils import get_fatal_error_message , prepare_crash_report
12
+ from pylint .lint .utils import (
13
+ _is_env_set_and_non_empty ,
14
+ get_fatal_error_message ,
15
+ prepare_crash_report ,
16
+ )
12
17
from pylint .testutils ._run import _Run as Run
13
18
14
19
@@ -56,3 +61,31 @@ def test_issue_template_on_fatal_errors(capsys: pytest.CaptureFixture) -> None:
56
61
assert "Fatal error while checking" in captured .out
57
62
assert "Please open an issue" in captured .out
58
63
assert "Traceback" in captured .err
64
+
65
+
66
+ @pytest .mark .parametrize (
67
+ "value, expected" ,
68
+ [
69
+ (None , False ),
70
+ ("" , False ),
71
+ (0 , True ),
72
+ (1 , True ),
73
+ (2 , True ),
74
+ (False , True ),
75
+ ("no" , True ),
76
+ ("off" , True ),
77
+ ("on" , True ),
78
+ (True , True ),
79
+ ("yes" , True ),
80
+ ],
81
+ ids = repr ,
82
+ )
83
+ def test_is_env_set_and_non_empty (
84
+ monkeypatch : pytest .MonkeyPatch , value : Any , expected : bool
85
+ ) -> None :
86
+ """Test the function returns True if the environment variable is set and non-empty."""
87
+ env_var = "TEST_VAR"
88
+ if value is not None :
89
+ monkeypatch .setenv (env_var , str (value ))
90
+
91
+ assert _is_env_set_and_non_empty (env_var ) == expected
You can’t perform that action at this time.
0 commit comments