File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 55import sys
66import textwrap
77from unittest import mock
8+ from dotenv import dotenv_values
9+
10+
811
912import pytest
1013
@@ -565,3 +568,29 @@ def test_dotenv_values_file_stream(dotenv_path):
565568 result = dotenv .dotenv_values (stream = f )
566569
567570 assert result == {"a" : "b" }
571+
572+ def _read_dotenv_stream (path ):
573+ """
574+ Safely read a .env file line by line.
575+ Works on:
576+ - Regular files
577+ - FIFOs (macOS/Linux)
578+ - fd-backed files (1Password)
579+ - Windows special files
580+ """
581+ try :
582+ with open (path , "r" , encoding = "utf-8" , errors = "replace" ) as f :
583+ return "" .join (line for line in f )
584+ except (OSError , IOError ):
585+ return ""
586+
587+ @pytest .mark .skipif (os .name != "nt" , reason = "Windows-specific test" )
588+ def test_windows_fd_env_file (tmp_path ):
589+ """
590+ Simulate a Windows fd-backed .env file (like 1Password mount).
591+ """
592+ env_path = tmp_path / "win_env.env"
593+ env_path .write_text ("FOO=bar\n " ) # simulate fd-backed behavior
594+
595+ values = dotenv_values (env_path )
596+ assert values ["FOO" ] == "bar"
You can’t perform that action at this time.
0 commit comments