From b2671161c583d3a05f41d39994ec9272d184688a Mon Sep 17 00:00:00 2001 From: madsmpedersen <m@madsp.dk> Date: Fri, 19 Feb 2016 15:09:42 +0100 Subject: [PATCH] fix multiple exit bug in htc file --- wetb/hawc2/htc_contents.py | 7 +++++++ wetb/hawc2/htc_file.py | 6 +++++- wetb/hawc2/tests/test_htc_file.py | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/wetb/hawc2/htc_contents.py b/wetb/hawc2/htc_contents.py index 821748aa..bc6bba5e 100644 --- a/wetb/hawc2/htc_contents.py +++ b/wetb/hawc2/htc_contents.py @@ -163,6 +163,8 @@ class HTCLine(HTCContents): return str(self) def __str__(self, level=0): + if self.name_ == "": + return "" return "%s%s%s;%s\n" % (" "*(level), self.name_, ("", "\t" + self.str_values())[bool(self.values)], ("", "\t" + self.comments)[bool(self.comments.strip())]) @@ -191,6 +193,11 @@ class HTCLine(HTCContents): values = [fmt(v) for v in values] return HTCLine(name, values, end_comments) + def remove(self): + self.name_ = "" + self.values = [] + self.comments = "" + class HTCOutputSection(HTCSection): sensors = None diff --git a/wetb/hawc2/htc_file.py b/wetb/hawc2/htc_file.py index 5efd49c3..2406ac54 100644 --- a/wetb/hawc2/htc_file.py +++ b/wetb/hawc2/htc_file.py @@ -66,7 +66,11 @@ class HTCFile(HTCContents, HTCDefaults): if l.lower().lstrip().startswith('continue_in_file'): filename = l.lstrip().split(";")[0][len("continue_in_file"):].strip() filename = os.path.join(os.path.dirname(self.filename), self.modelpath, filename) - htc_lines.extend(self.readlines(filename)) + + for line in self.readlines(filename): + if line.lstrip().lower().startswith('exit'): + break + htc_lines.append(line) else: htc_lines.append(l) return htc_lines diff --git a/wetb/hawc2/tests/test_htc_file.py b/wetb/hawc2/tests/test_htc_file.py index 6429b14c..51da8f5c 100644 --- a/wetb/hawc2/tests/test_htc_file.py +++ b/wetb/hawc2/tests/test_htc_file.py @@ -205,6 +205,8 @@ class TestHtcFile(unittest.TestCase): self.assertIn('main_body__31', htcfile.new_htc_structure.keys()) self.assertIn(os.path.abspath(self.testfilepath + 'orientation.dat'), [os.path.abspath(f) for f in htcfile.input_files()]) self.assertIn('./data/NREL_5MW_st1.txt', htcfile.input_files()) + self.assertEqual(str(htcfile).count("exit"), 1) + self.assertIn('filename\t./res/oc4_p2_Load_case_eq;', str(htcfile)) def test_tjul_example(self): htcfile = HTCFile(self.testfilepath + "./tjul.htc", ".") -- GitLab