11import os
22
3+ from pathlib import Path
34import yaml
45from data_diff .diff_tables import Algorithm
56from .test_cli import run_datadiff_cli
@@ -51,7 +52,7 @@ def test_get_datadiff_variables_empty(self):
5152 def test_get_models (self , mock_open ):
5253 expected_value = "expected_value"
5354 mock_self = Mock ()
54- mock_self .project_dir = ""
55+ mock_self .project_dir = Path ()
5556 mock_run_results = Mock ()
5657 mock_success_result = Mock ()
5758 mock_failed_result = Mock ()
@@ -69,47 +70,47 @@ def test_get_models(self, mock_open):
6970 models = DbtParser .get_models (mock_self )
7071
7172 self .assertEqual (expected_value , models [0 ])
72- mock_open .assert_any_call (RUN_RESULTS_PATH )
73- mock_open .assert_any_call (MANIFEST_PATH )
73+ mock_open .assert_any_call (Path ( RUN_RESULTS_PATH ) )
74+ mock_open .assert_any_call (Path ( MANIFEST_PATH ) )
7475 mock_self .parse_run_results .assert_called_once_with (run_results = {})
7576 mock_self .parse_manifest .assert_called_once_with (manifest = {})
7677
7778 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
7879 def test_get_models_bad_lower_dbt_version (self , mock_open ):
7980 mock_self = Mock ()
80- mock_self .project_dir = ""
81+ mock_self .project_dir = Path ()
8182 mock_run_results = Mock ()
8283 mock_self .parse_run_results .return_value = mock_run_results
8384 mock_run_results .metadata .dbt_version = "0.19.0"
8485
8586 with self .assertRaises (Exception ) as ex :
8687 DbtParser .get_models (mock_self )
8788
88- mock_open .assert_called_once_with (RUN_RESULTS_PATH )
89+ mock_open .assert_called_once_with (Path ( RUN_RESULTS_PATH ) )
8990 mock_self .parse_run_results .assert_called_once_with (run_results = {})
9091 mock_self .parse_manifest .assert_not_called ()
9192 self .assertIn ("version to be" , ex .exception .args [0 ])
9293
9394 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
9495 def test_get_models_bad_upper_dbt_version (self , mock_open ):
9596 mock_self = Mock ()
96- mock_self .project_dir = ""
97+ mock_self .project_dir = Path ()
9798 mock_run_results = Mock ()
9899 mock_self .parse_run_results .return_value = mock_run_results
99100 mock_run_results .metadata .dbt_version = "1.5.1"
100101
101102 with self .assertRaises (Exception ) as ex :
102103 DbtParser .get_models (mock_self )
103104
104- mock_open .assert_called_once_with (RUN_RESULTS_PATH )
105+ mock_open .assert_called_once_with (Path ( RUN_RESULTS_PATH ) )
105106 mock_self .parse_run_results .assert_called_once_with (run_results = {})
106107 mock_self .parse_manifest .assert_not_called ()
107108 self .assertIn ("version to be" , ex .exception .args [0 ])
108109
109110 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
110111 def test_get_models_no_success (self , mock_open ):
111112 mock_self = Mock ()
112- mock_self .project_dir = ""
113+ mock_self .project_dir = Path ()
113114 mock_run_results = Mock ()
114115 mock_success_result = Mock ()
115116 mock_failed_result = Mock ()
@@ -126,21 +127,22 @@ def test_get_models_no_success(self, mock_open):
126127 with self .assertRaises (Exception ):
127128 DbtParser .get_models (mock_self )
128129
129- mock_open .assert_any_call (RUN_RESULTS_PATH )
130- mock_open .assert_any_call (MANIFEST_PATH )
130+ mock_open .assert_any_call (Path ( RUN_RESULTS_PATH ) )
131+ mock_open .assert_any_call (Path ( MANIFEST_PATH ) )
131132 mock_self .parse_run_results .assert_called_once_with (run_results = {})
132133 mock_self .parse_manifest .assert_called_once_with (manifest = {})
133134
134135 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
135136 def test_set_project_dict (self , mock_open ):
136137 expected_dict = {"key1" : "value1" }
137138 mock_self = Mock ()
138- mock_self .project_dir = ""
139+
140+ mock_self .project_dir = Path ()
139141 mock_self .yaml .safe_load .return_value = expected_dict
140142 DbtParser .set_project_dict (mock_self )
141143
142144 self .assertEqual (mock_self .project_dict , expected_dict )
143- mock_open .assert_called_once_with (PROJECT_FILE )
145+ mock_open .assert_called_once_with (Path ( PROJECT_FILE ) )
144146
145147 def test_set_connection_snowflake_success (self ):
146148 expected_driver = "snowflake"
@@ -222,7 +224,7 @@ def test_get_connection_creds_success(self, mock_open):
222224 profile = profiles_dict ["a_profile" ]
223225 expected_credentials = profiles_dict ["a_profile" ]["outputs" ]["a_target" ]
224226 mock_self = Mock ()
225- mock_self .profiles_dir = ""
227+ mock_self .profiles_dir = Path ()
226228 mock_self .project_dict = {"profile" : "a_profile" }
227229 mock_self .yaml .safe_load .return_value = profiles_dict
228230 mock_self .ProfileRenderer ().render_data .return_value = profile
@@ -234,7 +236,7 @@ def test_get_connection_creds_success(self, mock_open):
234236 def test_get_connection_no_matching_profile (self , mock_open ):
235237 profiles_dict = {"a_profile" : {}}
236238 mock_self = Mock ()
237- mock_self .profiles_dir = ""
239+ mock_self .profiles_dir = Path ()
238240 mock_self .project_dict = {"profile" : "wrong_profile" }
239241 mock_self .yaml .safe_load .return_value = profiles_dict
240242 profile = profiles_dict ["a_profile" ]
@@ -252,7 +254,7 @@ def test_get_connection_no_target(self, mock_open):
252254 }
253255 }
254256 mock_self = Mock ()
255- mock_self .profiles_dir = ""
257+ mock_self .profiles_dir = Path ()
256258 profile = profiles_dict ["a_profile" ]
257259 mock_self .ProfileRenderer ().render_data .return_value = profile
258260 mock_self .project_dict = {"profile" : "a_profile" }
@@ -269,7 +271,7 @@ def test_get_connection_no_target(self, mock_open):
269271 def test_get_connection_no_outputs (self , mock_open ):
270272 profiles_dict = {"a_profile" : {"target" : "a_target" }}
271273 mock_self = Mock ()
272- mock_self .profiles_dir = ""
274+ mock_self .profiles_dir = Path ()
273275 mock_self .project_dict = {"profile" : "a_profile" }
274276 profile = profiles_dict ["a_profile" ]
275277 mock_self .ProfileRenderer ().render_data .return_value = profile
@@ -286,7 +288,7 @@ def test_get_connection_no_credentials(self, mock_open):
286288 }
287289 }
288290 mock_self = Mock ()
289- mock_self .profiles_dir = ""
291+ mock_self .profiles_dir = Path ()
290292 mock_self .project_dict = {"profile" : "a_profile" }
291293 mock_self .yaml .safe_load .return_value = profiles_dict
292294 profile = profiles_dict ["a_profile" ]
@@ -305,7 +307,7 @@ def test_get_connection_no_target_credentials(self, mock_open):
305307 }
306308 }
307309 mock_self = Mock ()
308- mock_self .profiles_dir = ""
310+ mock_self .profiles_dir = Path ()
309311 mock_self .project_dict = {"profile" : "a_profile" }
310312 profile = profiles_dict ["a_profile" ]
311313 mock_self .ProfileRenderer ().render_data .return_value = profile
@@ -322,7 +324,7 @@ def test_get_connection_no_type(self, mock_open):
322324 }
323325 }
324326 mock_self = Mock ()
325- mock_self .profiles_dir = ""
327+ mock_self .profiles_dir = Path ()
326328 mock_self .project_dict = {"profile" : "a_profile" }
327329 mock_self .yaml .safe_load .return_value = profiles_dict
328330 profile = profiles_dict ["a_profile" ]
0 commit comments