Skip to content

Commit aa82e88

Browse files
fixing configmanager test warnings (#1962)
* fixing configmanager test warnings * more warning fixes
1 parent 5637b34 commit aa82e88

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

test/integ/test_connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
import pathlib
1212
import queue
13+
import stat
1314
import threading
1415
import warnings
1516
import weakref
@@ -1264,6 +1265,7 @@ def test_connection_name_loading(monkeypatch, db_parameters, tmp_path, mode):
12641265
else:
12651266
tmp_connections_file = tmp_path / "connections.toml"
12661267
tmp_connections_file.write_text(tomlkit.dumps(doc))
1268+
tmp_connections_file.chmod(stat.S_IRUSR | stat.S_IWUSR)
12671269
with snowflake.connector.connect(
12681270
connection_name="default",
12691271
connections_file_path=tmp_connections_file,

test/integ/test_easy_logging.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
33
#
44

5+
import stat
56
from test.integ.conftest import create_connection
67

78
import pytest
@@ -28,7 +29,11 @@ def log_directory(tmp_path_factory):
2829

2930
@pytest.fixture(scope="function")
3031
def temp_config_file(tmp_path_factory):
31-
return tmp_path_factory.mktemp("config_file_path") / "config.toml"
32+
config_file = tmp_path_factory.mktemp("config_file_path") / "config.toml"
33+
# Pre-create config file and setup correct permissions on it
34+
config_file.touch()
35+
config_file.chmod(stat.S_IRUSR | stat.S_IWUSR)
36+
return config_file
3237

3338

3439
@pytest.fixture(scope="function")

test/unit/test_configmanager.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def tmp_files_helper(cwd: Path, to_create: files) -> None:
5858
def tmp_files(tmp_path: Path) -> Callable[[files], Path]:
5959
def create_tmp_files(to_create: files) -> Path:
6060
tmp_files_helper(tmp_path, to_create)
61+
# Automatically fix file permissions
62+
if "config.toml" in to_create:
63+
(tmp_path / "config.toml").chmod(stat.S_IRUSR | stat.S_IWUSR)
64+
if "connections.toml" in to_create:
65+
(tmp_path / "connections.toml").chmod(stat.S_IRUSR | stat.S_IWUSR)
6166
return tmp_path
6267

6368
return create_tmp_files
@@ -117,7 +122,7 @@ def test_simple_config_read(tmp_files):
117122
name="output_format",
118123
choices=("json", "yaml", "toml"),
119124
)
120-
TEST_PARSER.add_subparser(settings_parser)
125+
TEST_PARSER.add_submanager(settings_parser)
121126
assert TEST_PARSER["connections"] == {
122127
"snowflake": {
123128
"account": "snowflake",
@@ -170,7 +175,7 @@ def test_simple_config_read_sliced(tmp_files):
170175
name="output_format",
171176
choices=("json", "yaml", "toml"),
172177
)
173-
TEST_PARSER.add_subparser(settings_parser)
178+
TEST_PARSER.add_submanager(settings_parser)
174179
assert TEST_PARSER["connections"] == {
175180
"snowflake": {
176181
"account": "snowflake",
@@ -209,7 +214,7 @@ def test_missing_value(tmp_files):
209214
name="output_format",
210215
choices=("json", "yaml", "toml"),
211216
)
212-
TEST_PARSER.add_subparser(settings_parser)
217+
TEST_PARSER.add_submanager(settings_parser)
213218
assert TEST_PARSER["connections"] == {
214219
"snowflake": {
215220
"account": "snowflake",
@@ -266,7 +271,7 @@ def test_missing_value_sliced(tmp_files):
266271
name="output_format",
267272
choices=("json", "yaml", "toml"),
268273
)
269-
TEST_PARSER.add_subparser(settings_parser)
274+
TEST_PARSER.add_submanager(settings_parser)
270275
assert TEST_PARSER["connections"] == {
271276
"snowflake": {
272277
"account": "snowflake",
@@ -322,7 +327,7 @@ def test_only_in_slice(tmp_files):
322327
name="output_format",
323328
choices=("json", "yaml", "toml"),
324329
)
325-
TEST_PARSER.add_subparser(settings_parser)
330+
TEST_PARSER.add_submanager(settings_parser)
326331
with pytest.raises(
327332
ConfigSourceError,
328333
match="Configuration option 'connections' is not defined.*",
@@ -335,8 +340,8 @@ def test_simple_nesting(monkeypatch, tmp_path):
335340
c2 = ConfigManager(name="sb")
336341
c3 = ConfigManager(name="sb")
337342
c3.add_option(name="b", parse_str=lambda e: e.lower() == "true")
338-
c2.add_subparser(c3)
339-
c1.add_subparser(c2)
343+
c2.add_submanager(c3)
344+
c1.add_submanager(c2)
340345
with monkeypatch.context() as m:
341346
m.setenv("SNOWFLAKE_SB_SB_B", "TrUe")
342347
assert c1["sb"]["sb"]["b"] is True
@@ -347,7 +352,7 @@ def test_complicated_nesting(monkeypatch, tmp_path):
347352
c1 = ConfigManager(file_path=c_file, name="root_parser")
348353
c2 = ConfigManager(file_path=tmp_path / "config2.toml", name="sp")
349354
c2.add_option(name="b", parse_str=lambda e: e.lower() == "true")
350-
c1.add_subparser(c2)
355+
c1.add_submanager(c2)
351356
c_file.write_text(
352357
dedent(
353358
"""\
@@ -361,6 +366,7 @@ def test_complicated_nesting(monkeypatch, tmp_path):
361366
"""
362367
)
363368
)
369+
c_file.chmod(stat.S_IRUSR | stat.S_IWUSR)
364370
assert c1["sp"]["b"] is True
365371

366372

@@ -381,6 +387,7 @@ def test_error_invalid_toml(tmp_path):
381387
"""
382388
)
383389
)
390+
c_file.chmod(stat.S_IRUSR | stat.S_IWUSR)
384391
with pytest.raises(
385392
ConfigSourceError,
386393
match=re.escape(f"An unknown error happened while loading '{str(c_file)}'"),
@@ -393,7 +400,7 @@ def test_error_invalid_toml(tmp_path):
393400

394401
def test_error_child_conflict():
395402
cp = ConfigManager(name="test_parser")
396-
cp.add_subparser(ConfigManager(name="b"))
403+
cp.add_submanager(ConfigManager(name="b"))
397404
with pytest.raises(
398405
ConfigManagerError,
399406
match="'b' sub-manager, or option conflicts with a child element of 'test_parser'",
@@ -654,7 +661,8 @@ def test_deprecationwarning_config_parser():
654661
str(w[-1].message)
655662
== "CONFIG_PARSER has been deprecated, use CONFIG_MANAGER instead"
656663
)
657-
assert config_manager.CONFIG_MANAGER is config_manager.CONFIG_PARSER
664+
with warnings.catch_warnings(record=True) as w:
665+
assert config_manager.CONFIG_MANAGER is config_manager.CONFIG_PARSER
658666

659667

660668
def test_configoption_default_value(tmp_path, monkeypatch):
@@ -702,6 +710,7 @@ def test_defaultconnectionname(tmp_path, monkeypatch):
702710
"""
703711
)
704712
)
713+
c_file.chmod(stat.S_IRUSR | stat.S_IWUSR)
705714
# re-cache config file from disk
706715
CONFIG_MANAGER.file_path = c_file
707716
CONFIG_MANAGER.conf_file_cache = None

test/unit/test_connection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import json
99
import os
10+
import stat
1011
import sys
1112
from pathlib import Path
1213
from secrets import token_urlsafe
@@ -256,6 +257,7 @@ def test_missing_default_connection_conf_file(monkeypatch, tmp_path):
256257
"""
257258
)
258259
)
260+
config_file.chmod(stat.S_IRUSR | stat.S_IWUSR)
259261
with monkeypatch.context() as m:
260262
m.delenv("SNOWFLAKE_DEFAULT_CONNECTION_NAME", raising=False)
261263
m.delenv("SNOWFLAKE_CONNECTIONS", raising=False)
@@ -282,6 +284,7 @@ def test_missing_default_connection_conn_file(monkeypatch, tmp_path):
282284
"""
283285
)
284286
)
287+
connections_file.chmod(stat.S_IRUSR | stat.S_IWUSR)
285288
with monkeypatch.context() as m:
286289
m.delenv("SNOWFLAKE_DEFAULT_CONNECTION_NAME", raising=False)
287290
m.delenv("SNOWFLAKE_CONNECTIONS", raising=False)
@@ -306,6 +309,7 @@ def test_missing_default_connection_conf_conn_file(monkeypatch, tmp_path):
306309
"""
307310
)
308311
)
312+
config_file.chmod(stat.S_IRUSR | stat.S_IWUSR)
309313
connections_file.write_text(
310314
dedent(
311315
"""\
@@ -316,6 +320,7 @@ def test_missing_default_connection_conf_conn_file(monkeypatch, tmp_path):
316320
"""
317321
)
318322
)
323+
connections_file.chmod(stat.S_IRUSR | stat.S_IWUSR)
319324
with monkeypatch.context() as m:
320325
m.delenv("SNOWFLAKE_DEFAULT_CONNECTION_NAME", raising=False)
321326
m.delenv("SNOWFLAKE_CONNECTIONS", raising=False)

test/unit/test_easy_logging.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#
22
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
33
#
4+
import stat
5+
46
import pytest
57

68
pytestmark = pytest.mark.skipolddriver
@@ -26,7 +28,11 @@
2628

2729
@pytest.fixture(scope="function")
2830
def temp_config_file(tmp_path_factory):
29-
return tmp_path_factory.mktemp("config_file_path") / "config.toml"
31+
config_file = tmp_path_factory.mktemp("config_file_path") / "config.toml"
32+
# Pre-create config file and setup correct permissions on it
33+
config_file.touch()
34+
config_file.chmod(stat.S_IRUSR | stat.S_IWUSR)
35+
return config_file
3036

3137

3238
@pytest.fixture(scope="function")

0 commit comments

Comments
 (0)