1212ConnectionFactory = t .Callable [[str ], psycopg .Connection ]
1313
1414
15+ @pytest .fixture (scope = "function" )
16+ def is_windows () -> bool :
17+ """Returns True if running on Windows."""
18+
19+ return os .name == "nt"
20+
21+
22+ @pytest .fixture (scope = "function" )
23+ def is_windows_server_2019 (is_windows : bool ) -> bool :
24+ """Returns True if running on Windows Server 2019."""
25+
26+ if not is_windows :
27+ return False
28+
29+ windows_caption = subprocess .check_output (["wmic" , "os" , "get" , "Caption" ], text = True )
30+ return "Windows Server 2019" in windows_caption
31+
32+
1533@pytest .fixture (scope = "function" )
1634def connection_uri () -> str :
1735 """Read and return connection URI from environment."""
@@ -57,35 +75,40 @@ def connection(
5775 raise RuntimeError ("f{request.param}: unknown value" )
5876
5977
60- def test_connection_uri (connection_uri ):
78+ def test_connection_uri (connection_uri : str ):
6179 """Test that CONNECTION_URI matches EXPECTED_CONNECTION_URI."""
6280
6381 assert connection_uri == os .getenv ("EXPECTED_CONNECTION_URI" )
6482
6583
66- def test_service_name (service_name ):
84+ def test_service_name (service_name : str ):
6785 """Test that SERVICE_NAME matches EXPECTED_SERVICE_NAME."""
6886
6987 assert service_name == os .getenv ("EXPECTED_SERVICE_NAME" )
7088
7189
7290def test_server_encoding (connection : psycopg .Connection ):
73- """Test that PostgreSQL's encoding is 'UTF-8' ."""
91+ """Test that PostgreSQL's encoding matches the one we passed to initdb ."""
7492
7593 assert connection .execute ("SHOW SERVER_ENCODING" ).fetchone ()[0 ] == "UTF8"
7694
7795
78- def test_locale (connection : psycopg .Connection ):
79- """Test that PostgreSQL's locale is 'en_US.UTF-8'."""
96+ def test_locale (connection : psycopg .Connection , is_windows_server_2019 : bool ):
97+ """Test that PostgreSQL's locale matches the one we paased to initdb."""
98+
99+ locale_exp = "en_US.UTF-8"
100+
101+ if is_windows_server_2019 :
102+ locale_exp = "en-US"
80103
81104 lc_collate = connection .execute ("SHOW LC_COLLATE" ).fetchone ()[0 ]
82105 lc_ctype = connection .execute ("SHOW LC_CTYPE" ).fetchone ()[0 ]
83106
84- assert locale .normalize (lc_collate ) == "en_US.UTF-8"
85- assert locale .normalize (lc_ctype ) == "en_US.UTF-8"
107+ assert locale .normalize (lc_collate ) == locale_exp
108+ assert locale .normalize (lc_ctype ) == locale_exp
86109
87110
88- def test_environment_variables ():
111+ def test_environment_variables (is_windows : bool ):
89112 """Test that only expected 'PG*' variables are set."""
90113
91114 pg_environ = {k : v for k , v in os .environ .items () if k .startswith ("PG" )}
@@ -96,7 +119,7 @@ def test_environment_variables():
96119 pg_servicefile_exp = pathlib .Path (os .environ ["RUNNER_TEMP" ], "pgdata" , "pg_service.conf" )
97120 assert pg_servicefile .resolve () == pg_servicefile_exp .resolve ()
98121
99- if os . name == "nt" :
122+ if is_windows :
100123 pg_environ_exp = {
101124 "PGBIN" : "" ,
102125 "PGDATA" : "" ,
0 commit comments