Commit 3b2aef0f authored by Kelvin Loh's avatar Kelvin Loh

Test 2.

parent 6e1b8653
Pipeline #25620 failed with stages
in 8 minutes and 17 seconds
......@@ -116,6 +116,15 @@ def syst_3d(W=3, r1=2, r2=4, a=1, t=1.0):
return syst
def plotter_file_suffix(engine):
# We need this function so that we cna add a .html suffix to the output filename.
# This is required because plotly will throw an error if filename is without the suffix.
if engine == "plotly":
return ".html"
else:
return None
@pytest.mark.skipif(not _plotter.mpl_available, reason="Matplotlib unavailable.")
def test_matplotlib_plot():
......@@ -126,7 +135,7 @@ def test_matplotlib_plot():
color_opts = ['k', (lambda site: site.tag[0]),
lambda site: (abs(site.tag[0] / 100),
abs(site.tag[1] / 100), 0)]
with tempfile.TemporaryFile('w+b') as out:
with tempfile.NamedTemporaryFile('w+b', suffix=plotter_file_suffix(engine)) as out:
for color in color_opts:
for syst in (syst2d, syst3d):
fig = plot(syst, site_color=color, cmap='binary', file=out)
......@@ -171,8 +180,7 @@ def test_plotly_plot():
color_opts = ['black', (lambda site: site.tag[0]),
lambda site: (abs(site.tag[0] / 100),
abs(site.tag[1] / 100), 0)]
with tempfile.TemporaryFile('w+b') as out:
out = f'{out}.html'
with tempfile.NamedTemporaryFile('w+b', suffix=plotter_file_suffix(engine)) as out:
for color in color_opts:
for syst in (syst2d, syst3d):
plot(syst, site_color=color, cmap='binary', file=out, show=False)
......@@ -208,9 +216,7 @@ def test_plot_more_site_families_than_colors(engine):
syst[lat(i, 0)] = None
plotter.set_engine(engine)
with tempfile.TemporaryFile('w+b') as out:
if engine == 'plotly':
out = f'{out}.html'
with tempfile.NamedTemporaryFile('w+b', suffix=plotter_file_suffix(engine)) as out:
plotter.plot(syst, file=out, show=False)
......@@ -245,9 +251,7 @@ def test_map(engine):
plotter.set_engine(engine)
syst = syst_2d()
with tempfile.TemporaryFile('w+b') as out:
if engine == 'plotly':
out = f'{out}.html'
with tempfile.NamedTemporaryFile('w+b', suffix=plotter_file_suffix(engine)) as out:
plotter.map(syst, lambda site: site.tag[0], pos_transform=good_transform,
file=out, method='linear', a=4, oversampling=4, cmap='flag', show=False)
pytest.raises(ValueError, plotter.map, syst,
......@@ -288,9 +292,7 @@ def test_bands(engine):
syst = syst_2d().finalized().leads[0]
with tempfile.TemporaryFile('w+b') as out:
if engine == 'plotly':
out = f'{out}.html'
with tempfile.NamedTemporaryFile('w+b', suffix=plotter_file_suffix(engine)) as out:
plotter.bands(syst, show=False, file=out)
plotter.bands(syst, show=False, momenta=np.linspace(0, 2 * np.pi), file=out)
......@@ -323,9 +325,7 @@ def test_spectrum(engine):
vals = np.linspace(0, 1, 3)
with tempfile.TemporaryFile('w+b') as out:
if engine == 'plotly':
out = f'{out}.html'
with tempfile.NamedTemporaryFile('w+b', suffix=plotter_file_suffix(engine)) as out:
for ham in (ham_1d, ham_2d, fsyst):
plotter.spectrum(ham, ('a', vals), params=dict(b=1, c=1), file=out, show=False)
......@@ -357,9 +357,7 @@ def test_spectrum(engine):
def mask(a, b):
return a > 0.5
with tempfile.TemporaryFile('w+b') as out:
if engine == 'plotly':
out = f'{out}.html'
with tempfile.NamedTemporaryFile('w+b', suffix=plotter_file_suffix(engine)) as out:
plotter.spectrum(ham, ('a', vals), ('b', 2 * vals), params=dict(c=1),
mask=mask, file=out, show=False)
......@@ -621,7 +619,7 @@ def test_current():
current = J(kwant.wave_function(syst, energy=1)(1)[0])
# Test good codepath
with tempfile.TemporaryFile('w+b') as out:
with tempfile.NamedTemporaryFile('w+b', suffix=plotter_file_suffix(engine)) as out:
plotter.current(syst, current, file=out)
fig = pyplot.Figure()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment