12
12
ConnectionFactory = t .Callable [[str ], psycopg .Connection ]
13
13
14
14
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
+
15
33
@pytest .fixture (scope = "function" )
16
34
def connection_uri () -> str :
17
35
"""Read and return connection URI from environment."""
@@ -57,35 +75,40 @@ def connection(
57
75
raise RuntimeError ("f{request.param}: unknown value" )
58
76
59
77
60
- def test_connection_uri (connection_uri ):
78
+ def test_connection_uri (connection_uri : str ):
61
79
"""Test that CONNECTION_URI matches EXPECTED_CONNECTION_URI."""
62
80
63
81
assert connection_uri == os .getenv ("EXPECTED_CONNECTION_URI" )
64
82
65
83
66
- def test_service_name (service_name ):
84
+ def test_service_name (service_name : str ):
67
85
"""Test that SERVICE_NAME matches EXPECTED_SERVICE_NAME."""
68
86
69
87
assert service_name == os .getenv ("EXPECTED_SERVICE_NAME" )
70
88
71
89
72
90
def 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 ."""
74
92
75
93
assert connection .execute ("SHOW SERVER_ENCODING" ).fetchone ()[0 ] == "UTF8"
76
94
77
95
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"
80
103
81
104
lc_collate = connection .execute ("SHOW LC_COLLATE" ).fetchone ()[0 ]
82
105
lc_ctype = connection .execute ("SHOW LC_CTYPE" ).fetchone ()[0 ]
83
106
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
86
109
87
110
88
- def test_environment_variables ():
111
+ def test_environment_variables (is_windows : bool ):
89
112
"""Test that only expected 'PG*' variables are set."""
90
113
91
114
pg_environ = {k : v for k , v in os .environ .items () if k .startswith ("PG" )}
@@ -96,7 +119,7 @@ def test_environment_variables():
96
119
pg_servicefile_exp = pathlib .Path (os .environ ["RUNNER_TEMP" ], "pgdata" , "pg_service.conf" )
97
120
assert pg_servicefile .resolve () == pg_servicefile_exp .resolve ()
98
121
99
- if os . name == "nt" :
122
+ if is_windows :
100
123
pg_environ_exp = {
101
124
"PGBIN" : "" ,
102
125
"PGDATA" : "" ,
0 commit comments