-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for publish_plot (#28)
* Add dependencies to get postprocessing.publish_plot working * Refactor to allow for getting testing config file separately * Add unit tests for postprocessing.publish_plot * Remove second listing of requests library
- Loading branch information
1 parent
36bf63d
commit 9f422b4
Showing
3 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from postprocessing import publish_plot | ||
import pytest | ||
from tests.conftest import getDevConfigurationFile | ||
|
||
|
||
def test_get_user(): | ||
info = publish_plot.get_user(getDevConfigurationFile()) | ||
assert info | ||
# these aren't sepecified so just make sure the keys are present | ||
assert "username" in info | ||
assert "password" in info | ||
|
||
|
||
# plot1d test data | ||
data1d = [[0, 1], [2, 3], [4, 5]] | ||
|
||
|
||
@pytest.mark.parametrize("x_log, y_log", [(False, False), (True, True)]) | ||
def test_plot1d(x_log, y_log): | ||
# single spectrum | ||
assert publish_plot.plot1d( | ||
run_number=1234, | ||
instrument="instr", | ||
data_list=[data1d], | ||
x_log=x_log, | ||
y_log=y_log, | ||
publish=False, | ||
) | ||
# two spectra | ||
assert publish_plot.plot1d( | ||
run_number=1234, instrument="instr", data_list=[data1d, data1d], publish=False | ||
) | ||
|
||
|
||
def test_plot1d_fail(): | ||
with pytest.raises(RuntimeError): | ||
publish_plot.plot1d( | ||
run_number=1234, instrument="instr", data_list=None, publish=False | ||
) | ||
|
||
# when plot fails to publish the function returns None | ||
assert not publish_plot.plot1d( | ||
run_number=1234, instrument="instr", data_list=[data1d], publish=True | ||
) | ||
|
||
|
||
data2d = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] | ||
|
||
|
||
@pytest.mark.parametrize("x_log, y_log", [(False, False), (True, True)]) | ||
def test_plot_heatmap(x_log, y_log): | ||
assert publish_plot.plot_heatmap( | ||
1234, | ||
data2d[0], | ||
data2d[1], | ||
data2d[2], | ||
x_log=x_log, | ||
y_log=y_log, | ||
instrument="instr", | ||
publish=False, | ||
) | ||
|
||
|
||
def test_plot_heatmap_fail(): | ||
# when plot fails to publish the function returns None | ||
|
||
assert not publish_plot.plot_heatmap( | ||
1234, data2d[0], data2d[1], data2d[2], instrument="instr", publish=True | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main([__file__]) |