@@ -107,3 +107,77 @@ def test_log_level(invoke_cli: t.Callable[..., Result], create_empty_project: Em
107107 result = invoke_cli (["--log-level" , "debug" , "list" ])
108108 assert result .exit_code == 0
109109 assert logging .getLogger ("sqlmesh" ).getEffectiveLevel () == logging .DEBUG
110+
111+
112+ def test_profiles_dir (
113+ invoke_cli : t .Callable [..., Result ], create_empty_project : EmptyProjectCreator , tmp_path : Path
114+ ):
115+ project_dir , _ = create_empty_project (project_name = "test_profiles_dir" )
116+
117+ orig_profiles_yml = project_dir / "profiles.yml"
118+ assert orig_profiles_yml .exists ()
119+
120+ new_profiles_yml = tmp_path / "some_other_place" / "profiles.yml"
121+ new_profiles_yml .parent .mkdir (parents = True )
122+
123+ orig_profiles_yml .rename (new_profiles_yml )
124+ assert not orig_profiles_yml .exists ()
125+ assert new_profiles_yml .exists ()
126+
127+ # should fail if we don't specify --profiles-dir
128+ result = invoke_cli (["list" ])
129+ assert result .exit_code > 0 , result .output
130+ assert "profiles.yml not found" in result .output
131+
132+ # should pass if we specify --profiles-dir
133+ result = invoke_cli (["--profiles-dir" , str (new_profiles_yml .parent ), "list" ])
134+ assert result .exit_code == 0 , result .output
135+ assert "Models in project" in result .output
136+
137+
138+ def test_project_dir (
139+ invoke_cli : t .Callable [..., Result ], create_empty_project : EmptyProjectCreator
140+ ):
141+ orig_project_dir , _ = create_empty_project (project_name = "test_project_dir" )
142+
143+ orig_project_yml = orig_project_dir / "dbt_project.yml"
144+ assert orig_project_yml .exists ()
145+
146+ new_project_yml = orig_project_dir / "nested" / "dbt_project.yml"
147+ new_project_yml .parent .mkdir (parents = True )
148+
149+ orig_project_yml .rename (new_project_yml )
150+ assert not orig_project_yml .exists ()
151+ assert new_project_yml .exists ()
152+
153+ # should fail if we don't specify --project-dir
154+ result = invoke_cli (["list" ])
155+ assert result .exit_code != 0 , result .output
156+ assert "Error:" in result .output
157+
158+ # should fail if the profiles.yml also doesnt exist at that --project-dir
159+ result = invoke_cli (["--project-dir" , str (new_project_yml .parent ), "list" ])
160+ assert result .exit_code != 0 , result .output
161+ assert "profiles.yml not found" in result .output
162+
163+ # should pass if it can find both files, either because we specified --profiles-dir explicitly or the profiles.yml was found in --project-dir
164+ result = invoke_cli (
165+ [
166+ "--project-dir" ,
167+ str (new_project_yml .parent ),
168+ "--profiles-dir" ,
169+ str (orig_project_dir ),
170+ "list" ,
171+ ]
172+ )
173+ assert result .exit_code == 0 , result .output
174+ assert "Models in project" in result .output
175+
176+ orig_profiles_yml = orig_project_dir / "profiles.yml"
177+ new_profiles_yml = new_project_yml .parent / "profiles.yml"
178+ assert orig_profiles_yml .exists ()
179+ orig_profiles_yml .rename (new_profiles_yml )
180+
181+ result = invoke_cli (["--project-dir" , str (new_project_yml .parent ), "list" ])
182+ assert result .exit_code == 0 , result .output
183+ assert "Models in project" in result .output
0 commit comments