Skip to content

Commit 650b425

Browse files
authored
Merge pull request #1206 from wright-group/faster-pytest
faster pytest
2 parents 33b516c + 4b2416e commit 650b425

17 files changed

Lines changed: 72 additions & 57 deletions

File tree

.readthedocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
build:
44
os: ubuntu-22.04
55
tools:
6-
python: "3.9"
6+
python: "3.11"
77

88
python:
99
install:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
1818
- `data.from_LabRAM`: small tweaks to deal with newly emerged test failure in python 3.11 tests
1919

2020
### Changed
21+
- various unit tests were altered to speed up CI
2122
- default colorbar is sampled at 4096 points (was 256)
2223
- packaging now done through pyproject.toml
2324

WrightTools/data/_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ def norm_for_each(
790790
norm_vals = np.expand_dims(np.nanmax(channel[:], axis=trivial), trivial)
791791
new = (channel[:] - channel.null) / (norm_vals - channel.null)
792792
if new_channel:
793+
if not isinstance(new_channel, dict):
794+
new_channel = {}
793795
self.create_channel(
794796
new_channel.pop("name", f"{channel.natural_name}_{variable.natural_name}_norm"),
795797
values=new,

tests/artists/test_interact2D.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#! /usr/bin/env python3
22

3+
import pytest
34
import numpy as np
45
import WrightTools as wt
56
from WrightTools import datasets
@@ -49,6 +50,7 @@ def test_skewed():
4950
return wt.artists.interact2D(data, xaxis=0, yaxis=1)
5051

5152

53+
@pytest.mark.xfail(reason="sometimes fails for artificial reasons")
5254
def test_4D():
5355
w1 = np.linspace(-5, 5, 31)
5456
w2 = w1[::2].copy()

tests/collection/from_directory.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
#! /usr/bin/env python3
22

3-
import os
3+
import pathlib
44
import WrightTools as wt
55
from WrightTools import datasets
66

77

88
def test_from_directory():
99
from_dict = {
10-
"*.data": wt.data.from_PyCMDS,
1110
"*.csv": wt.collection.from_Cary,
11+
"*.txt": wt.data.from_JASCO,
1212
"KENT": None,
13-
"COLORS": None,
13+
"Shimadzu": None,
1414
}
1515
p = datasets.PyCMDS.w1_000
16-
p = os.path.dirname(p)
17-
p = os.path.dirname(p)
18-
col = wt.collection.from_directory(p, from_dict)
16+
col = wt.collection.from_directory(pathlib.Path(*p.parts[:-2]), from_dict)
1917
# Print the tree in case tests fail, also will catch errors in printing
2018
col.print_tree()
2119
assert col.natural_name == "datasets"
22-
assert col.PyCMDS["w1 000"]
20+
assert col.JASCO["PbSe batch 1"]
2321
assert col.Cary["CuPCtS_H2O_vis"]
2422
assert "KENT" not in col.item_names
2523
col.close()

tests/data/axis/convert_axis.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,24 @@ def test_exception():
5050
data.close()
5151

5252

53-
def test_w1_wa():
54-
p = datasets.PyCMDS.w1_wa_000
55-
data = wt.data.from_PyCMDS(p)
56-
assert data.wa.units == "wn"
57-
data.wa.convert("eV")
58-
assert data.wa.units == "eV"
59-
assert np.isclose(data.wa.max(), 1.5800551001941774)
60-
assert np.isclose(data.wa.min(), 0.6725528801867734)
61-
assert data["wa"].units == "nm"
53+
def test_w1_wm():
54+
p = datasets.wt5.v1p0p1_MoS2_TrEE_movie
55+
data = wt.open(p).at(d2=[0, "fs"])
56+
assert data.w2.units == "nm"
57+
data.w2.convert("eV")
58+
assert data.w2.units == "eV"
59+
assert np.isclose(data.w2.max(), 2.120129779494837)
60+
assert np.isclose(data.w2.min(), 1.6241930110774845)
61+
assert data["w2"].units == "nm"
6262
data.close()
6363

6464

6565
def test_wigner():
66-
p = datasets.COLORS.v2p2_WL_wigner
67-
data = wt.data.from_COLORS(p)
68-
data.d1.convert("ns")
69-
assert data.d1.units == "ns"
70-
assert data["d1"].units == "fs"
66+
p = datasets.wt5.v1p0p1_MoS2_TrEE_movie
67+
data = wt.open(p).at(w2=[680, "nm"])
68+
data.d2.convert("ns")
69+
assert data.d2.units == "ns"
70+
assert data["d2"].units == "fs"
7171
data.close()
7272

7373

@@ -78,5 +78,5 @@ def test_wigner():
7878
test_convert_variables()
7979
test_units_preserved_on_copy()
8080
test_exception()
81-
test_w1_wa()
81+
test_w1_wm()
8282
test_wigner()

tests/data/channel/normalize.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ def test_LDS821_mag_0p5():
3333

3434

3535
def test_wigner():
36-
p = datasets.COLORS.v2p2_WL_wigner
37-
data = wt.data.from_COLORS(p)
36+
p = datasets.wt5.v1p0p1_MoS2_TrEE_movie
37+
data = wt.open(p).at(w2=[680, "nm"])
3838
data.ai0.normalize()
3939
assert np.isclose(data.ai0.null, 0.0)
4040
assert np.isclose(data.ai0.max(), 1.0)
4141
data.close()
4242

4343

4444
def test_negative_wigner():
45-
p = datasets.COLORS.v2p2_WL_wigner
46-
data = wt.data.from_COLORS(p)
45+
p = datasets.wt5.v1p0p1_MoS2_TrEE_movie
46+
data = wt.open(p).at(w2=[680, "nm"])
4747
data.ai0 *= -1
4848
data.ai0.signed = True
4949
data.ai0.normalize()
@@ -54,8 +54,8 @@ def test_negative_wigner():
5454

5555

5656
def test_negative_wigner_mag_1p1():
57-
p = datasets.COLORS.v2p2_WL_wigner
58-
data = wt.data.from_COLORS(p)
57+
p = datasets.wt5.v1p0p1_MoS2_TrEE_movie
58+
data = wt.open(p).at(w2=[680, "nm"])
5959
data.ai0 *= -1
6060
data.ai0.signed = True
6161
data.ai0.normalize(1.1)

tests/data/chop.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
def test_2D_to_1D():
1717
p = datasets.PyCMDS.w2_w1_000
18-
data = wt.data.from_PyCMDS(p)
18+
data = wt.data.from_PyCMDS(p)[:, ::10]
1919
chop = data.chop("w2")
20-
assert len(chop) == 81
20+
assert len(chop) == data.w1.size
2121
for d in chop.values():
22-
assert d.w2.size == 81
22+
assert d.w2.size == data.w2.size
2323
assert d.axis_expressions == ("w2",)
2424
for k in data.variable_names:
2525
assert d[k].label == data[k].label
@@ -29,11 +29,11 @@ def test_2D_to_1D():
2929

3030
def test_3D_to_1D():
3131
p = datasets.PyCMDS.wm_w2_w1_000
32-
data = wt.data.from_PyCMDS(p)
32+
data = wt.data.from_PyCMDS(p)[::10, :, ::3]
3333
chop = data.chop("w2")
34-
assert len(chop) == 385
34+
assert len(chop) == data.wm.size * data.w1.size
3535
for d in chop.values():
36-
assert d.w2.size == 11
36+
assert d.w2.size == data.w2.size
3737
assert d.axis_expressions == ("w2",)
3838
data.close()
3939
chop.close()

tests/data/convert_data.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ def test_w1_wa():
4444

4545

4646
def test_wigner():
47-
p = datasets.COLORS.v2p2_WL_wigner
48-
data = wt.data.from_COLORS(p)
47+
data = wt.Data()
48+
data.create_variable("wm", values=np.linspace(100, 300)[:, None], units="nm")
49+
data.create_variable("d1", values=np.linspace(-100, 100)[None, :], units="fs")
50+
data.transform("d1", "wm")
4951
data.convert("ns")
5052
assert data.d1.units == "ns"
5153
assert data["d1"].units == "fs"

tests/data/from_COLORS.py

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

55
# --- import --------------------------------------------------------------------------------------
66

7-
7+
import pytest
88
import numpy as np
99
import glob
1010
import os
@@ -47,6 +47,7 @@ def test_v0p2_d1_d2_diagonal():
4747
data.close()
4848

4949

50+
@pytest.mark.skip(reason="This test takes a long time and examines rarely used code.")
5051
def test_v2p1_MoS2_TrEE_movie():
5152
ps = sorted(
5253
glob.glob(
@@ -61,6 +62,7 @@ def test_v2p1_MoS2_TrEE_movie():
6162
data.close()
6263

6364

65+
@pytest.mark.skip(reason="This test takes a long time and examines rarely used code.")
6466
def test_v2p2_WL_wigner():
6567
p = datasets.COLORS.v2p2_WL_wigner
6668
data = wt.data.from_COLORS(p)

0 commit comments

Comments
 (0)