Skip to content

Commit a938d47

Browse files
committed
renamed rule
1 parent cbaa002 commit a938d47

File tree

10 files changed

+37
-31
lines changed

10 files changed

+37
-31
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Adjustments and Enhancements
66

7-
- Added a new core rule `opening-time` that can be used to check the
7+
- Added a new core rule `access-latency` that can be used to check the
88
time it takes to open datasets.
99

1010
- Added HTML styling for both CLI output (`--format html`) and rendering

docs/rule-ref.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ New rules will be added by upcoming XRLint releases.
55

66
## Core Rules
77

8+
### :material-bug: `access-latency`
9+
10+
Ensure that the time it takes to open a dataset from its source does a exceed a given `threshold` in seconds. The default threshold is `2.5`.
11+
12+
Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert:
13+
814
### :material-lightbulb: `content-desc`
915

1016
A dataset should provide information about where the data came from and what has been done to it. This information is mainly for the benefit of human readers. The rule accepts the following configuration parameters:
@@ -65,12 +71,6 @@ Empty chunks should not be encoded and written. The rule currently applies to Za
6571

6672
Contained in: `all`-:material-lightning-bolt: `recommended`-:material-circle-off-outline:
6773

68-
### :material-bug: `opening-time`
69-
70-
Ensure that the time it takes to open a dataset from its source does a exceed a given `threshold` in seconds. The default threshold is `2.5`.
71-
72-
Contained in: `all`-:material-lightning-bolt: `recommended`-:material-alert:
73-
7474
### :material-bug: `time-coordinate`
7575

7676
Time coordinates should have valid and unambiguous time units encoding.

tests/_linter/test_rulectx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_defaults(self):
1919
self.assertEqual({}, context.settings)
2020
self.assertEqual("./ds.zarr", context.file_path)
2121
self.assertEqual(None, context.file_index)
22-
self.assertEqual(None, context.opening_time)
22+
self.assertEqual(None, context.access_latency)
2323

2424
def test_report(self):
2525
context = RuleContextImpl(

tests/plugins/core/rules/test_opening_time.py renamed to tests/plugins/core/rules/test_access_latency.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from xrlint._linter.rulectx import RuleContextImpl
88
from xrlint.config import ConfigObject
99
from xrlint.node import DatasetNode
10-
from xrlint.plugins.core.rules.opening_time import OpeningTime
10+
from xrlint.plugins.core.rules.access_latency import AccessLatency
1111
from xrlint.result import Message
1212
from xrlint.rule import RuleExit
1313

@@ -19,22 +19,24 @@
1919
class OpeningTimeTest(TestCase):
2020
@classmethod
2121
def invoke_op(
22-
cls, dataset: xr.Dataset, opening_time: float, threshold: float | None = None
22+
cls, dataset: xr.Dataset, access_latency: float, threshold: float | None = None
2323
):
2424
ctx = RuleContextImpl(
2525
config=ConfigObject(),
2626
dataset=dataset,
2727
file_path="test.zarr",
2828
file_index=None,
29-
opening_time=opening_time,
29+
access_latency=access_latency,
3030
)
3131
node = DatasetNode(
3232
path="dataset",
3333
parent=None,
3434
dataset=ctx.dataset,
3535
)
3636
rule_op = (
37-
OpeningTime(threshold=threshold) if threshold is not None else OpeningTime()
37+
AccessLatency(threshold=threshold)
38+
if threshold is not None
39+
else AccessLatency()
3840
)
3941
with pytest.raises(RuleExit):
4042
rule_op.validate_dataset(ctx, node)
@@ -52,7 +54,7 @@ def test_invalid(self):
5254
self.assertEqual(
5355
[
5456
Message(
55-
message="Opening time exceeds threshold: 3.2 > 2.5 seconds.",
57+
message="Access latency exceeds threshold: 3.2 > 2.5 seconds.",
5658
node_path="dataset",
5759
severity=2,
5860
)
@@ -64,7 +66,7 @@ def test_invalid(self):
6466
self.assertEqual(
6567
[
6668
Message(
67-
message="Opening time exceeds threshold: 0.2 > 0.1 seconds.",
69+
message="Access latency exceeds threshold: 0.2 > 0.1 seconds.",
6870
node_path="dataset",
6971
severity=2,
7072
)

tests/plugins/core/test_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ def test_rules_complete(self):
88
plugin = export_plugin()
99
self.assertEqual(
1010
{
11+
"access-latency",
1112
"content-desc",
1213
"conventions",
1314
"coords-for-dims",
1415
"grid-mappings",
1516
"lat-coordinate",
1617
"lon-coordinate",
17-
"opening-time",
1818
"no-empty-attrs",
1919
"no-empty-chunks",
2020
"time-coordinate",

xrlint/_linter/rulectx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(
1717
dataset: xr.Dataset,
1818
file_path: str,
1919
file_index: int | None,
20-
opening_time: float | None,
20+
access_latency: float | None,
2121
):
2222
assert config is not None
2323
assert dataset is not None
@@ -27,7 +27,7 @@ def __init__(
2727
self._dataset = dataset
2828
self._file_path = file_path
2929
self._file_index = file_index
30-
self._opening_time = opening_time
30+
self._access_latency = access_latency
3131
self.messages: list[Message] = []
3232
self.rule_id: str | None = None
3333
self.severity: Literal[1, 2] = SEVERITY_ERROR
@@ -54,8 +54,8 @@ def file_index(self) -> int | None:
5454
return self._file_index
5555

5656
@property
57-
def opening_time(self) -> float | None:
58-
return self._opening_time
57+
def access_latency(self) -> float | None:
58+
return self._access_latency
5959

6060
def report(
6161
self,

xrlint/_linter/validate.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ def _validate_dataset(
2727
dataset: xr.Dataset,
2828
file_path: str,
2929
file_index: int | None,
30-
opening_time: float | None,
30+
access_latency: float | None,
3131
) -> list[Message]:
3232
assert isinstance(config_obj, ConfigObject)
3333
assert isinstance(dataset, xr.Dataset)
3434
assert isinstance(file_path, str)
3535

36-
context = RuleContextImpl(config_obj, dataset, file_path, file_index, opening_time)
36+
context = RuleContextImpl(
37+
config_obj, dataset, file_path, file_index, access_latency
38+
)
3739
for rule_id, rule_config in config_obj.rules.items():
3840
with context.use_state(rule_id=rule_id):
3941
apply_rule(context, rule_id, rule_config)
@@ -55,10 +57,10 @@ def _open_and_validate_dataset(
5557
ds_path_list = processor_op.preprocess(file_path, opener_options)
5658
except (OSError, ValueError, TypeError) as e:
5759
return [new_fatal_message(str(e))]
58-
opening_time = time.time() - t0
60+
access_latency = time.time() - t0
5961
return processor_op.postprocess(
6062
[
61-
_validate_dataset(config_obj, ds, path, i, opening_time)
63+
_validate_dataset(config_obj, ds, path, i, access_latency)
6264
for i, (ds, path) in enumerate(ds_path_list)
6365
],
6466
file_path,
@@ -69,9 +71,11 @@ def _open_and_validate_dataset(
6971
dataset = _open_dataset(ds_source, opener_options, file_path)
7072
except (OSError, ValueError, TypeError) as e:
7173
return [new_fatal_message(str(e))]
72-
opening_time = time.time() - t0
74+
access_latency = time.time() - t0
7375
with dataset:
74-
return _validate_dataset(config_obj, dataset, file_path, None, opening_time)
76+
return _validate_dataset(
77+
config_obj, dataset, file_path, None, access_latency
78+
)
7579

7680

7781
def _open_dataset(

xrlint/plugins/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def export_plugin() -> Plugin:
1212
{
1313
"name": "recommended",
1414
"rules": {
15+
"access-latency": "warn",
1516
"content-desc": "warn",
1617
"conventions": "warn",
1718
"coords-for-dims": "error",
@@ -20,7 +21,6 @@ def export_plugin() -> Plugin:
2021
"lon-coordinate": "error",
2122
"no-empty-attrs": "warn",
2223
"no-empty-chunks": "off",
23-
"opening-time": "warn",
2424
"time-coordinate": "error",
2525
"var-desc": "warn",
2626
"var-flags": "error",

xrlint/plugins/core/rules/opening_time.py renamed to xrlint/plugins/core/rules/access_latency.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
@plugin.define_rule(
17-
"opening-time",
17+
"access-latency",
1818
version="1.0.0",
1919
description=(
2020
"Ensure that the time it takes to open a dataset from its source"
@@ -33,14 +33,14 @@
3333
},
3434
),
3535
)
36-
class OpeningTime(RuleOp):
36+
class AccessLatency(RuleOp):
3737
def __init__(self, threshold: float = DEFAULT_THRESHOLD):
3838
self.threshold = threshold
3939

4040
def validate_dataset(self, ctx: RuleContext, node: DatasetNode) -> None:
41-
if ctx.opening_time is not None and ctx.opening_time > self.threshold:
41+
if ctx.access_latency is not None and ctx.access_latency > self.threshold:
4242
ctx.report(
43-
f"Opening time exceeds threshold: {ctx.opening_time:.1f}"
43+
f"Access latency exceeds threshold: {ctx.access_latency:.1f}"
4444
f" > {format_count(self.threshold, 'second')}."
4545
)
4646
raise RuleExit

xrlint/rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def dataset(self) -> xr.Dataset:
4040

4141
@property
4242
@abstractmethod
43-
def opening_time(self) -> float | None:
43+
def access_latency(self) -> float | None:
4444
"""The time in seconds that it took for opening the dataset.
4545
`None` if the dataset has not been opened from `file_path`.
4646
"""

0 commit comments

Comments
 (0)