Skip to content

Commit 467785e

Browse files
committed
use os.pathsep
1 parent 31fb89d commit 467785e

1 file changed

Lines changed: 66 additions & 16 deletions

File tree

tests/units/test_environment.py

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_interpret_path_env(self):
8080
"""Test path interpretation."""
8181
result = interpret_path_env("/some/path", "TEST_FIELD")
8282
assert isinstance(result, Path)
83-
assert str(result) == "/some/path"
83+
assert str(result) == str(Path("/some/path"))
8484

8585
def test_interpret_existing_path_env_valid(self):
8686
"""Test existing path interpretation with valid path."""
@@ -214,7 +214,11 @@ def test_interpret(self):
214214
assert result == 42
215215

216216
def test_getenv_set(self, monkeypatch):
217-
"""Test getenv when environment variable is set."""
217+
"""Test getenv when environment variable is set.
218+
219+
Args:
220+
monkeypatch: pytest monkeypatch fixture.
221+
"""
218222
monkeypatch.setenv("TEST_VAR", "test_value")
219223
env_var_instance = EnvVar("TEST_VAR", "default", str)
220224
result = env_var_instance.getenv()
@@ -227,21 +231,33 @@ def test_getenv_not_set(self):
227231
assert result is None
228232

229233
def test_getenv_empty_string(self, monkeypatch):
230-
"""Test getenv with empty string value."""
234+
"""Test getenv with empty string value.
235+
236+
Args:
237+
monkeypatch: pytest monkeypatch fixture.
238+
"""
231239
monkeypatch.setenv("TEST_VAR", "")
232240
env_var_instance = EnvVar("TEST_VAR", "default", str)
233241
result = env_var_instance.getenv()
234242
assert result is None
235243

236244
def test_getenv_whitespace_only(self, monkeypatch):
237-
"""Test getenv with whitespace-only value."""
245+
"""Test getenv with whitespace-only value.
246+
247+
Args:
248+
monkeypatch: pytest monkeypatch fixture.
249+
"""
238250
monkeypatch.setenv("TEST_VAR", " ")
239251
env_var_instance = EnvVar("TEST_VAR", "default", str)
240252
result = env_var_instance.getenv()
241253
assert result is None
242254

243255
def test_is_set_true(self, monkeypatch):
244-
"""Test is_set when variable is set."""
256+
"""Test is_set when variable is set.
257+
258+
Args:
259+
monkeypatch: pytest monkeypatch fixture.
260+
"""
245261
monkeypatch.setenv("TEST_VAR", "value")
246262
env_var_instance = EnvVar("TEST_VAR", "default", str)
247263
assert env_var_instance.is_set() is True
@@ -252,13 +268,21 @@ def test_is_set_false(self):
252268
assert env_var_instance.is_set() is False
253269

254270
def test_is_set_empty_string(self, monkeypatch):
255-
"""Test is_set with empty string."""
271+
"""Test is_set with empty string.
272+
273+
Args:
274+
monkeypatch: pytest monkeypatch fixture.
275+
"""
256276
monkeypatch.setenv("TEST_VAR", "")
257277
env_var_instance = EnvVar("TEST_VAR", "default", str)
258278
assert env_var_instance.is_set() is False
259279

260280
def test_get_with_env_value(self, monkeypatch):
261-
"""Test get method when environment variable is set."""
281+
"""Test get method when environment variable is set.
282+
283+
Args:
284+
monkeypatch: pytest monkeypatch fixture.
285+
"""
262286
monkeypatch.setenv("TEST_VAR", "env_value")
263287
env_var_instance = EnvVar("TEST_VAR", "default", str)
264288
result = env_var_instance.get()
@@ -279,7 +303,11 @@ def test_set_string_value(self):
279303
del os.environ["TEST_VAR"]
280304

281305
def test_set_none_value(self, monkeypatch):
282-
"""Test setting None value removes the environment variable."""
306+
"""Test setting None value removes the environment variable.
307+
308+
Args:
309+
monkeypatch: pytest monkeypatch fixture.
310+
"""
283311
monkeypatch.setenv("TEST_VAR", "value")
284312
env_var_instance = EnvVar("TEST_VAR", "default", str)
285313
env_var_instance.set(None)
@@ -387,7 +415,7 @@ class TestClass:
387415

388416
def test_paths_from_env_files(self):
389417
"""Test _paths_from_env_files function."""
390-
env_files = "/path/one:/path/two:/path/three"
418+
env_files = "/path/one" + os.pathsep + "/path/two" + os.pathsep + "/path/three"
391419
result = _paths_from_env_files(env_files)
392420

393421
# Should be reversed order
@@ -396,7 +424,9 @@ def test_paths_from_env_files(self):
396424

397425
def test_paths_from_env_files_with_spaces(self):
398426
"""Test _paths_from_env_files with spaces."""
399-
env_files = " /path/one : /path/two : /path/three "
427+
env_files = (
428+
" /path/one " + os.pathsep + " /path/two " + os.pathsep + " /path/three "
429+
)
400430
result = _paths_from_env_files(env_files)
401431

402432
expected = [Path("/path/three"), Path("/path/two"), Path("/path/one")]
@@ -408,8 +438,12 @@ def test_paths_from_env_files_empty(self):
408438
assert result == []
409439

410440
def test_paths_from_environment_set(self, monkeypatch):
411-
"""Test _paths_from_environment when REFLEX_ENV_FILE is set."""
412-
monkeypatch.setenv("REFLEX_ENV_FILE", "/path/one:/path/two")
441+
"""Test _paths_from_environment when REFLEX_ENV_FILE is set.
442+
443+
Args:
444+
monkeypatch: pytest monkeypatch fixture.
445+
"""
446+
monkeypatch.setenv("REFLEX_ENV_FILE", "/path/one" + os.pathsep + "/path/two")
413447
result = _paths_from_environment()
414448
expected = [Path("/path/two"), Path("/path/one")]
415449
assert result == expected
@@ -425,7 +459,11 @@ def test_paths_from_environment_not_set(self):
425459

426460
@patch("reflex.environment.load_dotenv")
427461
def test_load_dotenv_from_files_with_dotenv(self, mock_load_dotenv):
428-
"""Test _load_dotenv_from_files when dotenv is available."""
462+
"""Test _load_dotenv_from_files when dotenv is available.
463+
464+
Args:
465+
mock_load_dotenv: Mock for the load_dotenv function.
466+
"""
429467
with tempfile.TemporaryDirectory() as temp_dir:
430468
file1 = Path(temp_dir) / "file1.env"
431469
file2 = Path(temp_dir) / "file2.env"
@@ -441,7 +479,11 @@ def test_load_dotenv_from_files_with_dotenv(self, mock_load_dotenv):
441479
@patch("reflex.environment.load_dotenv", None)
442480
@patch("reflex.utils.console")
443481
def test_load_dotenv_from_files_without_dotenv(self, mock_console):
444-
"""Test _load_dotenv_from_files when dotenv is not available."""
482+
"""Test _load_dotenv_from_files when dotenv is not available.
483+
484+
Args:
485+
mock_console: Mock for the console object.
486+
"""
445487
with tempfile.TemporaryDirectory() as temp_dir:
446488
file1 = Path(temp_dir) / "file1.env"
447489
file1.touch()
@@ -456,7 +498,11 @@ def test_load_dotenv_from_files_empty_list(self):
456498

457499
@patch("reflex.environment.load_dotenv")
458500
def test_load_dotenv_from_files_nonexistent_file(self, mock_load_dotenv):
459-
"""Test _load_dotenv_from_files with non-existent file."""
501+
"""Test _load_dotenv_from_files with non-existent file.
502+
503+
Args:
504+
mock_load_dotenv: Mock for the load_dotenv function.
505+
"""
460506
nonexistent_file = Path("/non/existent/file.env")
461507
_load_dotenv_from_files([nonexistent_file])
462508

@@ -545,7 +591,11 @@ class TestClass:
545591

546592
@pytest.fixture(autouse=True)
547593
def cleanup_env_vars():
548-
"""Clean up test environment variables after each test."""
594+
"""Clean up test environment variables after each test.
595+
596+
Yields:
597+
None: Fixture yields control back to the test.
598+
"""
549599
test_vars = [
550600
"TEST_VAR",
551601
"NONEXISTENT_VAR",

0 commit comments

Comments
 (0)