Skip to content

Commit

Permalink
lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubelMozumder committed Jan 23, 2025
1 parent eedb0e9 commit e6eb16e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 29 deletions.
18 changes: 6 additions & 12 deletions src/pynxtools/dataconverter/readers/example/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,16 @@ def read(

# virtual datasets slicing
my_path = str(f"{os.path.dirname(__file__)}/../../../data/")
template[("/ENTRY[entry]" "/test_virtual" "_dataset/sliced" "_dataset")] = {
"link": (
f"{my_path}/xarray_saved_small_" "calibration.h5:/binned/BinnedData"
),
template[("/ENTRY[entry]/test_virtual_dataset/sliced_dataset")] = {
"link": (f"{my_path}/xarray_saved_small_calibration.h5:/binned/BinnedData"),
"shape": np.index_exp[:, 1, :, :],
}
template[("/ENTRY[entry]" "/test_virtual" "_dataset/slic" "ed_dataset2")] = {
"link": (
f"{my_path}/xarray_saved_small" "_calibration.h5:/binned/BinnedData"
),
template[("/ENTRY[entry]/test_virtual_dataset/sliced_dataset2")] = {
"link": (f"{my_path}/xarray_saved_small_calibration.h5:/binned/BinnedData"),
"shape": np.index_exp[:, :, :, 1],
}
template[("/ENTRY[entry]" "/test_virtual" "_dataset/slic" "ed_dataset3")] = {
"link": (
f"{my_path}/xarray_saved_small" "_calibration.h5:/binned/BinnedData"
),
template[("/ENTRY[entry]/test_virtual_dataset/sliced_dataset3")] = {
"link": (f"{my_path}/xarray_saved_small_calibration.h5:/binned/BinnedData"),
"shape": np.index_exp[:, :, :, 2:4],
}

Expand Down
2 changes: 1 addition & 1 deletion src/pynxtools/dataconverter/readers/json_map/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_val_nested_keystring_from_dict(keystring, data):
return data[current_key].values
if isinstance(data[current_key], xarray.core.dataset.Dataset):
raise NotImplementedError(
"Xarray datasets are not supported. " "You can only use xarray dataarrays."
"Xarray datasets are not supported. You can only use xarray dataarrays."
)

return data[current_key]
Expand Down
4 changes: 2 additions & 2 deletions src/pynxtools/nexus/nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def process_node(hdf_node, hdf_path, parser, logger, doc=True):
if len(hdf_node.shape) <= 1
else str(decode_if_string(hdf_node[0])).split("\n")
)
logger.debug(f'value: {val[0]} {"..." if len(val) > 1 else ""}')
logger.debug(f"value: {val[0]} {'...' if len(val) > 1 else ''}")
else:
logger.debug(
f"===== GROUP (/{hdf_path} "
Expand All @@ -460,7 +460,7 @@ def process_node(hdf_node, hdf_path, parser, logger, doc=True):
for key, value in hdf_node.attrs.items():
logger.debug(f"===== ATTRS (/{hdf_path}@{key})")
val = str(decode_if_string(value)).split("\n")
logger.debug(f'value: {val[0]} {"..." if len(val) > 1 else ""}')
logger.debug(f"value: {val[0]} {'...' if len(val) > 1 else ''}")
(req_str, nxdef, nxdl_path) = get_nxdl_doc(hdf_info, logger, doc, attr=key)
if (
parser is not None
Expand Down
6 changes: 3 additions & 3 deletions src/pynxtools/testing/nexus_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def convert_to_nexus(
"""
Test the example data for the reader plugin.
"""
assert hasattr(
self.reader, "supported_nxdls"
), f"Reader{self.reader} must have supported_nxdls attribute"
assert hasattr(self.reader, "supported_nxdls"), (
f"Reader{self.reader} must have supported_nxdls attribute"
)
assert callable(self.reader.read), f"Reader{self.reader} must have read method"

if isinstance(self.files_or_dir, (list, tuple)):
Expand Down
6 changes: 3 additions & 3 deletions src/pynxtools/testing/nomad_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ def example_upload_entry_point_valid(
os.path.abspath(os.path.join(dirpath, filename))
)

assert (
sorted(real_upload_files) == sorted(expected_upload_files)
), f"Uploaded files {real_upload_files} do not match the expected files: {expected_upload_files}"
assert sorted(real_upload_files) == sorted(expected_upload_files), (
f"Uploaded files {real_upload_files} do not match the expected files: {expected_upload_files}"
)
4 changes: 2 additions & 2 deletions tests/dataconverter/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ def fixture_filled_test_data(template, tmp_path):
template["/ENTRY[my_entry]/program_name"] = "Testing program"
template["/ENTRY[my_entry]/NXODD_name[nxodd_name]/type"] = "2nd type"
template["/ENTRY[my_entry]/NXODD_name[nxodd_name]/date_value"] = (
"2022-01-22T12" ":14:12.05018+00:00"
"2022-01-22T12:14:12.05018+00:00"
)
template["/ENTRY[my_entry]/required_group/description"] = "An example description"
template["/ENTRY[my_entry]/required_group2/description"] = "An example description"
template["/ENTRY[my_entry]/does/not/exist"] = "random"
template["/ENTRY[my_entry]/links/ext_link"] = {
"link": f"{tmp_path}/" f"xarray_saved_small_cali" f"bration.h5:/axes/ax3"
"link": f"{tmp_path}/xarray_saved_small_calibration.h5:/axes/ax3"
}
return template

Expand Down
12 changes: 6 additions & 6 deletions tests/nexus/test_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ def test_decode_if_string(string_obj, decode, expected):

# Handle np.ndarray outputs
if isinstance(expected, np.ndarray):
assert isinstance(
result, np.ndarray
), f"Expected ndarray, but got {type(result)}"
assert (
result == expected
).all(), f"Failed for {string_obj} with decode={decode}"
assert isinstance(result, np.ndarray), (
f"Expected ndarray, but got {type(result)}"
)
assert (result == expected).all(), (
f"Failed for {string_obj} with decode={decode}"
)
# Handle list outputs
elif isinstance(expected, list):
assert isinstance(result, list), f"Expected list, but got {type(result)}"
Expand Down

0 comments on commit e6eb16e

Please sign in to comment.