@@ -53,6 +53,50 @@ def gce(request, common_mocks, tmpdir):
53
53
class TestGCE :
54
54
"""General GCE testing."""
55
55
56
+ @pytest .mark .parametrize (
57
+ "toml_content,expected" ,
58
+ (
59
+ (
60
+ "[gce]\n service_account_email = '[email protected] '\n " ,
61
+
62
+ ),
63
+
64
+ ),
65
+ )
66
+ def test_init_config_parsing_service_account_email (
67
+ self , toml_content , expected , common_mocks , tmpdir
68
+ ):
69
+ """
70
+ service_account_email comes from pycloudlib.toml fallback config_file.
71
+ """
72
+ cfg_file = tmpdir .join ("pyproject.toml" )
73
+ cfg_file .write (toml_content )
74
+ gce = GCE (tag = "pycl-tag" , config_file = cfg_file .strpath )
75
+ assert expected == gce .service_account_email
76
+
77
+ @pytest .mark .parametrize (
78
+ "environ,cred_path,project" ,
79
+ [
80
+ ({}, "" , "my-project" ),
81
+ (
82
+ {"GOOGLE_APPLICATION_CREDENTIALS" : "other-file" },
83
+ "other-file" ,
84
+ "my-project" ,
85
+ ),
86
+ ({"GOOGLE_CLOUD_PROJECT" : "env-project" }, "" , "env-project" ),
87
+ ],
88
+ )
89
+ def test_init_config_parsing_from_environment (
90
+ self , environ , cred_path , project , common_mocks , tmpdir
91
+ ):
92
+ with mock .patch .dict ("os.environ" , values = environ ):
93
+ gce = GCE (
94
+ tag = "pycl-tag" ,
95
+ config_file = tmpdir .join ("pyproject.toml" ).strpath ,
96
+ )
97
+ assert cred_path == gce .credentials_path
98
+ assert project == gce .project
99
+
56
100
@pytest .mark .parametrize ("gce" , [{}], indirect = True )
57
101
@pytest .mark .parametrize (
58
102
[
0 commit comments