Skip to content

Commit

Permalink
Fix CI tests (#146)
Browse files Browse the repository at this point in the history
* fix tqdm.auto frontend test

* try fix CI lint

* CI lint: show black diff

* update black 20.x and apply
  • Loading branch information
benbovy committed Nov 13, 2020
1 parent d26c9e4 commit 363cd66
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Lint with flake8
Expand All @@ -28,4 +28,4 @@ jobs:
- name: Check formatting with black
run: |
pip install black
black --check .
black --check --diff .
8 changes: 6 additions & 2 deletions versioneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,11 +1237,15 @@ def versions_from_file(filename):
except EnvironmentError:
raise NotThisMethod("unable to read _version.py")
mo = re.search(
r"version_json = '''\n(.*)''' # END VERSION_JSON", contents, re.M | re.S,
r"version_json = '''\n(.*)''' # END VERSION_JSON",
contents,
re.M | re.S,
)
if not mo:
mo = re.search(
r"version_json = '''\r\n(.*)''' # END VERSION_JSON", contents, re.M | re.S,
r"version_json = '''\r\n(.*)''' # END VERSION_JSON",
contents,
re.M | re.S,
)
if not mo:
raise NotThisMethod("no version_json in _version.py")
Expand Down
4 changes: 3 additions & 1 deletion xsimlab/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ def _create_zarr_dataset(
self.consolidated = False

def _maybe_resize_zarr_dataset(
self, model: Model, var_key: VarKey,
self,
model: Model,
var_key: VarKey,
):
# Maybe increases the length of one or more dimensions of
# the zarr array (only increases, never shrinks dimensions).
Expand Down
6 changes: 5 additions & 1 deletion xsimlab/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ def test_create_variable_cache(self, model):
},
{},
),
("add", {"offset": ("add", "offset")}, {"u_diff": ("add", "u_diff")},),
(
"add",
{"offset": ("add", "offset")},
{"u_diff": ("add", "u_diff")},
),
],
)
def test_set_process_keys(
Expand Down
2 changes: 1 addition & 1 deletion xsimlab/tests/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@pytest.mark.parametrize(
"frontend,tqdm_module",
[
("auto", "tqdm"), # assume tests are run in a terminal evironment
("auto", "tqdm.auto"),
("console", "tqdm"),
("gui", "tqdm.gui"),
("notebook", "tqdm.notebook"),
Expand Down
4 changes: 3 additions & 1 deletion xsimlab/tests/test_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ class P:
model = xs.Model({"p": P})

in_ds = xs.create_setup(
model=model, clocks={"clock": [0, 1, 2]}, output_vars={"p__arr": "clock"},
model=model,
clocks={"clock": [0, 1, 2]},
output_vars={"p__arr": "clock"},
)

store = ZarrSimulationStore(in_ds, model)
Expand Down
5 changes: 4 additions & 1 deletion xsimlab/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ def test_frozen():
with pytest.raises(AttributeError):
x.update({"c": "C", "b": "B"})
assert x.mapping == mapping
assert repr(x) in ("Frozen({'a': 'A', 'b': 'B'})", "Frozen({'b': 'B', 'a': 'A'})",)
assert repr(x) in (
"Frozen({'a': 'A', 'b': 'B'})",
"Frozen({'b': 'B', 'a': 'A'})",
)
# test iter
assert set(x) == set(mapping)
assert len(x) == 2
14 changes: 10 additions & 4 deletions xsimlab/tests/test_xr_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def test_update_clocks(self, model):
ds = xr.Dataset()
with pytest.raises(ValueError) as excinfo:
ds.xsimlab.update_clocks(
model=model, clocks={"clock": ("x", [0, 1, 2])},
model=model,
clocks={"clock": ("x", [0, 1, 2])},
)
assert "Invalid dimension" in str(excinfo.value)

Expand Down Expand Up @@ -274,7 +275,9 @@ def test_update_clocks(self, model):
assert ds.clock.attrs[self._output_vars_key] == "profile__u"

new_ds = ds.xsimlab.update_clocks(
model=model, clocks={"clock2": [0, 0.5, 1, 1.5, 2]}, master_clock="clock2",
model=model,
clocks={"clock2": [0, 0.5, 1, 1.5, 2]},
master_clock="clock2",
)
assert new_ds.xsimlab.master_clock_dim == "clock2"

Expand All @@ -296,7 +299,8 @@ def test_update_vars_promote_to_coords(self, model, in_dataset):
# label that cooresponds to its name (turned into a coordinate). This
# should not raise any merge conflict error
ds = in_dataset.xsimlab.update_vars(
model=model, input_vars={"roll__shift": ("roll__shift", [1, 2])},
model=model,
input_vars={"roll__shift": ("roll__shift", [1, 2])},
)

assert "roll__shift" in ds.coords
Expand Down Expand Up @@ -392,7 +396,9 @@ def test_output_vars_by_clock(self, model):
o_vars = {("roll", "u_diff"): "clock", ("add", "u_diff"): None}

ds = xs.create_setup(
model=model, clocks={"clock": [0, 2, 4, 6, 8]}, output_vars=o_vars,
model=model,
clocks={"clock": [0, 2, 4, 6, 8]},
output_vars=o_vars,
)

expected = {"clock": [("roll", "u_diff")], None: [("add", "u_diff")]}
Expand Down

0 comments on commit 363cd66

Please sign in to comment.