From b05ca4fa783bb5246df55493d90baebbb894116b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABlle=20Rigoudy?= Date: Fri, 8 Mar 2024 09:12:13 +0100 Subject: [PATCH] Bugfix in fline function. --- climaf/chtml.py | 9 ++++++++- scripts/mcdo.py | 3 +++ tests/test_html.py | 37 ++++++++++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/climaf/chtml.py b/climaf/chtml.py index 8e0610a5..dbd897d4 100644 --- a/climaf/chtml.py +++ b/climaf/chtml.py @@ -17,6 +17,7 @@ from __future__ import print_function, division, unicode_literals, absolute_import import os +import pprint import re import pickle import shutil @@ -475,7 +476,13 @@ def foo(*args): repr(sargs))) return else: - sargs = OrderedDict(list([(repr(sarg), sarg) for sarg in sargs])) + new_sargs = OrderedDict() + for sarg in sargs: + if isinstance(sarg, six.string_types): + new_sargs[sarg] = sarg + else: + new_sargs[repr(sarg)] = sarg + sargs = new_sargs rep = open_line(title) for key in sargs: allargs = [farg, sargs[key]] diff --git a/scripts/mcdo.py b/scripts/mcdo.py index 2a8a92ce..bed5ba15 100755 --- a/scripts/mcdo.py +++ b/scripts/mcdo.py @@ -17,6 +17,9 @@ import shutil import six import xarray as xr +import sys + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from env.site_settings import onCiclad, onSpirit from env.clogging import clogger, clog diff --git a/tests/test_html.py b/tests/test_html.py index daabfefe..ce115bd0 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -314,10 +314,41 @@ def tearDown(self): class FlineTests(unittest.TestCase): - @unittest.skipUnless(False, "Not implemented") def test_fline(self): - # TODO: Implement the tests - pass + def my_func(*args): + print(args) + return str(args) + + rep = fline(my_func, 'COD', ['EurNland', 'EurSland', 'AtlOce', 'MedSea'], title="Seasonal cycle (1)", + common_args=['AERmon', [{'id': 'MODIS', + 'name': 'MODIS', + 'ignore': ['EUC12', 'Scplains'], + 'period': '2003-2018', + 'var': 'Cloud_Optical_Thickness_Combined_Mean_Mean'}], True], + other_args={'EurNland': ['blue black black black black black black', '0 0 2 16 5 13 15', 0, 40], + 'EurSland': ['blue black black black black black black', '0 0 2 16 5 13 15', 0, 40], + 'AtlOce': ['blue black black black black black black', '0 0 2 16 5 13 15', 0, 40], + 'MedSea': ['blue black black black black black black', '0 0 2 16 5 13 15', 0, 40]}) + reference_rep = " \n" \ + "
  • Seasonal cycle (1)
  • \n" \ + "('COD', 'EurNland', 'AERmon', [{'id': 'MODIS', 'name': 'MODIS', 'ignore': " \ + "['EUC12', 'Scplains'], 'period': '2003-2018', 'var': " \ + "'Cloud_Optical_Thickness_Combined_Mean_Mean'}], True, " \ + "'blue black black black black black black', '0 0 2 16 5 13 15', 0, 40)\n" \ + "('COD', 'EurSland', 'AERmon', [{'id': 'MODIS', 'name': 'MODIS', 'ignore': " \ + "['EUC12', 'Scplains'], 'period': '2003-2018', 'var': " \ + "'Cloud_Optical_Thickness_Combined_Mean_Mean'}], True, " \ + "'blue black black black black black black', '0 0 2 16 5 13 15', 0, 40)\n" \ + "('COD', 'AtlOce', 'AERmon', [{'id': 'MODIS', 'name': 'MODIS', 'ignore': " \ + "['EUC12', 'Scplains'], 'period': '2003-2018', 'var': " \ + "'Cloud_Optical_Thickness_Combined_Mean_Mean'}], True, " \ + "'blue black black black black black black', '0 0 2 16 5 13 15', 0, 40)\n" \ + "('COD', 'MedSea', 'AERmon', [{'id': 'MODIS', 'name': 'MODIS', 'ignore': " \ + "['EUC12', 'Scplains'], 'period': '2003-2018', 'var': " \ + "'Cloud_Optical_Thickness_Combined_Mean_Mean'}], True, " \ + "'blue black black black black black black', '0 0 2 16 5 13 15', 0, 40)\n " \ + "\n" + self.assertEqual(rep, reference_rep) def tearDown(self): craz()