Commit 86d62717 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

refactor File.replace_ext

parent 13df314a
Pipeline #2297 failed with stage
...@@ -6,7 +6,7 @@ class File: ...@@ -6,7 +6,7 @@ class File:
self.file_path = file_path self.file_path = file_path
self.file_path_prefix, self.file_path_ext = os.path.splitext(file_path) self.file_path_prefix, self.file_path_ext = os.path.splitext(file_path)
def switch_extension(self, ext="wht.fits") -> str: def replace_ext(self, ext="wht.fits") -> str:
if ext.startswith("."): if ext.startswith("."):
return self.file_path_prefix + ext return self.file_path_prefix + ext
else: else:
......
...@@ -5,5 +5,5 @@ from csst_common import File ...@@ -5,5 +5,5 @@ from csst_common import File
class TestFile(unittest.TestCase): class TestFile(unittest.TestCase):
def test_parameterized_module_decorator(self): def test_parameterized_module_decorator(self):
f = File("/path/to/file.fits") f = File("/path/to/file.fits")
self.assertEqual(f.switch_extension(".cat"), "/path/to/file.cat") self.assertEqual(f.replace_ext(".cat"), "/path/to/file.cat")
self.assertEqual(f.switch_extension("img.cat"), "/path/to/file_img.cat") self.assertEqual(f.replace_ext("img.cat"), "/path/to/file_img.cat")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment