Skip to content

Commit 9284bc5

Browse files
committed
TST: partially cover the Parameter class
1 parent b9a9b83 commit 9284bc5

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python
2+
##############################################################################
3+
#
4+
# diffpy.pdfgui Complex Modeling Initiative
5+
# (c) 2019 Brookhaven Science Associates,
6+
# Brookhaven National Laboratory.
7+
# All rights reserved.
8+
#
9+
# File coded by: Pavol Juhas
10+
#
11+
# See AUTHORS.txt for a list of people who contributed.
12+
# See LICENSE.txt for license information.
13+
#
14+
##############################################################################
15+
16+
"""
17+
Unit tests for the Parameter class.
18+
"""
19+
20+
import unittest
21+
22+
import wx
23+
24+
from diffpy.pdfgui.control.parameter import Parameter
25+
from diffpy.pdfgui.control.controlerrors import ControlTypeError
26+
from diffpy.pdfgui.control.controlerrors import ControlKeyError
27+
from diffpy.pdfgui.gui.mainframe import MainFrame
28+
from diffpy.pdfgui.tests.testutils import GUITestCase, datafile
29+
30+
# ----------------------------------------------------------------------------
31+
32+
class TestParameter(GUITestCase):
33+
34+
@classmethod
35+
def setUpClass(cls):
36+
GUITestCase.setUpClass()
37+
GUITestCase.setCmdArgs([datafile("lcmo.ddp")])
38+
cls.app = wx.App()
39+
cls.frame = MainFrame(None, -1, "")
40+
tree = cls.frame.treeCtrlMain
41+
fits = tree.GetChildren(tree.root)
42+
cls.frame.makeTreeSelection(fits[0])
43+
return
44+
45+
46+
@classmethod
47+
def tearDownClass(cls):
48+
cls.frame.Close()
49+
cls.app.Destroy()
50+
GUITestCase.tearDownClass()
51+
return
52+
53+
54+
def setUp(self):
55+
self.fitting = self.frame.rightPanel.fit
56+
return
57+
58+
59+
def test___init__(self):
60+
"check Parameter.__init__"
61+
p = Parameter(3, 2.2)
62+
self.assertEqual(3, p.idx)
63+
self.assertIsNone(p.refined)
64+
self.assertEqual(2.2, p.initialValue())
65+
p100 = Parameter(100, self.fitting)
66+
self.assertAlmostEqual(0.7957747, p100.initialValue(), 6)
67+
p102 = Parameter(102, "=fit-d300:102")
68+
self.assertAlmostEqual(1.1811493, p102.initialValue(), 6)
69+
self.assertRaises(ControlTypeError, Parameter, 1, None)
70+
return
71+
72+
73+
def test_initialValue(self):
74+
"check Parameter.initialValue"
75+
p1 = Parameter(1, 0.25)
76+
self.assertEqual(0.25, p1.initialValue())
77+
self.assertEqual("0.25", p1.initialStr())
78+
px = Parameter(7, "=undefined")
79+
self.assertRaises(ControlKeyError, px.initialValue)
80+
self.assertEqual("=undefined:7", px.initialStr())
81+
return
82+
83+
# End of class TestParameter
84+
85+
# ----------------------------------------------------------------------------
86+
87+
if __name__ == '__main__':
88+
unittest.main()

0 commit comments

Comments
 (0)