From e3acb631eedab0f627b867ef684e30e7017680b2 Mon Sep 17 00:00:00 2001 From: Loic Huder Date: Wed, 14 Oct 2020 09:45:52 +0200 Subject: [PATCH] Fixed lint errors after running flake8 --- pygeodyn/_version.py | 2 +- pygeodyn/augkf/__init__.py | 2 +- pygeodyn/augkf/algo.py | 5 +- pygeodyn/augkf/analyser.py | 1 + pygeodyn/common.py | 4 +- pygeodyn/corestates.py | 4 +- pygeodyn/generic/__init__.py | 2 - pygeodyn/generic/algo.py | 3 - pygeodyn/generic/computer.py | 1 - pygeodyn/inout/config.py | 5 +- pygeodyn/inout/observations.py | 6 +- pygeodyn/inout/priors.py | 23 +++--- pygeodyn/inout/reads.py | 9 ++- pygeodyn/pca.py | 1 + pygeodyn/release/releasing.py | 61 +++++++++------ pygeodyn/run.py | 2 +- pygeodyn/tests/strategies.py | 40 ++++++---- pygeodyn/tests/test_augkfalgo.py | 11 ++- pygeodyn/tests/test_common.py | 81 ++++++++++++++++---- pygeodyn/tests/test_config.py | 8 +- pygeodyn/tests/test_corestates.py | 110 +++++++++++++++++----------- pygeodyn/tests/test_initialise.py | 16 ++-- pygeodyn/tests/test_observations.py | 3 +- pygeodyn/tests/test_pca.py | 52 +++++++++---- pygeodyn/tests/test_run.py | 1 + pygeodyn/tests/test_utilities.py | 41 ++++++----- pygeodyn/tests/test_writes.py | 2 +- pygeodyn/tests/test_zonkfalgo.py | 9 ++- pygeodyn/utilities.py | 1 - pygeodyn/zonkf/__init__.py | 2 +- pygeodyn/zonkf/analyser.py | 1 - 31 files changed, 324 insertions(+), 185 deletions(-) diff --git a/pygeodyn/_version.py b/pygeodyn/_version.py index bd18148..f708a9b 100644 --- a/pygeodyn/_version.py +++ b/pygeodyn/_version.py @@ -1 +1 @@ -__version__ = '1.3.2' \ No newline at end of file +__version__ = "1.3.2" diff --git a/pygeodyn/augkf/__init__.py b/pygeodyn/augkf/__init__.py index 6f9c694..826608d 100644 --- a/pygeodyn/augkf/__init__.py +++ b/pygeodyn/augkf/__init__.py @@ -1,3 +1,3 @@ """ Subpackage implementing the AugKF algorithm as described in Barrois et al., 2017, 2018 and Gillet et al. 2019 -""" \ No newline at end of file +""" diff --git a/pygeodyn/augkf/algo.py b/pygeodyn/augkf/algo.py index 4afb912..ae4b0ed 100644 --- a/pygeodyn/augkf/algo.py +++ b/pygeodyn/augkf/algo.py @@ -1,12 +1,14 @@ import numpy as np import os import logging +import sys from .. import common, corestates as cs, pca from ..inout import reads from ..generic.algo import GenericAlgo from .forecaster import AugkfForecaster, AugkfForecasterPCA from .analyser import AugkfAnalyser, AugkfAnalyserPCA + def create_augkf_algo(config, nb_realisations): """ Factory function that returns the appropriate PCA-version AugKF algo @@ -127,7 +129,7 @@ class AugkfAlgo(GenericAlgo): Utype_for_AR, realisations_for_AR = self.choose_core_flow_for_ar(realisations_U, avg_priors, covariance_matrices) del realisations_U - #ensure realistations_U is deleted + # Ensure realistations_U is deleted locs = locals().items() for name, var in locs: if name == 'realistations_U': @@ -345,5 +347,4 @@ class AugkfAlgoPCA(AugkfAlgo): """ normed_PCA_operator = pca.NormedPCAOperator(self.config) - # return normed_PCA_operator, self.da_fit_transform(realisations_U, self.config.N_pca_u) return normed_PCA_operator, normed_PCA_operator.fit_transform(realisations_U) diff --git a/pygeodyn/augkf/analyser.py b/pygeodyn/augkf/analyser.py index 1b00c58..73d92c7 100644 --- a/pygeodyn/augkf/analyser.py +++ b/pygeodyn/augkf/analyser.py @@ -8,6 +8,7 @@ from ..inout import observations as observations_module from ..generic.computer import GenericComputer from ..corestates import with_core_state_of_dimensions + class AugkfAnalyser(GenericComputer): """ Class that handles the analyses of the Augmented State Kalman Filter algorithm with DIFF treated as a contribution to ER. diff --git a/pygeodyn/common.py b/pygeodyn/common.py index a9aabee..676bb66 100644 --- a/pygeodyn/common.py +++ b/pygeodyn/common.py @@ -118,8 +118,8 @@ def compute_dense_AR_matrices(times, X_quantity, sampling_dt): # Then compute dX = X(t+dt) - X(t) nb_samples, nb_coeffs = sampled_X.shape - X_t = sampled_X[0:-1] # X(t) - X_tpdt = sampled_X[1:] # X(t+dt) + X_t = sampled_X[0:-1] # X(t) + X_tpdt = sampled_X[1:] # X(t+dt) dX = X_tpdt - X_t # Compute covariance matrices P diff --git a/pygeodyn/corestates.py b/pygeodyn/corestates.py index f9bdfac..5bdffef 100644 --- a/pygeodyn/corestates.py +++ b/pygeodyn/corestates.py @@ -253,7 +253,7 @@ class CoreState: :return: Magnetic field and core flow data :rtype: np.ndarray """ - return np.concatenate((self._measures['MF'], self._measures['U']), axis=-1) + return np.concatenate((self._measures['MF'], self._measures['U']), axis=-1) @BU.setter def BU(self, field_and_flow): @@ -361,7 +361,7 @@ class CoreState: decimal_date = date_to_decimal(date, 2) date_indexes = (np.where(file_data['times'] == decimal_date))[0] - #print(file_data['times']) + # print(file_data['times']) if len(date_indexes) == 0: raise ValueError('Found no computed state in {} for date {}. Cannot initialise CoreState.'.format(file_path, decimal_date)) diff --git a/pygeodyn/generic/__init__.py b/pygeodyn/generic/__init__.py index 86b908b..e69de29 100644 --- a/pygeodyn/generic/__init__.py +++ b/pygeodyn/generic/__init__.py @@ -1,2 +0,0 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- \ No newline at end of file diff --git a/pygeodyn/generic/algo.py b/pygeodyn/generic/algo.py index c5ef3c5..0cb44fa 100644 --- a/pygeodyn/generic/algo.py +++ b/pygeodyn/generic/algo.py @@ -1,6 +1,3 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- - from ..inout.config import ComputationConfig diff --git a/pygeodyn/generic/computer.py b/pygeodyn/generic/computer.py index b4f160e..518c89b 100644 --- a/pygeodyn/generic/computer.py +++ b/pygeodyn/generic/computer.py @@ -64,4 +64,3 @@ class GenericComputer(object): # Return A(b) return np.transpose(AbT) - diff --git a/pygeodyn/inout/config.py b/pygeodyn/inout/config.py index 4590080..f0b382e 100644 --- a/pygeodyn/inout/config.py +++ b/pygeodyn/inout/config.py @@ -1,6 +1,5 @@ import numpy as np import logging -from pygeodyn import constants from pygeodyn.inout import reads import pygeodyn from pygeodyn.utilities import date_array_to_decimal @@ -47,6 +46,7 @@ def config_from_hdf5_file(hdf5_file): return ComputationConfig(config_dict=extracted_dict) + def find_obs_type(obs_dir): """ Deduce the observation type from the file extension in the directory of @@ -68,12 +68,13 @@ def find_obs_type(obs_dir): if extension == 'hdf5': return 'COVOBS_hdf5' elif extension == 'dat': - return 'COVOBS' + return 'COVOBS' elif extension == 'obs': return 'GO_VO' else: raise TypeError("obs_type could not be deduced, please set a value in configuration file") + class ComputationConfig(object): """ Defines the configuration of the computation, namely: diff --git a/pygeodyn/inout/observations.py b/pygeodyn/inout/observations.py index 46b54b6..50ffb41 100644 --- a/pygeodyn/inout/observations.py +++ b/pygeodyn/inout/observations.py @@ -1,4 +1,3 @@ -#-*- coding: utf-8 -*- """ Contains the functions building observations """ import os.path import numpy as np @@ -11,6 +10,7 @@ import glob from pygeodyn.inout import reads from pygeodyn import common, utilities + class Observation: """ Class storing the observation data, operator and errors in members: @@ -82,7 +82,7 @@ def build_go_vo_observations(cfg, nb_realisations, measure_type): measure_type, var_path)) # Take only the diagonal of the variance var_data = np.diag(np.loadtxt(var_path)) - assert len(var_data) % 3 == 0 # check that the format of the MF is [Br1, Br2, ..., BrN, Bth1, ..., BthN, Bph1, ..., BphN] + assert len(var_data) % 3 == 0 # check that the format of the MF is [Br1, Br2, ..., BrN, Bth1, ..., BthN, Bph1, ..., BphN] numberofVOs = len(var_data)//3 # Draw a seed for normal draw @@ -168,7 +168,7 @@ def build_covobs_observations(cfg, nb_realisations, measure_type): nb_coefs = cfg.Nb # Find files (sort to have reproducible order of realisations_files) - realisations_files = sorted(glob.glob(os.path.join(datadir,'real*_{}_int_coefs.dat'.format(measure_type.lower())))) + realisations_files = sorted(glob.glob(os.path.join(datadir, 'real*_{}_int_coefs.dat'.format(measure_type.lower())))) nb_real_files = len(realisations_files) if nb_real_files == 0: diff --git a/pygeodyn/inout/priors.py b/pygeodyn/inout/priors.py index f626dec..a61cd53 100644 --- a/pygeodyn/inout/priors.py +++ b/pygeodyn/inout/priors.py @@ -1,9 +1,8 @@ -#-*- coding: utf-8 -*- """ Contains the reading methods for prior types """ import h5py import os.path import numpy as np -from pygeodyn import common + def read_coupled_earth(data_directory, return_U=True): """ @@ -15,15 +14,15 @@ def read_coupled_earth(data_directory, return_U=True): :rtype: None, numpy.ndarray, numpy.ndarray, numpy.ndarray """ - if return_U: # load only U - U = np.genfromtxt(os.path.join(data_directory, 'RealU.dat')) + if return_U: # load only U + U = np.genfromtxt(os.path.join(data_directory, "RealU.dat")) # Need to change the sign convention for U prior if read from Coupled-Earth U = (-1) * U return U # Read the prior data , \sqrt{<(X-^2)>} and (X-) for all quantities - B = np.genfromtxt(os.path.join(data_directory, 'RealB.dat')) - E = np.genfromtxt(os.path.join(data_directory, 'RealER.dat')) + B = np.genfromtxt(os.path.join(data_directory, "RealB.dat")) + E = np.genfromtxt(os.path.join(data_directory, "RealER.dat")) # No time data is given for Coupled-Earth times = None @@ -41,12 +40,12 @@ def read_midpath(data_directory, return_U=True): :rtype: numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray """ if return_U: - with h5py.File(os.path.join(data_directory, 'Real.hdf5'), 'r') as hdf_file: - U = np.array(hdf_file['U']) + with h5py.File(os.path.join(data_directory, "Real.hdf5"), "r") as hdf_file: + U = np.array(hdf_file["U"]) return U - with h5py.File(os.path.join(data_directory, 'Real.hdf5'), 'r') as hdf_file: - times = np.array(hdf_file['times']) - B = np.array(hdf_file['MF']) - E = np.array(hdf_file['ER']) + with h5py.File(os.path.join(data_directory, "Real.hdf5"), "r") as hdf_file: + times = np.array(hdf_file["times"]) + B = np.array(hdf_file["MF"]) + E = np.array(hdf_file["ER"]) return times, B, E diff --git a/pygeodyn/inout/reads.py b/pygeodyn/inout/reads.py index 7349980..a59b5bc 100644 --- a/pygeodyn/inout/reads.py +++ b/pygeodyn/inout/reads.py @@ -7,6 +7,7 @@ import h5py from . import priors as priors_module from .. import utilities + def extract_realisations(prior_directory, prior_type, return_U=True): """ Return prior data arrays (nb_realisations x nb_coefs) by dynamically getting the reading function from the prior type. @@ -59,10 +60,10 @@ def parse_config_file(file_name=None): config = {} with open(file_name, "r") as handle: - for l in handle: - if l.strip().startswith("#") or l.strip() == '': + for line in handle: + if line.strip().startswith("#") or line.strip() == '': continue - parameter, p_type, p_val = l.split() + parameter, p_type, p_val = line.split() if p_type == "int": config[parameter] = int(p_val) elif p_type == "float": @@ -96,7 +97,7 @@ def parse_config_file(file_name=None): def read_prior(filename, max_cols=None, **kwargs): """ Uses genfromtxt to read the prior data. Returns the average :math:``, the RMS - :math:`\sqrt{<(X-)^2>}` and deviation :math:`X-` of the prior. + :math:`sqrt{<(X-)^2>}` and deviation :math:`X-` of the prior. :param filename: path of the prior file to read :type filename: str diff --git a/pygeodyn/pca.py b/pygeodyn/pca.py index be2794a..2ecd72f 100644 --- a/pygeodyn/pca.py +++ b/pygeodyn/pca.py @@ -4,6 +4,7 @@ from . import utilities import numpy as np import logging + class NormedPCAOperator: """ Object handling the transforms with normalisation of the PCA of U. diff --git a/pygeodyn/release/releasing.py b/pygeodyn/release/releasing.py index cc4a5a9..de00af3 100644 --- a/pygeodyn/release/releasing.py +++ b/pygeodyn/release/releasing.py @@ -1,10 +1,8 @@ -#!/usr/bin/env python3 -#-*- coding: utf-8 -*- import os.path import datetime -valid_release_types = ['major', 'minor', 'patch'] -file_extension = '.md' +valid_release_types = ["major", "minor", "patch"] +file_extension = ".md" def do_release(): @@ -17,20 +15,23 @@ def do_release(): def generate_change_log(version_number, changes, date=None): now = datetime.datetime.now() - with open(os.path.join(os.path.dirname(__file__), '../../CHANGELOG'+file_extension), 'r+') as changelog: + with open( + os.path.join(os.path.dirname(__file__), "../../CHANGELOG" + file_extension), + "r+", + ) as changelog: changelog_header = changelog.readline() old_changes = changelog.readlines() changelog.seek(0) # go back to the beginning of the file # Write new changes at the beginning if date is None: date = now.strftime("%Y-%m-%d") - header = '{} - {}\n'.format(version_number, date) - changelog.write(changelog_header+'\n') + header = "{} - {}\n".format(version_number, date) + changelog.write(changelog_header + "\n") changelog.write(header) - changelog.write('-'*(len(header)-1)+'\n') + changelog.write("-" * (len(header) - 1) + "\n") changelog.write(changes) - if not changes.endswith('\n'): - changelog.write('\n') + if not changes.endswith("\n"): + changelog.write("\n") for line in old_changes: changelog.write(line) changelog.close() @@ -39,44 +40,58 @@ def generate_change_log(version_number, changes, date=None): def generate_version_number(release_type): # Parse current version - with open(os.path.join(os.path.dirname(__file__), '../_version.py')) as version_file: + with open( + os.path.join(os.path.dirname(__file__), "../_version.py") + ) as version_file: version = version_file.read().strip().split("'")[1] - version_numbers = version.split('.') + version_numbers = version.split(".") # Find the release_type: 0=major, 1=minor, 2=patch try: i_release = valid_release_types.index(release_type) except ValueError: - raise TypeError('Found "{}" as release type which is not a valid release type !'.format(release_type)) + raise TypeError( + 'Found "{}" as release type which is not a valid release type !'.format( + release_type + ) + ) # Increment corresponding version number - version_numbers[i_release] = '{}'.format(int(version_numbers[i_release])+1) + version_numbers[i_release] = "{}".format(int(version_numbers[i_release]) + 1) # Set subordinate version numbers to 0 - for i_nb, nb in enumerate(version_numbers[i_release+1:]): - version_numbers[i_release+1+i_nb] = '0' + for i_nb, nb in enumerate(version_numbers[i_release + 1 :]): + version_numbers[i_release + 1 + i_nb] = "0" return ".".join(version_numbers) def parse_release_file(): - release_file_path = os.path.join(os.path.dirname(__file__), 'RELEASE'+file_extension) + release_file_path = os.path.join( + os.path.dirname(__file__), "RELEASE" + file_extension + ) if not os.path.isfile(release_file_path): - raise IOError('No RELEASE{} file was found !'.format(file_extension)) + raise IOError("No RELEASE{} file was found !".format(file_extension)) release_type = None with open(release_file_path) as release_file: for line in release_file: - if 'RELEASE_TYPE' in line: + if "RELEASE_TYPE" in line: release_type = line.strip().split()[-1].lower() break # Verify that we found a valid release_type if release_type not in valid_release_types: - raise TypeError('Found "{}" as release type which is not a valid release type !'.format(release_type)) + raise TypeError( + 'Found "{}" as release type which is not a valid release type !'.format( + release_type + ) + ) # Parse the blank line line = release_file.readline() if len(line.strip()) != 0: - raise IOError('No blank line were found after the line defining the release type !') + raise IOError( + "No blank line were found after the line defining the release type !" + ) # Parse the changes (assumed to be the rest of the file) changes = release_file.read() @@ -84,7 +99,9 @@ def parse_release_file(): def update_version_file(version_string): - with open(os.path.join(os.path.dirname(__file__), '../_version.py'), 'w') as version_file: + with open( + os.path.join(os.path.dirname(__file__), "../_version.py"), "w" + ) as version_file: version_file.write("__version__ = '{}'".format(version_string)) return 0 diff --git a/pygeodyn/run.py b/pygeodyn/run.py index 7016029..deddb72 100644 --- a/pygeodyn/run.py +++ b/pygeodyn/run.py @@ -200,7 +200,7 @@ def algorithm(output_path, computation_name, config_file, nb_models, seed=None, logging.debug("Waiting all process to finish forecast") comm.Barrier() - logging.debug("Sync done !".format(rank)) + logging.debug("Sync done !") # Recover all forecasts by summing all arrays measure by measure (this works as models in processes are only non zero if forecasted) # Note that Allreduce updates the array of each process with the result so no need to broadcast afterwards. diff --git a/pygeodyn/tests/strategies.py b/pygeodyn/tests/strategies.py index 7e1fd73..066825d 100644 --- a/pygeodyn/tests/strategies.py +++ b/pygeodyn/tests/strategies.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- import numpy as np -from hypothesis.strategies import * -from hypothesis.extra.numpy import * +from hypothesis.strategies import floats, integers, fixed_dictionaries +from hypothesis.extra.numpy import arrays from hypothesis.strategies import composite from pygeodyn.corestates import CoreState from pygeodyn.inout.config import ComputationConfig @@ -19,14 +19,17 @@ def finite_floats(draw, **kwargs): def square_matrices(draw, max_size, min_size=1, min_value=None, max_value=None): n = draw(integers(min_value=min_size, max_value=max_size)) float_strat = finite_floats(min_value=min_value, max_value=max_value) - sq_M = draw(arrays(elements=float_strat, shape=(n, n), dtype=np.float64, fill=float_strat)) + sq_M = draw( + arrays(elements=float_strat, shape=(n, n), dtype=np.float64, fill=float_strat) + ) return sq_M + @composite def singular_square_matrices(draw, *args, **kwargs): sq_M = draw(square_matrices(*args, **kwargs)) # Set a line to 0. to ensure singularity - sq_M[0] = 0. + sq_M[0] = 0.0 return sq_M @@ -34,7 +37,7 @@ def singular_square_matrices(draw, *args, **kwargs): def decimal_dates(draw): year = draw(integers(min_value=0, max_value=3000)) month = draw(integers(min_value=1, max_value=12)) - return year + month/12. + return year + month / 12.0 @composite @@ -43,24 +46,35 @@ def CoreStates(draw, max_degree=30): Lu = draw(integers(min_value=0, max_value=max_degree)) Lsv = draw(integers(min_value=0, max_value=max_degree)) - cs = CoreState({'MF': np.zeros(Lb*(Lb+2)), - 'U': np.zeros(2*Lu*(Lu+2)), - 'ER': np.zeros(Lsv*(Lsv+2)), - 'SV': np.zeros(Lsv*(Lsv+2))}) + cs = CoreState( + { + "MF": np.zeros(Lb * (Lb + 2)), + "U": np.zeros(2 * Lu * (Lu + 2)), + "ER": np.zeros(Lsv * (Lsv + 2)), + "SV": np.zeros(Lsv * (Lsv + 2)), + } + ) return cs @composite def working_ComputationConfig_dict(draw, fill=integers(min_value=1)): - working_dict = draw(fixed_dictionaries({k: fill for k in ComputationConfig.necessary_parameters})) + working_dict = draw( + fixed_dictionaries({k: fill for k in ComputationConfig.necessary_parameters}) + ) # Ensure dt analysis is a multiple of dt forecast - working_dict['dt_a'] = draw(integers(min_value=1))*working_dict['dt_f'] + working_dict["dt_a"] = draw(integers(min_value=1)) * working_dict["dt_f"] return working_dict def long_test(func): def func_wrapper(*args, **kwargs): - print('Running {}: it will take some time... (around one minute)'.format(func.__name__)) + print( + "Running {}: it will take some time... (around one minute)".format( + func.__name__ + ) + ) func(*args, **kwargs) + return func_wrapper diff --git a/pygeodyn/tests/test_augkfalgo.py b/pygeodyn/tests/test_augkfalgo.py index 2c589eb..e17693f 100644 --- a/pygeodyn/tests/test_augkfalgo.py +++ b/pygeodyn/tests/test_augkfalgo.py @@ -7,22 +7,25 @@ from pygeodyn.inout.config import ComputationConfig class TestAugkfAlgo(unittest.TestCase): def setUp(self): - conf_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.conf') + conf_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "test.conf" + ) self.config = ComputationConfig(config_file=conf_path) self.nb_realisations = 10 def test_init(self): # Non-existing observation file - self.config.obs_dir = '/path/to/nothing/gkdjgskdh' + self.config.obs_dir = "/path/to/nothing/gkdjgskdh" self.assertRaises(IOError, create_augkf_algo, self.config, self.nb_realisations) def test_functional_init(self): # Correct init - augkf_algo = create_augkf_algo(self.config, self.nb_realisations) + create_augkf_algo(self.config, self.nb_realisations) -if __name__ == '__main__': +if __name__ == "__main__": SUITE = unittest.TestLoader().loadTestsFromTestCase(TestAugkfAlgo) RES = unittest.TextTestRunner(verbosity=2).run(SUITE) import sys + sys.exit(max(len(RES.failures), len(RES.errors))) diff --git a/pygeodyn/tests/test_common.py b/pygeodyn/tests/test_common.py index d5df5f6..cedc3da 100644 --- a/pygeodyn/tests/test_common.py +++ b/pygeodyn/tests/test_common.py @@ -1,7 +1,7 @@ import unittest import numpy as np from scipy import linalg -from hypothesis import given, settings, HealthCheck +from hypothesis import given from pygeodyn.tests import strategies from pygeodyn import common @@ -14,10 +14,10 @@ class TestCommon(unittest.TestCase): def test_compute_direct_obs_operator(self): """ Checks that the shape of H is consistent with the input """ - positions = [r_earth, np.pi, 0.] + positions = [r_earth, np.pi, 0.0] max_degree = 10 H = common.compute_direct_obs_operator(positions, max_degree) - self.assertEqual(H.shape, (len(positions), max_degree*(max_degree+2))) + self.assertEqual(H.shape, (len(positions), max_degree * (max_degree + 2))) def test_compute_dense_AR_matrices(self): """ Test that compute dense AR matrices raises errors """ @@ -26,20 +26,36 @@ class TestCommon(unittest.TestCase): # # Build a X_qty with 100 times the same random vector X_qty = np.eye(100, 20) X_qty[:] = random_vec - sampling_dt = 5. + sampling_dt = 5.0 # Test sampling with no time data - self.assertRaises(ValueError, common.compute_dense_AR_matrices, None, X_qty, sampling_dt) + self.assertRaises( + ValueError, common.compute_dense_AR_matrices, None, X_qty, sampling_dt + ) # Test wrong dimensions for X_quantity wrong_X_qty = X_qty.reshape((2000)) - self.assertRaises(AssertionError, common.compute_dense_AR_matrices, times, wrong_X_qty, sampling_dt) + self.assertRaises( + AssertionError, + common.compute_dense_AR_matrices, + times, + wrong_X_qty, + sampling_dt, + ) wrong_X_qty = X_qty.reshape((20, 100)) - self.assertRaises(ValueError, common.compute_dense_AR_matrices, times, wrong_X_qty, sampling_dt) + self.assertRaises( + ValueError, + common.compute_dense_AR_matrices, + times, + wrong_X_qty, + sampling_dt, + ) # Test NaN for sampling_dt - self.assertRaises(AssertionError, common.compute_dense_AR_matrices, times, X_qty, 'NaN') + self.assertRaises( + AssertionError, common.compute_dense_AR_matrices, times, X_qty, "NaN" + ) def test_functional_Kalman_matrix_computation(self): """ Test that the function returns the appropriate matrix result """ @@ -64,20 +80,52 @@ class TestCommon(unittest.TestCase): qty = np.random.rand(N) avg_qty = np.random.rand(N) Cholesky = np.tril((N, N)) - time_step = 2. + time_step = 2.0 drift_matrix = np.identity(N) wrong_qty = qty.reshape((4, 25)) - self.assertRaises(ValueError, common.ar1_process, wrong_qty, avg_qty, Cholesky, time_step, drift_matrix) + self.assertRaises( + ValueError, + common.ar1_process, + wrong_qty, + avg_qty, + Cholesky, + time_step, + drift_matrix, + ) wrong_avg_qty = avg_qty.reshape((5, 20)) - self.assertRaises(ValueError, common.ar1_process, qty, wrong_avg_qty, Cholesky, time_step, drift_matrix) + self.assertRaises( + ValueError, + common.ar1_process, + qty, + wrong_avg_qty, + Cholesky, + time_step, + drift_matrix, + ) upper_Cholesky = np.transpose(Cholesky) - self.assertRaises(ValueError, common.ar1_process, qty, avg_qty, upper_Cholesky, time_step, drift_matrix) + self.assertRaises( + ValueError, + common.ar1_process, + qty, + avg_qty, + upper_Cholesky, + time_step, + drift_matrix, + ) wrong_drift_matrix = drift_matrix.reshape(25, 400) - self.assertRaises(ValueError, common.ar1_process, qty, avg_qty, Cholesky, time_step, wrong_drift_matrix) + self.assertRaises( + ValueError, + common.ar1_process, + qty, + avg_qty, + Cholesky, + time_step, + wrong_drift_matrix, + ) @given(strategies.singular_square_matrices(max_size=100)) def test_Cholesky_inversion(self, non_invertible): @@ -87,7 +135,9 @@ class TestCommon(unittest.TestCase): # Check that det = 0 self.assertEqual(linalg.det(non_invertible), 0) # Numpy will also throw a LinAlgError if the input is not definite positive - self.assertRaises(np.linalg.LinAlgError, common.mat_inv_using_Cholesky, non_invertible) + self.assertRaises( + np.linalg.LinAlgError, common.mat_inv_using_Cholesky, non_invertible + ) def test_functional_Cholesky_inversion(self): """ Test that matrix inversion using Cholesky gives the same result as scipy.linalg.inv """ @@ -115,8 +165,9 @@ class TestCommon(unittest.TestCase): self.assertTrue(result_test[0] or result_test[1]) -if __name__ == '__main__': +if __name__ == "__main__": SUITE = unittest.TestLoader().loadTestsFromTestCase(TestCommon) RES = unittest.TextTestRunner(verbosity=2).run(SUITE) import sys + sys.exit(max(len(RES.failures), len(RES.errors))) diff --git a/pygeodyn/tests/test_config.py b/pygeodyn/tests/test_config.py index b2cb20b..0f149da 100644 --- a/pygeodyn/tests/test_config.py +++ b/pygeodyn/tests/test_config.py @@ -4,8 +4,8 @@ import pygeodyn.run import h5py import os from hypothesis import given -from pygeodyn.tests import strategies -from pygeodyn.tests.strategies import long_test +from hypothesis import strategies +from pygeodyn.tests.strategies import working_ComputationConfig_dict, long_test class TestComputationConfig(unittest.TestCase): @@ -38,7 +38,7 @@ class TestComputationConfig(unittest.TestCase): ) @given( - strategies.working_ComputationConfig_dict().filter( + working_ComputationConfig_dict().filter( lambda d: abs(d["t_end"] - d["t_start"]) / d["dt_f"] < 100 ) ) @@ -116,5 +116,5 @@ if __name__ == "__main__": SUITE = unittest.TestLoader().loadTestsFromTestCase(TestComputationConfig) RES = unittest.TextTestRunner(verbosity=2).run(SUITE) import sys - sys.exit(max(len(RES.failures), len(RES.errors))) + sys.exit(max(len(RES.failures), len(RES.errors))) diff --git a/pygeodyn/tests/test_corestates.py b/pygeodyn/tests/test_corestates.py index a089136..500ad0c 100644 --- a/pygeodyn/tests/test_corestates.py +++ b/pygeodyn/tests/test_corestates.py @@ -8,8 +8,8 @@ from pygeodyn.utilities import decimal_to_date from pygeodyn.corestates import CoreState, coef_print import numpy as np import os.path -from pygeodyn.tests import strategies -from hypothesis import given, assume +from hypothesis import given, assume, strategies +from pygeodyn.tests.strategies import CoreStates, finite_floats GH_MEASURE_SIZE = 224 TS_MEASURE_SIZE = 720 @@ -20,12 +20,16 @@ class TestCoreState(unittest.TestCase): def setUp(self): # Build a 1D full CoreState - self.full_cs = CoreState({'MF': np.zeros(GH_MEASURE_SIZE), - 'U': np.zeros(TS_MEASURE_SIZE), - 'SV': np.zeros(GH_MEASURE_SIZE), - 'ER': np.zeros(GH_MEASURE_SIZE)}) - - @given(strategies.CoreStates(), strategies.integers(), strategies.floats()) + self.full_cs = CoreState( + { + "MF": np.zeros(GH_MEASURE_SIZE), + "U": np.zeros(TS_MEASURE_SIZE), + "SV": np.zeros(GH_MEASURE_SIZE), + "ER": np.zeros(GH_MEASURE_SIZE), + } + ) + + @given(CoreStates(), strategies.integers(), strategies.floats()) def test_coef_print(self, core_state, int_index, not_int_index): """ Test that coef_print throws an error if not given a CoreState or an int""" not_core_state_array = np.linspace(0, 10, 20) @@ -41,9 +45,11 @@ class TestCoreState(unittest.TestCase): # Test error if given a negative int self.assertRaises(AssertionError, coef_print, core_state, int_index) else: - if (int_index >= len(core_state.B) or int_index >= len(core_state.U)) or int_index >= len(core_state.SV): + if ( + int_index >= len(core_state.B) or int_index >= len(core_state.U) + ) or int_index >= len(core_state.SV): # Test return empty string if out of bounds - self.assertEqual(coef_print(core_state, int_index), '') + self.assertEqual(coef_print(core_state, int_index), "") else: # Test ok result = coef_print(core_state, int_index) @@ -55,22 +61,22 @@ class TestCoreState(unittest.TestCase): """ cs = CoreState() # Test with a dim != Lb*(Lb+2) - wrong_measure_data = np.zeros(Lb*(Lb+2) + 1) - self.assertRaises(ValueError, cs.addMeasure, 'MF', wrong_measure_data) + wrong_measure_data = np.zeros(Lb * (Lb + 2) + 1) + self.assertRaises(ValueError, cs.addMeasure, "MF", wrong_measure_data) # Test with dim = Lb*(Lb+2) - right_measure_data = np.zeros(Lb*(Lb+2)) - cs.addMeasure('MF', right_measure_data) - self.assertIn('MF', cs.measures) + right_measure_data = np.zeros(Lb * (Lb + 2)) + cs.addMeasure("MF", right_measure_data) + self.assertIn("MF", cs.measures) self.assertEqual(Lb, cs.Lb) @given(strategies.integers(min_value=0, max_value=1000)) def test_addMeasureU(self, Lu): cs = CoreState() # U dim = 2*Lu*(Lu+2) - right_measure_data = np.zeros(2*Lu*(Lu+2)) - cs.addMeasure('U', right_measure_data) - self.assertIn('U', cs.measures) + right_measure_data = np.zeros(2 * Lu * (Lu + 2)) + cs.addMeasure("U", right_measure_data) + self.assertIn("U", cs.measures) self.assertEqual(Lu, cs.Lu) @given(strategies.integers(min_value=-1000, max_value=1000)) @@ -78,7 +84,7 @@ class TestCoreState(unittest.TestCase): cs = CoreState() # Any data: need to set max_degree even if it has no meaning any_data = np.zeros(158) - measure_name = 'ANY' + measure_name = "ANY" cs.addMeasure(measure_name, any_data, Lany) self.assertIn(measure_name, cs.measures) self.assertEqual(cs._getMaxDegree(measure_name), Lany) @@ -86,15 +92,19 @@ class TestCoreState(unittest.TestCase): def test_getMaxDegree(self): cs = CoreState() # Test getMaxDegree gives 0 for a measure not set - not_a_measure = 'YAR' + not_a_measure = "YAR" self.assertNotIn(not_a_measure, cs.measures) self.assertEqual(cs._getMaxDegree(not_a_measure), 0) - @given(strategies.integers(min_value=0, max_value=GH_MEASURE_SIZE-1), strategies.finite_floats()) + @given( + strategies.integers(min_value=0, max_value=GH_MEASURE_SIZE - 1), finite_floats() + ) def test_get_set_item(self, index, value): # Test dict-like behaviour of get_item for measure in self.full_cs.keys(): - np.testing.assert_equal(self.full_cs[measure], self.full_cs.getMeasure(measure)) + np.testing.assert_equal( + self.full_cs[measure], self.full_cs.getMeasure(measure) + ) # Test get_item & set_item truncate = 10 @@ -102,16 +112,21 @@ class TestCoreState(unittest.TestCase): self.assertEqual(truncated_cs.measures, self.full_cs.measures) for measure in truncated_cs.measures: self.assertEqual(len(truncated_cs.getMeasure(measure)), truncate) - np.testing.assert_equal(truncated_cs.getMeasure(measure), - self.full_cs.getMeasure(measure)[:10]) + np.testing.assert_equal( + truncated_cs.getMeasure(measure), self.full_cs.getMeasure(measure)[:10] + ) # Test copy copied_cs = self.full_cs.copy() self.assertEqual(copied_cs.measures, self.full_cs.measures) for measure in self.full_cs.measures: - np.testing.assert_equal(copied_cs.getMeasure(measure), self.full_cs.getMeasure(measure)) + np.testing.assert_equal( + copied_cs.getMeasure(measure), self.full_cs.getMeasure(measure) + ) # Test set_item with index - assume(value != 0.) # Exclude the value zero to be able to test the fact that full_cs is not updated + assume( + value != 0.0 + ) # Exclude the value zero to be able to test the fact that full_cs is not updated copied_cs[index] = value for measure in self.full_cs.measures: # Test that item was properly set in the copy @@ -121,32 +136,43 @@ class TestCoreState(unittest.TestCase): def test_initialisation_from_file(self): # Read the data that will be used for initialisation - file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'benchmarks', 'test_run_augkf.hdf5') + file_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "benchmarks", + "test_run_augkf.hdf5", + ) file_data = read_computed_states_hdf5(file_path) - Nb = file_data['MF'].shape[-1] - Nsv = file_data['SV'].shape[-1] - Nu2 = file_data['U'].shape[-1] + Nb = file_data["MF"].shape[-1] + Nsv = file_data["SV"].shape[-1] + Nu2 = file_data["U"].shape[-1] # Take a random date for initialisation - i_date = np.random.randint(0, len(file_data['times'])) - date = decimal_to_date(file_data['times'][i_date]) + i_date = np.random.randint(0, len(file_data["times"])) + date = decimal_to_date(file_data["times"][i_date]) nb_reals = 2 # Build a 3D full CoreState - full_cs = CoreState({'MF': np.zeros((nb_reals, 1, Nb)), - 'U': np.zeros((nb_reals, 1, Nu2)), - 'SV': np.zeros((nb_reals, 1, Nsv)), - 'ER': np.zeros((nb_reals, 1, Nsv))}) + full_cs = CoreState( + { + "MF": np.zeros((nb_reals, 1, Nb)), + "U": np.zeros((nb_reals, 1, Nu2)), + "SV": np.zeros((nb_reals, 1, Nsv)), + "ER": np.zeros((nb_reals, 1, Nsv)), + } + ) # Initialise it from the CoreState at date from file full_cs.initialise_from_file(file_path, date) # Check that the initialisation worked for measure in full_cs.keys(): - np.testing.assert_equal(full_cs[measure][:, 0], file_data[measure][:nb_reals, i_date]) + np.testing.assert_equal( + full_cs[measure][:, 0], file_data[measure][:nb_reals, i_date] + ) + +if __name__ == "__main__": + SUITE = unittest.TestLoader().loadTestsFromTestCase(TestCoreState) + RES = unittest.TextTestRunner(verbosity=2).run(SUITE) + import sys -if __name__ == '__main__': - SUITE = unittest.TestLoader().loadTestsFromTestCase(TestCoreState) - RES = unittest.TextTestRunner(verbosity=2).run(SUITE) - import sys - sys.exit(max(len(RES.failures), len(RES.errors))) + sys.exit(max(len(RES.failures), len(RES.errors))) diff --git a/pygeodyn/tests/test_initialise.py b/pygeodyn/tests/test_initialise.py index a27d883..9166d0e 100644 --- a/pygeodyn/tests/test_initialise.py +++ b/pygeodyn/tests/test_initialise.py @@ -1,19 +1,21 @@ import unittest import pygeodyn.inout.config as config_m import os -from pygeodyn.augkf import algo class TestAlgoInit(unittest.TestCase): """ Test the Augkf algorithm initialisation. TODO... """ def setUp(self): - conf_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.conf') + conf_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "test.conf" + ) self.cfg = config_m.ComputationConfig(config_file=conf_path) -if __name__ == '__main__': - SUITE = unittest.TestLoader().loadTestsFromTestCase(TestAlgoInit) - RES = unittest.TextTestRunner(verbosity=2).run(SUITE) - import sys - sys.exit(max(len(RES.failures), len(RES.errors))) +if __name__ == "__main__": + SUITE = unittest.TestLoader().loadTestsFromTestCase(TestAlgoInit) + RES = unittest.TextTestRunner(verbosity=2).run(SUITE) + import sys + + sys.exit(max(len(RES.failures), len(RES.errors))) diff --git a/pygeodyn/tests/test_observations.py b/pygeodyn/tests/test_observations.py index 4b654b7..f29302f 100644 --- a/pygeodyn/tests/test_observations.py +++ b/pygeodyn/tests/test_observations.py @@ -1,7 +1,6 @@ import unittest from pygeodyn.inout import observations -from pygeodyn.tests import strategies -from hypothesis import given +from hypothesis import given, strategies import numpy as np diff --git a/pygeodyn/tests/test_pca.py b/pygeodyn/tests/test_pca.py index 11a59ad..b6ffbd2 100644 --- a/pygeodyn/tests/test_pca.py +++ b/pygeodyn/tests/test_pca.py @@ -5,20 +5,26 @@ from pygeodyn.inout.reads import extract_realisations from pygeodyn import pca import numpy as np -from pygeodyn.tests.strategies import long_test - class TestPca(unittest.TestCase): """ Test the pca module """ def setUp(self): - conf_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_dense.conf') + conf_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "test_dense.conf" + ) self.cfg = config_m.ComputationConfig(config_file=conf_path) # Extract reals of U real_U = extract_realisations(self.cfg.prior_dir, self.cfg.prior_type) # Take a subset of reals to avoid MemoryErrors real_Nu = real_U.shape[1] // 2 - self.real_U = np.concatenate((real_U[:5000, :self.cfg.Nu], real_U[:5000, real_Nu:real_Nu + self.cfg.Nu]), axis=1) + self.real_U = np.concatenate( + ( + real_U[:5000, : self.cfg.Nu], + real_U[:5000, real_Nu : real_Nu + self.cfg.Nu], + ), + axis=1, + ) def testPCAOperatorWithoutNorm(self): """ @@ -32,10 +38,15 @@ class TestPca(unittest.TestCase): # Try to recover U with: # Regular PCA inverse transform (sklearn) - recovered_U_sklearn = custom_pca_operator.sklearn_operator.inverse_transform(U_pca) + recovered_U_sklearn = custom_pca_operator.sklearn_operator.inverse_transform( + U_pca + ) # Manual inverse transform using U = S_u * U_pca + U0 - recovered_U_manual = np.transpose(np.matmul(custom_pca_operator.S_u, np.transpose(U_pca))) + custom_pca_operator.U0 + recovered_U_manual = ( + np.transpose(np.matmul(custom_pca_operator.S_u, np.transpose(U_pca))) + + custom_pca_operator.U0 + ) # Semi-manual (PCAOperator implements manual inverse transform) recovered_U_semi_manual = custom_pca_operator.inverse_transform(U_pca) @@ -44,12 +55,18 @@ class TestPca(unittest.TestCase): np.testing.assert_equal(recovered_U_manual, recovered_U_semi_manual) # Test that inverse_transform followed by transform gives the same result - recovered_U_pca = custom_pca_operator.transform(custom_pca_operator.inverse_transform(U_pca)) + recovered_U_pca = custom_pca_operator.transform( + custom_pca_operator.inverse_transform(U_pca) + ) np.testing.assert_almost_equal(recovered_U_pca, U_pca) # Test that transform followed by inverse_transform gives the same result - recovered_U = custom_pca_operator.inverse_transform(custom_pca_operator.transform(self.real_U)) - recovered_U2 = custom_pca_operator.sklearn_operator.inverse_transform(custom_pca_operator.sklearn_operator.transform(self.real_U)) + recovered_U = custom_pca_operator.inverse_transform( + custom_pca_operator.transform(self.real_U) + ) + recovered_U2 = custom_pca_operator.sklearn_operator.inverse_transform( + custom_pca_operator.sklearn_operator.transform(self.real_U) + ) np.testing.assert_almost_equal(recovered_U, recovered_U2) def testPCAOperatorWithNorm(self): @@ -57,18 +74,21 @@ class TestPca(unittest.TestCase): Function tests of the transform and inverse transform method of NormedPCAOperator """ # Ensure 'energy' normalisation - self.cfg.pca_norm = 'energy' + self.cfg.pca_norm = "energy" # Perform the PCA custom_pca_operator = pca.NormedPCAOperator(self.cfg) U_pca = custom_pca_operator.fit_transform(self.real_U) # Test that inverse_transform followed by transform gives the same result - recovered_U_pca = custom_pca_operator.transform(custom_pca_operator.inverse_transform(U_pca)) + recovered_U_pca = custom_pca_operator.transform( + custom_pca_operator.inverse_transform(U_pca) + ) np.testing.assert_almost_equal(recovered_U_pca, U_pca) -if __name__ == '__main__': - SUITE = unittest.TestLoader().loadTestsFromTestCase(TestPca) - RES = unittest.TextTestRunner(verbosity=2).run(SUITE) - import sys - sys.exit(max(len(RES.failures), len(RES.errors))) +if __name__ == "__main__": + SUITE = unittest.TestLoader().loadTestsFromTestCase(TestPca) + RES = unittest.TextTestRunner(verbosity=2).run(SUITE) + import sys + + sys.exit(max(len(RES.failures), len(RES.errors))) diff --git a/pygeodyn/tests/test_run.py b/pygeodyn/tests/test_run.py index ceb7ba7..53d03aa 100644 --- a/pygeodyn/tests/test_run.py +++ b/pygeodyn/tests/test_run.py @@ -6,6 +6,7 @@ from pygeodyn.corestates import CoreState import numpy as np from pygeodyn.tests.strategies import long_test + class TestRunAlgos(unittest.TestCase): """ Tests if all algos can be run properly on a short time span and with few realisations diff --git a/pygeodyn/tests/test_utilities.py b/pygeodyn/tests/test_utilities.py index ec857c0..2ea1d19 100644 --- a/pygeodyn/tests/test_utilities.py +++ b/pygeodyn/tests/test_utilities.py @@ -1,35 +1,41 @@ import unittest import numpy as np from pygeodyn import utilities -from hypothesis import given, note -from pygeodyn.tests import strategies +from hypothesis import given, strategies +from pygeodyn.tests.strategies import decimal_dates MAX_DEGREE = 50 class TestUtilities(unittest.TestCase): - @given(strategies.decimal_dates()) + @given(decimal_dates()) def test_decimal_from_to_date(self, date): converted_date = utilities.decimal_to_date(date) - year, month = str(converted_date).split('-') - self.assertEqual(int(year) + (int(month)) / 12., date) + year, month = str(converted_date).split("-") + self.assertEqual(int(year) + (int(month)) / 12.0, date) self.assertEqual(utilities.date_to_decimal(converted_date), date) - @given(strategies.integers(max_value=MAX_DEGREE*(MAX_DEGREE+2))) # Works up to 10^6 + @given( + strategies.integers(max_value=MAX_DEGREE * (MAX_DEGREE + 2)) + ) # Works up to 10^6 def test_get_degree_order(self, k): if k < 0: self.assertRaises(AssertionError, utilities.get_degree_order, k) else: l, m, coef_type = utilities.get_degree_order(k) - if coef_type == 'g': + if coef_type == "g": if m == 0: - self.assertTrue(k == l**2 - 1) + self.assertTrue(k == l ** 2 - 1) else: - self.assertTrue(k == l**2 + 2*m - 2) - elif coef_type == 'h': - self.assertTrue(k == l**2 + 2*m - 1) + self.assertTrue(k == l ** 2 + 2 * m - 2) + elif coef_type == "h": + self.assertTrue(k == l ** 2 + 2 * m - 1) else: - raise ValueError('Coef_type is equal to {} whereas "g" or "h" was expected'.format(coef_type)) + raise ValueError( + 'Coef_type is equal to {} whereas "g" or "h" was expected'.format( + coef_type + ) + ) @given(strategies.integers(min_value=0, max_value=MAX_DEGREE)) def test_zonal_index_generator(self, Lu): @@ -45,12 +51,14 @@ class TestUtilities(unittest.TestCase): non_zonal_mask = utilities.non_zonal_mask(Lu) # Test shapes - Nu2 = 2*Lu*(Lu+2) + Nu2 = 2 * Lu * (Lu + 2) self.assertEqual(len(zonal_mask), Nu2) self.assertEqual(len(non_zonal_mask), Nu2) # Functional tests - self.assertTrue(np.all(zonal_mask[[i_z for i_z in utilities.zonal_indexes(Lu)]])) + self.assertTrue( + np.all(zonal_mask[[i_z for i_z in utilities.zonal_indexes(Lu)]]) + ) np.testing.assert_equal(non_zonal_mask, np.logical_not(zonal_mask)) @given(strategies.integers(min_value=1, max_value=MAX_DEGREE)) @@ -71,7 +79,7 @@ class TestUtilities(unittest.TestCase): last_l, last_m = 1, 0 # Test that all other members are non zonal and in increasing order (only for tc, ts) - for i in range(Lu, Nu2//2): + for i in range(Lu, Nu2 // 2): l, m, coef_type = utilities.get_degree_order(znz_U[i]) self.assertNotEqual(m, 0) self.assertGreater(m, last_m) @@ -84,8 +92,7 @@ class TestUtilities(unittest.TestCase): np.testing.assert_equal(new_U, spectral_U) - -if __name__ == '__main__': +if __name__ == "__main__": SUITE = unittest.TestLoader().loadTestsFromTestCase(TestUtilities) RES = unittest.TextTestRunner(verbosity=2).run(SUITE) import sys diff --git a/pygeodyn/tests/test_writes.py b/pygeodyn/tests/test_writes.py index 4805c2a..0dae0d2 100644 --- a/pygeodyn/tests/test_writes.py +++ b/pygeodyn/tests/test_writes.py @@ -20,7 +20,7 @@ class TestWrites(unittest.TestCase): if not os.path.exists(valid_path): os.mkdir(valid_path) self.assertTrue(os.path.exists(valid_path)) - result_save = writes.saveReadme(valid_path, config=self.config, algo_name='test', nb_realisations=10, elapsed_time=0, parallel=False) + result_save = writes.saveReadme(valid_path, config=self.config, algo_name='test', nb_realisations=10, elapsed_time=0, parallel=False) self.assertEqual(0, result_save) def test_saveHandlers(self): diff --git a/pygeodyn/tests/test_zonkfalgo.py b/pygeodyn/tests/test_zonkfalgo.py index 5b53240..1f71c13 100644 --- a/pygeodyn/tests/test_zonkfalgo.py +++ b/pygeodyn/tests/test_zonkfalgo.py @@ -7,15 +7,18 @@ import pygeodyn.inout.config as config_m class TestZonkfAlgo(unittest.TestCase): def setUp(self): - conf_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_dense.conf') + conf_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "test_dense.conf" + ) self.config = config_m.ComputationConfig(config_file=conf_path) def test_init(self): - zonkf_algo = create_zonkf_algo(self.config, nb_realisations=10) + create_zonkf_algo(self.config, nb_realisations=10) -if __name__ == '__main__': +if __name__ == "__main__": SUITE = unittest.TestLoader().loadTestsFromTestCase(TestZonkfAlgo) RES = unittest.TextTestRunner(verbosity=2).run(SUITE) import sys + sys.exit(max(len(RES.failures), len(RES.errors))) diff --git a/pygeodyn/utilities.py b/pygeodyn/utilities.py index 845752a..fbeeb45 100644 --- a/pygeodyn/utilities.py +++ b/pygeodyn/utilities.py @@ -1,4 +1,3 @@ -#-*- coding: utf-8 -*- """ Utility functions """ diff --git a/pygeodyn/zonkf/__init__.py b/pygeodyn/zonkf/__init__.py index 055e66b..57e9282 100644 --- a/pygeodyn/zonkf/__init__.py +++ b/pygeodyn/zonkf/__init__.py @@ -1,3 +1,3 @@ """ Subpackage implementing the Zonal AugKF algorithm -""" \ No newline at end of file +""" diff --git a/pygeodyn/zonkf/analyser.py b/pygeodyn/zonkf/analyser.py index 9ca49cc..f685216 100644 --- a/pygeodyn/zonkf/analyser.py +++ b/pygeodyn/zonkf/analyser.py @@ -335,4 +335,3 @@ class ZonkfAnalyserPCA(ZonkfAnalyser): self.algo.covariance_matrices["zu,pca_u"].T, ) ) - -- GitLab