Skip to content

Commit 973d044

Browse files
authored
Merge pull request #175 from CURENT/misc
Format
2 parents 804ade7 + d67a232 commit 973d044

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

ams/core/matprocessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def export_csv(self, path=None):
9494
path, file_name = get_export_path(self.owner.system,
9595
self.name,
9696
path=path,
97-
format='csv')
97+
fmt='csv')
9898

9999
pd.DataFrame(data=self.v, columns=self.col_names, index=self.row_names).to_csv(path)
100100

ams/routines/routine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def export_csv(self, path=None):
455455
return None
456456

457457
path, file_name = get_export_path(self.system, self.class_name,
458-
path=path, format='csv')
458+
path=path, fmt='csv')
459459

460460
data_dict = initialize_data_dict(self)
461461

ams/utils/paths.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def confirm_overwrite(outfile, overwrite=None):
257257
return True
258258

259259

260-
def get_export_path(system, fname, path=None, format='csv'):
260+
def get_export_path(system, fname, path=None, fmt='csv'):
261261
"""
262262
Get the absolute export path and the derived file name for
263263
an AMS system export.
@@ -274,10 +274,10 @@ def get_export_path(system, fname, path=None, format='csv'):
274274
The desired output path.
275275
- If it's a directory, the file name will be generated.
276276
- If it's a full file path (with extension), the filename part will be used
277-
as the base, and the `format` argument will determine the final extension.
277+
as the base, and the `fmt` argument will determine the final extension.
278278
- If None, the current working directory will be used, and the filename will
279279
be generated.
280-
format : str, optional
280+
fmt : str, optional
281281
The file format to export, e.g., 'csv', 'json'. Default is 'csv'.
282282
283283
Returns
@@ -295,7 +295,7 @@ def get_export_path(system, fname, path=None, format='csv'):
295295
base_name_prefix = os.path.splitext(os.path.basename(system.files.fullname))[0]
296296
base_name_prefix += f'_{fname}'
297297

298-
target_extension = format.lower() # Ensure consistent extension casing
298+
target_extension = fmt.lower() # Ensure consistent extension casing
299299

300300
if path:
301301
abs_path = os.path.abspath(path) # Resolve to absolute path early

tests/test_paths.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ def test_no_fullname(self):
3939
path, file_name = get_export_path(self.ss,
4040
'DCOPF',
4141
path=None,
42-
format='csv')
42+
fmt='csv')
4343

4444
dir_path, only_file_name = os.path.split(path)
4545
self.assertTrue(os.path.exists(dir_path))
46+
self.assertIsNotNone(only_file_name)
4647

4748
def test_no_path(self):
4849
"""
@@ -51,10 +52,11 @@ def test_no_path(self):
5152
path, file_name = get_export_path(self.ss,
5253
'DCOPF',
5354
path=None,
54-
format='csv')
55+
fmt='csv')
5556

5657
dir_path, only_file_name = os.path.split(path)
5758
self.assertTrue(os.path.exists(dir_path))
59+
self.assertIsNotNone(only_file_name)
5860

5961
def test_current_path(self):
6062
"""
@@ -63,7 +65,21 @@ def test_current_path(self):
6365
path, file_name = get_export_path(self.ss,
6466
'DCOPF',
6567
path='.',
66-
format='csv')
68+
fmt='csv')
6769

6870
dir_path, only_file_name = os.path.split(path)
6971
self.assertTrue(os.path.exists(dir_path))
72+
self.assertIsNotNone(only_file_name)
73+
74+
def test_path_with_file_name(self):
75+
"""
76+
Test export path with path and file name specified.
77+
"""
78+
path, file_name = get_export_path(self.ss,
79+
'DCOPF',
80+
path='./test_export.csv',
81+
fmt='csv',)
82+
83+
dir_path, only_file_name = os.path.split(path)
84+
self.assertTrue(os.path.exists(dir_path))
85+
self.assertEqual(only_file_name, 'test_export.csv')

0 commit comments

Comments
 (0)