-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathtest_extendedplotframe.py
More file actions
75 lines (61 loc) · 2.36 KB
/
test_extendedplotframe.py
File metadata and controls
75 lines (61 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
##############################################################################
#
# diffpy.pdfgui Complex Modeling Initiative
# (c) 2019 Brookhaven Science Associates,
# Brookhaven National Laboratory.
# All rights reserved.
#
# File coded by: Pavol Juhas
#
# See AUTHORS.txt for a list of people who contributed.
# See LICENSE.txt for license information.
#
##############################################################################
"""Unit tests for the ExtendedPlotFrame class."""
import unittest
import numpy
import wx
from testutils import GUITestCase, overridefiledialog
from diffpy.pdfgui.control.plotter import Plotter
from diffpy.pdfgui.gui import extendedplotframe as epf
from diffpy.pdfgui.gui.extendedplotframe import ExtendedPlotFrame
# ----------------------------------------------------------------------------
class TestExtendedPlotFrame(GUITestCase):
def setUp(self):
self.app = wx.App()
self.frame = ExtendedPlotFrame(None)
return
def tearDown(self):
self.frame.Close()
self.app.Destroy()
return
def _clicktoolbar(self, tbid):
e = wx.CommandEvent(wx.EVT_TOOL.typeId, tbid)
self.frame.toolbar.ProcessEvent(e)
return
def test_insertCurve(self):
"Check ExtendedPlotFrame.insertCurve"
x = numpy.linspace(-5, 5)
ys = numpy.sin(x)
style = {"with": "lines", "color": "blue", "line": "solid", "width": 2.3}
line = self.frame.insertCurve(x, ys, style)
self.assertEqual(2.3, line.get_linewidth())
return
def test_savePlotData(self):
self.frame.plotter = Plotter()
# intercept plotter.export to avoid plot setup and temporary files
self.frame.plotter.export = lambda fn: setattr(self, "spd", fn)
self.spd = ""
with overridefiledialog(wx.ID_OK, ["testfile.dat"]):
self._clicktoolbar(epf.DATA_SAVE_ID)
self.assertEqual("testfile.dat", self.spd)
self.spd = ""
with overridefiledialog(wx.ID_CANCEL, ["testfile2.dat"]):
self._clicktoolbar(epf.DATA_SAVE_ID)
self.assertEqual("", self.spd)
return
# End of class TestExtendedPlotFrame
# ----------------------------------------------------------------------------
if __name__ == "__main__":
unittest.main()