From c4b2ae6bf654a8657bb311685755e0f6cf39959a Mon Sep 17 00:00:00 2001 From: 1313e Date: Thu, 17 Dec 2020 12:50:25 +1100 Subject: [PATCH] Fixed a v3 compatibility bug where the attributes were not retrieved from the proper place in the HDF5-file. Modified the generate_test_hickle.py file to now create hickled files that caused this issue before. --- hickle/__version__.py | 2 +- hickle/hickle.py | 8 ++++---- .../tests/legacy_hkls/generate_test_hickle.py | 2 +- .../{hickle_3_4_8.hkl => hickle_3_4_9.hkl} | Bin 16504 -> 17656 bytes hickle/tests/test_legacy_load.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename hickle/tests/legacy_hkls/{hickle_3_4_8.hkl => hickle_3_4_9.hkl} (68%) diff --git a/hickle/__version__.py b/hickle/__version__.py index 573afdf6..1ccd369f 100644 --- a/hickle/__version__.py +++ b/hickle/__version__.py @@ -10,4 +10,4 @@ # %% VERSIONS # Default/Latest/Current version -__version__ = '4.0.2' +__version__ = '4.0.3' diff --git a/hickle/hickle.py b/hickle/hickle.py index 5b13d1bf..e9aeee8b 100644 --- a/hickle/hickle.py +++ b/hickle/hickle.py @@ -508,23 +508,23 @@ def load(file_obj, path='/', safe=True): # Try to read the provided file_obj as a hickle file try: h5f, path, close_flag = file_opener(file_obj, path, 'r') - h_root_group = h5f.get(path) + h_root_group = h5f.get(path) # Solely used by v4 # Define attributes h_root_group must have v3_attrs = ['CLASS', 'VERSION', 'PYTHON_VERSION'] v4_attrs = ['HICKLE_VERSION', 'HICKLE_PYTHON_VERSION'] # Check if the proper attributes for v3 loading are available - if all(map(h_root_group.attrs.get, v3_attrs)): + if all(map(h5f.attrs.get, v3_attrs)): # Check if group attribute 'CLASS' has value 'hickle - if(h_root_group.attrs['CLASS'] != b'hickle'): # pragma: no cover + if(h5f.attrs['CLASS'] != b'hickle'): # pragma: no cover # If not, raise error raise AttributeError("HDF5-file attribute 'CLASS' does not " "have value 'hickle'!") # Obtain version with which the file was made try: - major_version = int(h_root_group.attrs['VERSION'][0]) + major_version = int(h5f.attrs['VERSION'][0]) # If this cannot be done, then this is not a v3 file except Exception: # pragma: no cover diff --git a/hickle/tests/legacy_hkls/generate_test_hickle.py b/hickle/tests/legacy_hkls/generate_test_hickle.py index 4d58afd7..e8b8f596 100644 --- a/hickle/tests/legacy_hkls/generate_test_hickle.py +++ b/hickle/tests/legacy_hkls/generate_test_hickle.py @@ -23,5 +23,5 @@ } print("Dumping %s..." % fn_out) -hkl.dump(dd, fn_out) +hkl.dump(dd, fn_out, path='test') diff --git a/hickle/tests/legacy_hkls/hickle_3_4_8.hkl b/hickle/tests/legacy_hkls/hickle_3_4_9.hkl similarity index 68% rename from hickle/tests/legacy_hkls/hickle_3_4_8.hkl rename to hickle/tests/legacy_hkls/hickle_3_4_9.hkl index 976ced42ba35dd494bcd0dc791307c37aff46fa8..4795c4a1c76512d8b39344239893c49a4510ebd1 100644 GIT binary patch delta 768 zcmY+Bzfaph6vutfX`Ey-AR$w5?8Z^B3QB_c5tjfp&=FOD)T$F?fQk-PrIbnxQR_}k zJCVG9096%=GR4XO6GDg~W6Fe>7#KPtrc~-s=k8LMTb|$3*Pnae?{!?#`AYUp=sfct zA3}I{`~9vU;7Mw|X^K09>|rI8@ftF~Wf<$J*Jw-qSd2f!8!?IdQUZ&i!KkSU^tkv_ z()!AeSl433r~Q_eho1PI$R`hYolNJ_Q_UBVfj)3_EG6f>(=$@d$uWlu%ENdO-l!@v zso~Iw<{c>nuM<(6P{(jfTB&ArD2#daL4aSHzug9256how=us6ey4jxaLbkk1$|4rNT6n&7V=pcvYx12)YgMmM6J>toHjb(~*7bz-;o}oTd6c13v^Mw)|EOkkL0nGBSYybcN delta 700 zcmY+CF-s#+5Xaw}M6(+dBZm?%x9rO*aqkGpGlpb6j4o;+7NUicN;?T$bzL|PPQ*g7 zF*l9aU2`1a3YTpx+Gzd7PA(C5i9EOcxR=^O9(#)m#twE0No>V58sLwtskbee z6yRfQam)#wh$`z-b~;zeIsS(BW*CU+HAevsQW(!~q018QZ(}lxs^n!RKWYlAsrVV* zr_68alGHLX{9Hx2^p91%J4W}Me3bS%uciFPK z#f$VE5F3A6Eb{5b#4D@uJ(+-x;dv#BCs79H6H==cYTb$VbopQM8U@|Pea@m`={CB? zJG|sYAQ}9}H{sW~U|c&c1_f8w)NJ9p!GyDn!1V;as