From cbf3d0b0c6a4c929bc569a0085d0d570d503c342 Mon Sep 17 00:00:00 2001 From: mmpe <mmpe@dtu.dk> Date: Fri, 2 Nov 2018 12:02:12 +0100 Subject: [PATCH] add test for auto_detect_modelpath with mixed case filenames --- wetb/hawc2/htc_file.py | 11 +++++++++-- wetb/hawc2/tests/test_htc_file.py | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/wetb/hawc2/htc_file.py b/wetb/hawc2/htc_file.py index 317ed80..5c619e7 100644 --- a/wetb/hawc2/htc_file.py +++ b/wetb/hawc2/htc_file.py @@ -105,10 +105,17 @@ class HTCFile(HTCContents, HTCDefaults, HTCExtensions): import numpy as np input_files = HTCFile(self.filename, 'unknown').input_files() rel_input_files = [f for f in input_files if not os.path.isabs(f)] - found = ([np.sum([os.path.isfile(os.path.join(os.path.dirname(self.filename), "../" * i, f)) + + def isfile_case_insensitive(f): + try: + unix_path_old(f) + return True + except IOError: + return False + found = ([np.sum([isfile_case_insensitive(os.path.join(os.path.dirname(self.filename), "../" * i, f)) for f in rel_input_files]) for i in range(4)]) # for f in self.input_files(): - # print (os.path.isfile(os.path.join(os.path.dirname(self.filename), "../",f)), f) + # print(os.path.isfile(os.path.join(os.path.dirname(self.filename), "../", f)), f) if max(found) > 0: relpath = "../" * np.argmax(found) return os.path.abspath(os.path.join(os.path.dirname(self.filename), relpath)) diff --git a/wetb/hawc2/tests/test_htc_file.py b/wetb/hawc2/tests/test_htc_file.py index cfb19aa..c43b58f 100644 --- a/wetb/hawc2/tests/test_htc_file.py +++ b/wetb/hawc2/tests/test_htc_file.py @@ -300,6 +300,10 @@ end turb_export;""" htcfile.filename)).replace("\\", "/"), "../..") self.assertRaisesRegex(ValueError, "Modelpath cannot be autodetected", HTCFile, self.testfilepath + "test2.htc") + def test_htc_model_autodetect_upper_case_files(self): + htcfile = HTCFile(self.testfilepath + "../simulation_setup/DTU10MWRef6.0/htc/DTU_10MW_RWT.htc") + self.assertEqual(os.path.relpath(htcfile.modelpath, os.path.dirname(htcfile.filename)), "..") + def test_open_eq_save(self): HTCFile(self.testfilepath + "test3.htc", "../").save(self.testfilepath + "tmp.htc") htcfile = HTCFile(self.testfilepath + "tmp.htc", "../") -- GitLab